Documentation
¶
Index ¶
- Constants
- type Config
- type RewrapKeysOptions
- type RewrapKeysResult
- type Store
- func (s *Store) ActiveKeyVersion(ctx context.Context, conn pgxConn, scope, scopeID string) (int, error)
- func (s *Store) CreateKey(ctx context.Context, conn pgxConn, scope, scopeID string) (*encryption.EncryptedKey, error)
- func (s *Store) DestroyKeys(ctx context.Context, conn pgxConn, scope, scopeID string) error
- func (s *Store) GetActiveKey(ctx context.Context, conn pgxConn, scope, scopeID string) (*encryption.EncryptedKey, error)
- func (s *Store) GetKey(ctx context.Context, conn pgxConn, scope, scopeID string, version int) (*encryption.EncryptedKey, error)
- func (s *Store) RevokeKeys(ctx context.Context, conn pgxConn, scope, scopeID string) error
- func (s *Store) RotateKey(ctx context.Context, conn pgxConn, scope, scopeID string) (*encryption.EncryptedKey, error)
Constants ¶
const ( // DefaultSchema is the default PostgreSQL schema for encryption keys. DefaultSchema = "infrastructure" // DefaultTable is the default PostgreSQL table name for encryption keys. DefaultTable = "encryption_keys" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config holds the schema and table names for the PostgreSQL keystore.
func ApplyDefaults ¶
ApplyDefaults fills in the default schema and table names when omitted.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default PostgreSQL keystore configuration.
type RewrapKeysOptions ¶ added in v0.0.6
RewrapKeysOptions configures RewrapKeys.
type RewrapKeysResult ¶ added in v0.0.6
type RewrapKeysResult struct {
MatchedRows int
RewrappedRows int
SkippedRows int
RemainingRows int
Batches int
}
RewrapKeysResult summarizes a KEK rewrap run.
func RewrapKeys ¶ added in v0.0.6
func RewrapKeys(ctx context.Context, pool *pgxpool.Pool, cfg Config, env *envelope.Envelope, opts RewrapKeysOptions) (RewrapKeysResult, error)
RewrapKeys re-encrypts stored DEKs from one KEK to another in short PostgreSQL-managed batch transactions.
This is an administrative operation for retiring old KEKs or migrating across KMS providers. It updates only the stored encrypted_dek and kek_id for matching rows while preserving and verifying each row's (scope, scope_id, key_version) AAD.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store coordinates DEK generation, KEK-based wrapping, and persistence in PostgreSQL. It is a stateless service; all database operations require an explicit pgx connection.
func NewStore ¶
NewStore creates a new PostgreSQL keystore wired to the given envelope crypto engine.
func (*Store) ActiveKeyVersion ¶
func (s *Store) ActiveKeyVersion(ctx context.Context, conn pgxConn, scope, scopeID string) (int, error)
ActiveKeyVersion returns the version number of the active key for the given scope.
func (*Store) CreateKey ¶
func (s *Store) CreateKey(ctx context.Context, conn pgxConn, scope, scopeID string) (*encryption.EncryptedKey, error)
CreateKey generates a new DEK via envelope, wraps it with the active KEK bound to (scope, scopeID, version=1) AAD, and inserts it into PostgreSQL. Returns ErrKeyExists if a key already exists for the scope.
func (*Store) DestroyKeys ¶
DestroyKeys permanently deletes all keys for the given scope (GDPR crypto-shredding).
func (*Store) GetActiveKey ¶
func (s *Store) GetActiveKey(ctx context.Context, conn pgxConn, scope, scopeID string) (*encryption.EncryptedKey, error)
GetActiveKey returns the active (non-revoked) key for the given scope.
func (*Store) GetKey ¶
func (s *Store) GetKey(ctx context.Context, conn pgxConn, scope, scopeID string, version int) (*encryption.EncryptedKey, error)
GetKey returns a specific key version for the given scope.
func (*Store) RevokeKeys ¶
RevokeKeys marks all active keys for the given scope as revoked, except the highest version (the current active key).
func (*Store) RotateKey ¶
func (s *Store) RotateKey(ctx context.Context, conn pgxConn, scope, scopeID string) (*encryption.EncryptedKey, error)
RotateKey generates a new DEK, wraps it with the active KEK bound to (scope, scopeID, current_version + 1) AAD, and atomically revokes the previous active version while inserting the new version.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package migrations exposes the embedded PostgreSQL keystore migration.
|
Package migrations exposes the embedded PostgreSQL keystore migration. |