Documentation
¶
Overview ¶
Package secrets implements envelope encryption for secrets stored in the replicated state (ADR 0011, FA-SEC-SEC): a master key (KEK) wraps data encryption keys (DEKs), and DEKs encrypt individual values with AES-256-GCM. Only the standard library is used.
Index ¶
Constants ¶
const ( SourceEnv = "MASTER_KEY" SourceFile = "MASTER_KEY_FILE" SourceGenerated = "generated" )
KEK sources.
const GeneratedKEKFile = "master.key"
GeneratedKEKFile is the file a KEK is generated into when none is configured (ADR 0011 option B).
const KeySize = 32
KeySize is the size of KEKs and DEKs in bytes (AES-256).
Variables ¶
var ( // ErrKEKMismatch means the replicated DEKs are wrapped with a different // master key than the one this node was started with (ADR 0011). ErrKEKMismatch = errors.New("master key does not match the cluster") // ErrNoActiveKey means no data key exists yet (the leader creates one at startup). ErrNoActiveKey = errors.New("no active data key") // ErrDecrypt covers malformed or tampered ciphertexts and wrong AAD. ErrDecrypt = errors.New("cannot decrypt secret") )
Errors of the keyring.
Functions ¶
func InstallGenerated ¶
InstallGenerated stores a master key received at join in dataDir, as if it had been generated there. It never overwrites an existing key; an existing key must be the same one (fingerprint), otherwise the node belongs to another cluster.
func IsEncrypted ¶
IsEncrypted reports whether s has the format produced by Encrypt.
func KeyFingerprint ¶
KeyFingerprint returns the fingerprint a key would have as KEK.
Types ¶
type KEK ¶
type KEK struct {
// Fingerprint identifies the key without revealing it.
Fingerprint string
// Source tells where the key came from (SourceEnv, SourceFile, SourceGenerated).
Source string
// contains filtered or unexported fields
}
KEK is the master key. It never leaves the process except during a join over mTLS (phase 2).
func LoadKEK ¶
LoadKEK returns the master key from envKey (base64), from keyFile (base64 or 32 raw bytes) or, if neither is set, from dataDir/master.key, which is generated with mode 0600 on first start.
func (*KEK) Transferable ¶
Transferable returns the key for a joining voter, only if it was generated in the data directory. Operators who configure MASTER_KEY or MASTER_KEY_FILE provide the same key to every voter themselves.
type Keyring ¶
type Keyring struct {
// contains filtered or unexported fields
}
Keyring encrypts and decrypts values with the cluster's data keys. New keys arrive through Raft; an unknown key ID triggers a reload.
func NewKeyring ¶
NewKeyring creates a keyring; call Reload before use.
func (*Keyring) ActiveKeyID ¶
ActiveKeyID returns the key new values are encrypted with ("" if none).
func (*Keyring) Decrypt ¶
Decrypt reverses Encrypt. Values encrypted with older (rotated) keys remain readable as long as the key exists.