Documentation
¶
Overview ¶
Package crypto encrypts the credentials the server keeps in its own database: the instance and data source credentials, and the LLM provider API keys.
The data key is a random 32-byte AES-256 key. A ciphertext is the prefix "v1:" followed by the standard base64 of a fresh 12-byte nonce, the encrypted bytes and the 16-byte GCM tag. Because every value gets its own nonce, equal plaintexts never produce equal ciphertexts, and because the tag authenticates the whole value, decrypting with the wrong key or reading an edited value fails instead of returning garbage.
Index ¶
Constants ¶
const ( // Prefix versions the ciphertext layout. It is the only version this build // writes, and a reader refuses a value without it: a credential written by // the retired obfuscation scheme fails as an error rather than decrypting to // garbage that the next write would store as the new plaintext. Prefix = "v1:" // KeySize is the AES-256 key length in bytes. KeySize = 32 // KeyEnvironment names the environment variable that holds the current // key-encryption key. Its presence is what keeps a database read or a // database backup from being enough to recover the stored credentials: the // data key is wrapped with it instead of being kept in the clear. KeyEnvironment = "METAXISDATA_ENCRYPTION_KEY" // PreviousKeyEnvironment names an optional comma-separated list of retired // key-encryption keys. They are only ever used to open a wrapped data key, so // a rotation does not require re-encrypting a single stored credential. PreviousKeyEnvironment = "METAXISDATA_ENCRYPTION_KEY_PREVIOUS" )
Variables ¶
This section is empty.
Functions ¶
func IsCiphertext ¶
IsCiphertext reports whether a value is stored in the current ciphertext format.
func ParseKey ¶
ParseKey parses one key from its configured form: base64 (padded or not), hex, or the raw 32 bytes. The key comes from an environment variable an operator pastes by hand, so all the spellings are accepted.
The encodings are tried before the raw reading, and a hex string of the wrong length is an error rather than a raw key: sixteen random bytes printed as hex are 32 characters, and silently taking those characters as a 256-bit key would leave the deployment with half the entropy it believes it has.
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher encrypts and decrypts values with one data key.