seal

package
v0.6.112 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package seal encrypts what a service keeps and has to read back — a receiver's signing secret, a provider's token — so a copy of its database or of a backup holds ciphertext only. It is a configuration section and a dependency, like a database connection:

type Config struct {
    config.Backplane `json:"backplane"`
    Seal seal.Config `json:"seal"` // KOMEET_SEAL_KEY, KOMEET_SEAL_PREVIOUS
}

sealer := deps.NewDependency(root, seal.New(cfg.Seal), deps.Name("seal"))
sealed, err := sealer.Get().Seal(ctx, []byte(secret), []byte(subscriptionID))
secret, err := sealer.Get().Open(ctx, sealed, []byte(subscriptionID))

The associated data (aad) binds a sealed value to what it belongs to: it is not stored, Open needs the same, and a value copied to another row does not open there.

The keys are AES-256-GCM keys of the section: key seals and opens, previous only opens. A sealed value names its key (by a hash of it), so rotation is: generate a key (GenerateKey), set it as key and the old one as previous, Rewrap what is stored, then drop previous.

With vault set, Vault's Transit engine seals instead (envelope encryption: a fresh data key per value, wrapped by the Transit key, which never leaves Vault), and the dependency probes Vault. The section's keys, when still set, open what they sealed, and Rewrap moves it to Vault; after a Transit key rotation Rewrap moves values to its latest version.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConfig: the section has no key, a key is not base64 of 32 bytes,
	// or its vault is incomplete.
	ErrConfig = config.ErrSeal
	// ErrOpen: the value is not sealed by these keys, was changed, or the
	// aad differs.
	ErrOpen = errors.New("seal: cannot open")
)

Errors.

View Source
var ErrVault = errors.New("seal: vault")

ErrVault: Vault answered with an error or could not be reached.

Functions

func GenerateKey

func GenerateKey() string

GenerateKey is a new random key, base64.

func New

func New(cfg Config) deps.Provider[Sealer]

New is the provider of the section's sealer.

Types

type Config

type Config = config.Seal

Config is the section of the keys (config.Seal): Key and Previous, or Vault. Its Validate checks it.

type Sealer

type Sealer interface {
	// Seal encrypts plaintext under the active key, bound to aad.
	Seal(ctx context.Context, plaintext, aad []byte) ([]byte, error)
	// Open decrypts what Seal returned with the same aad, under the active
	// key or a previous one.
	Open(ctx context.Context, sealed, aad []byte) ([]byte, error)
	// Rewrap seals sealed again under the active key; changed is false,
	// and sealed returns as is, when it is under the active key already.
	Rewrap(ctx context.Context, sealed, aad []byte) (out []byte, changed bool, err error)
}

Sealer seals and opens values. It is immutable and safe for concurrent use.

func Open

func Open(cfg Config) (Sealer, error)

Open is the section's sealer, outside of a dependency (tools, tests).

type Vault added in v0.6.49

type Vault = config.SealVault

Vault is the section's Vault Transit (config.SealVault).

Jump to

Keyboard shortcuts

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