safekeys/envelope-encryption [built]
Envelope encryption separates the key that protects a secret from the key that protects that key. Each secret is encrypted with a random data encryption key (DEK); the DEK is wrapped by a key-encryption key (KEK) held in the key store. The sidecar unwraps a DEK only for the duration of a resolve, then zeroises both the DEK and the plaintext.
Status: built
Why this exists
Rotating or revoking a master key must not require re-encrypting every secret ever stored, and a compromised DEK must expose only one object. Envelope encryption gives per-object key isolation and a single small set of KEKs to protect, which is also the shape that later lets the KEK live in a secure element or be reconstructed under threshold policy without touching the data.
Design decisions
openbao-or-vault [accepted]
Decision: Use OpenBao or Vault Transit/KV as the MVP key store.
Rationale: Mature, self-hostable, and auditable, with wrapping primitives already available. Auto-unseal comes later. It avoids building a key store before proving the protocol.
Alternatives considered:
- AWS KMS / cloud provider KMS — rejected: It puts the root of trust in a provider the customer may not control, and a multi-tenant AI-cloud KMS in particular could be reachable by the model provider — defeating the product's core property.
- Build a bespoke key store — rejected: It slows the MVP and adds an unreviewed crypto component on the most sensitive path.
envelope-not-direct [accepted]
Decision: Wrap keys rather than encrypting secrets directly under a master key.
Rationale: Envelope encryption keeps per-object isolation and makes master key rotation cheap, which is also the structure required to move the KEK into hardware or threshold custody without changing the data layer.
How it works
Wrap a data encryption key (wrap-dek)
A new DEK is generated locally and wrapped by the KEK without leaving the key store's trust boundary.
- Generate — Generate a random DEK for the object.
- Encrypt — Encrypt the plaintext object with the DEK.
- Send — Send the DEK to the key store for wrapping under the KEK; only the wrapped form is persisted.
- Observe — Plaintext is discarded from memory after encryption.
Unwrap a DEK for a resolve (unwrap-dek)
The sidecar requests unwrap only after a token has passed every verification step.
- Transmit — Sidecar sends the wrapped DEK and token context to the key store after token verification.
- Receive — Key store returns the unwrapped DEK over an authenticated channel.
- Decrypt — Sidecar decrypts the target object in memory.
- Delete — Zeroise the DEK and the plaintext buffer once injection completes.