secrets

package
v0.1.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package secrets implements envelope encryption for cluster secrets (spec §3.13, design §2.10):

recovery passphrase ──argon2id──▶ KEK ──AES-GCM──▶ sealed data key (in Raft)
data key (memory only) ──AES-GCM──▶ every secret value (in Raft)

Control nodes hold the plaintext data key in memory; a joining control node receives it from the leader over mTLS. Restore from backup requires the passphrase.

Index

Constants

View Source
const (
	ArgonTime      = argonTime
	ArgonMemoryKiB = argonMemoryKiB
	ArgonThreads   = argonThreads
	ArgonKeyLen    = keyLen
	ArgonSaltLen   = saltLen
)

Exported argon2id parameters, reused by password hashing (T-04) so it stays in lockstep with the cluster-key KDF.

Variables

View Source
var ErrSealedDataInvalid = errors.New("secrets: wrong passphrase or corrupted key material")

ErrSealedDataInvalid covers wrong passphrase and corrupted material — AES-GCM cannot distinguish them.

Functions

func GenerateDataKey

func GenerateDataKey() ([]byte, error)

GenerateDataKey returns a fresh random 32-byte cluster data key.

func GeneratePassphrase

func GeneratePassphrase() (string, error)

GeneratePassphrase returns a human-typable recovery passphrase (8 groups of 4 base32 chars ≈ 160 bits).

func SealDataKey

func SealDataKey(dataKey []byte, passphrase string, keyVersion uint32) (*zatterav1.ClusterKeyMaterial, error)

SealDataKey encrypts the data key under a passphrase-derived KEK, producing the ClusterKeyMaterial stored in Raft.

func UnsealDataKey

func UnsealDataKey(m *zatterav1.ClusterKeyMaterial, passphrase string) ([]byte, error)

UnsealDataKey recovers the data key from ClusterKeyMaterial + passphrase. Uses the argon2 parameters recorded in the material (forward compat).

Types

type Keyring

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

Keyring holds the cluster data key in memory only. Control nodes keep it for the lifetime of the process; it is never written to disk. A joining control node receives it from the leader over mTLS (M2); a restore from backup derives it from the recovery passphrase.

func NewKeyring

func NewKeyring(dataKey []byte, keyVersion uint32) (*Keyring, error)

NewKeyring wraps a plaintext data key. It copies the key so the caller may zero its own buffer.

func (*Keyring) DataKey

func (k *Keyring) DataKey() []byte

DataKey returns a copy of the plaintext data key (for handing to a joining control node over mTLS). Handle with care; never log or persist it.

func (*Keyring) KeyVersion

func (k *Keyring) KeyVersion() uint32

KeyVersion returns the data key version.

func (*Keyring) Sealer

func (k *Keyring) Sealer() (Sealer, error)

Sealer returns a Sealer bound to the current data key version.

type Sealer

type Sealer interface {
	Seal(plaintext []byte) (*zatterav1.EncryptedValue, error)
	Open(v *zatterav1.EncryptedValue) ([]byte, error)
}

Sealer encrypts/decrypts individual secret values with the cluster data key. The zero Sealer is unusable; obtain one via NewSealer.

func NewSealer

func NewSealer(dataKey []byte, keyVersion uint32) (Sealer, error)

NewSealer wraps a 32-byte data key.

Jump to

Keyboard shortcuts

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