Karta.Vault (Karta v1.0.0)

Encryption at rest for secrets (DKIM keys, TOTP secrets, endpoint passwords), built on Karta.Crypto (AES-256-GCM).

Configuration (application environment of :karta):

  • :vault_key (required): the active key, base64 of 32 bytes. Production reads it from KARTA_VAULT_KEY.
  • :vault_key_id (default "v1"): the label new ciphertexts carry.
  • :vault_retired_keys (default %{}): %{key_id => base64 key} of keys that still decrypt old values after a rotation.

To rotate: add the old key to :vault_retired_keys under its id, set a new :vault_key and :vault_key_id, re-encrypt stored values (Karta.Vault.Reencrypt), then drop the retired key. In production the three come from KARTA_VAULT_KEY, KARTA_VAULT_KEY_ID and KARTA_VAULT_RETIRED_KEYS (id:base64 pairs separated by commas).

Stored message bodies (Karta.Storage) are encrypted with keys derived from the same keys. They are not re-encrypted: keep a retired key until every message stored under it has passed its server's retention period (at most 365 days).

Summary

Functions

The id and value of the active key.

Decrypts a value encrypted with the active key or a retired one.

Encrypts a secret with the active key.

Every key that can still decrypt: the active key and the retired ones, by id.

Functions

active_key()

@spec active_key() :: {binary(), binary()}

The id and value of the active key.

decrypt(ciphertext)

@spec decrypt(binary()) :: {:ok, binary()} | :error

Decrypts a value encrypted with the active key or a retired one.

encrypt(plaintext)

@spec encrypt(binary()) :: {:ok, binary()}

Encrypts a secret with the active key.

keys()

@spec keys() :: %{required(binary()) => binary()}

Every key that can still decrypt: the active key and the retired ones, by id.