secrets

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package secrets provides a forward-compatible interface for secret storage.

All API keys, OAuth tokens, webhook secrets, and other credential material flows through Store. The current implementation (LocalStore) wraps the in-process AES-256-GCM crypto package and stores ciphertext inline in resource columns. A future enterprise build can swap in a Vault-backed implementation without touching call sites.

The ref argument on every method names the secret with a stable path-like identifier, e.g. "connection/<id>/access_token". LocalStore authenticates the ref as AES-GCM additional data, preventing ciphertext from being moved between resource fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RewrapDatabase added in v0.4.0

func RewrapDatabase(ctx context.Context, pool *pgxpool.Pool, store Store) (int64, error)

RewrapDatabase re-encrypts persisted Store values under the active key. It is an explicit stop-all key rotation and must not be called during normal startup.

The transaction makes the scan atomic, and its advisory lock serializes accidental concurrent rotation replicas before either can serve.

Types

type LocalStore

type LocalStore struct {
	// contains filtered or unexported fields
}

LocalStore implements Store using AES-256-GCM with stable key IDs.

func NewLocal

func NewLocal(enc *crypto.Encryptor) *LocalStore

NewLocal wraps a crypto.Encryptor as a Store. enc must be non-nil.

func (*LocalStore) Get

func (l *LocalStore) Get(_ context.Context, ref, stored string) (string, error)

func (*LocalStore) Open added in v0.4.0

func (l *LocalStore) Open(_ context.Context, aad, sealed string) (string, error)

func (*LocalStore) Put

func (l *LocalStore) Put(_ context.Context, ref, plaintext string) (string, error)

func (*LocalStore) Rewrap added in v0.4.0

func (l *LocalStore) Rewrap(ctx context.Context, ref, stored string) (string, bool, error)

func (*LocalStore) Seal added in v0.4.0

func (l *LocalStore) Seal(_ context.Context, aad, plaintext string) (string, error)

type Store

type Store interface {
	// Put encrypts plaintext and returns a value the caller persists
	// alongside the owning resource row. The returned value is opaque to
	// callers — its format depends on the implementation.
	Put(ctx context.Context, ref, plaintext string) (string, error)

	// Get returns the plaintext for a value returned by Put.
	Get(ctx context.Context, ref, stored string) (string, error)

	// Rewrap returns stored in the ref-bound envelope under the current key.
	// Callers persist the result only during an explicit stop-all migration.
	Rewrap(ctx context.Context, ref, stored string) (rewrapped string, changed bool, err error)

	// Seal encrypts plaintext bound to aad and returns an opaque sealed
	// value. Open returns the plaintext only when given the identical aad —
	// the binding lets the agent persist the sealed value in its own storage
	// while a caller under a different aad cannot decrypt it. (For LocalStore
	// the aad is the GCM additional-authenticated-data; a future KMS store
	// maps it to the encryption context.)
	Seal(ctx context.Context, aad, plaintext string) (string, error)

	// Open reverses Seal. Returns an error if aad doesn't match the value
	// sealed under.
	Open(ctx context.Context, aad, sealed string) (string, error)
}

Store is the interface for storing and retrieving secret material.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL