Secret vaults and keys
A secret vault keeps an application's secrets (passwords, API keys, connection strings, certificates) in the database server itself, in place of a cloud key vault or a secrets manager. Each value is encrypted under keys held by an HSM, a post-quantum key pair or (for development) a key file; every version is kept; deletes are soft and purge-protected; and every read and change is audited and hash-chained. A vault can also hold keys that the server uses for you without ever returning them, and keys that encrypted columns are sealed with.
Vaults are part of the enterprise server (rasterizeddb-enterprise). A vault is a ledger table of a fixed shape, so it lives under the same chain, anchors and verification.
Create a vault
CREATE VAULT app_secrets
KEY PROVIDER 'pkcs11:module=/usr/lib/softhsm/libsofthsm2.so;token=rdb;key=vault-kek;pin-source=/etc/rasterizeddb/hsm.pin'
RETAIN DELETED 30 DAYS;| Clause | Required | What it does |
|---|---|---|
KEY PROVIDER '<uri>' | Yes | Where the vault's key-encryption key lives. See Key providers. |
RETAIN DELETED <n> <unit> | No | How long a deleted secret is kept before it may be purged. Default 90 days. Units as for ledger tables: SECOND to YEAR, where a month is 31 days and a year 366. |
NO DROP UNTIL <n> <unit> IDLE | No | DROP TABLE on the vault is refused until nothing has been written to it for this long. |
ANCHOR TO '<sink>' [, …] | No | Anchor sinks for the database's chain, as for a ledger table. |
CREATE VAULT IF NOT EXISTS name … is accepted; over an existing vault it changes nothing and opens no key provider. A vault takes no column list.
The key provider is opened when the vault is created, so a missing PIN, an unreadable key file or an unreachable token fails the CREATE VAULT and no vault is made:
ERROR: the vault's key provider does not open: pkcs11: give the PIN by pin-source=<file> or pin-env=<VAR>A vault is dropped with DROP TABLE app_secrets, subject to its legal holds and NO DROP UNTIL clause.
Key providers
Every secret version is sealed with AES-256-GCM under a data key of its own. Data keys are stored only wrapped by the provider's key-encryption key, in the vault's keyring. The provider URI has no spaces.
| Provider | Form | What it is |
|---|---|---|
| PKCS#11 | pkcs11:module=<library>;token=<label>;key=<label>;pin-source=<file> or …;pin-env=<VAR>, optionally ;mechanism=gcm|kwp|cbc | A key inside an HSM, a network or cloud HSM, or a TPM 2.0 through tpm2-pkcs11. The key never leaves the device: data keys are wrapped and unwrapped inside it. |
| ML-KEM | mlkem:<path> or mlkem:<path>;create | A hybrid post-quantum key pair, ML-KEM-768 with X25519, in a file: breaking the wrapping needs breaking both. |
| File | file:<path> | A 32-byte key, or 64 hexadecimal characters, in a file on the database host. For tests and development only. |
| TPM | tpm:<path>[;tcti=<tcti>][;create] | A key sealed by this machine's TPM 2.0. Not in the release builds: use a TPM through pkcs11: (tpm2-pkcs11) instead. |
PKCS#11
| Attribute | Required | What it is |
|---|---|---|
module | Yes | The vendor's PKCS#11 library, loaded when the vault opens. |
token | Yes | The token's label. |
key | Yes | The label of an AES secret-key object on the token, made with your HSM's tools before the vault. |
pin-source=<file> | One of these | A file holding the user PIN. |
pin-env=<VAR> | One of these | An environment variable of the server holding the user PIN. |
mechanism | No | gcm (AES-256-GCM on the token, the default), kwp (AES key wrap with padding) or cbc (AES-CBC with padding), for tokens without GCM. |
The PIN is never written in SQL. SHOW LEDGER shows the provider with the PIN source cut (pin-source=…). Several vaults may share one token.
ML-KEM key files
The file holds 192 hexadecimal characters. With ;create, the server makes one (mode 600) the first time the vault is opened, if the file does not exist; its directory must exist. Keep a copy of the file somewhere safe: without it, no secret of the vault can be read again.
CREATE VAULT app_secrets KEY PROVIDER 'mlkem:/etc/rasterizeddb/app_secrets.mlkem;create';Key files
A file: provider keeps the key on the same host as the data, so the server refuses it unless the server's environment has RDB_VAULT_ALLOW_FILE_KEY=1:
openssl rand -hex 32 > /etc/rasterizeddb/dev-vault.key
chmod 600 /etc/rasterizeddb/dev-vault.key
export RDB_VAULT_ALLOW_FILE_KEY=1CREATE VAULT dev_secrets KEY PROVIDER 'file:/etc/rasterizeddb/dev-vault.key';On Linux and macOS, file: and mlkem: key files must be readable by their owner only; a file with group or other permissions is refused.
Secrets
The VAULT statements read and write a vault. Each answers with text rows.
VAULT app_secrets SET SECRET 'db/password' = 'correct horse battery staple';db/password version 1VAULT app_secrets GET SECRET 'db/password';correct horse battery stapleSetting a secret
VAULT <vault> SET SECRET '<name>' = '<value>'
[CONTENT TYPE '<type>'] [EXPIRES '<time>'] [NOT BEFORE '<time>'] [TAGS '<text>']- A name is 1 to 256 characters of
A-Z a-z 0-9 . _ - / :. Names startingkey:belong to the vault's keys. - Setting an existing name adds a new version. Older versions stay readable with
VERSION nuntil the secret is purged. - Times are UTC,
'YYYY-MM-DD'or'YYYY-MM-DDTHH:MM:SSZ'. A secret is not served afterEXPIRESor beforeNOT BEFORE. - The value is a quoted literal; double a quote inside it (
'it''s'). Wherever the server keeps statement text (its log, statement statistics), a statement is cut at the wordSECRET, so the value is not kept. Only the ciphertext is written to the table, the write-ahead log, the replication stream and backups. Use TLS between client and server. - Setting a deleted secret is refused: recover or purge it first. Setting a disabled secret adds a version and makes the secret active again.
Reading
| Statement | Answer |
|---|---|
VAULT v GET SECRET 'name' | The newest version's value, one row. |
VAULT v GET SECRET 'name' VERSION 3 | That version's value. |
VAULT v GET ALL | Every active, current, unexpired secret, one JSON row each: {"name":"db/password","version":1,"value":"…"}. |
VAULT v GET ALL PREFIX 'app/' | The same, for names starting with the prefix. |
VAULT v LIST | One row per secret and key: name vN state, then type=…, expires_us=… and updated_us=… when set. No values. |
VAULT v VERSIONS SECRET 'name' | The secret's history: vN set by <role> at <micros> per version, (purged) after a purged one, and a line per state change. |
db/password v2 active type=text/plain updated_us=1795701600000000
key:pii v1 active type=aes256-gcm updated_us=1795701500000000Every read is audited before the value is returned; if the audit cannot be written, nothing is returned. A read that is refused is audited too, with why:
ERROR: secret 'db/password': it is disabledThe reasons are no such secret, it is disabled (or deleted, purged), no such version, it has expired, it is not valid yet, and its key was purged; it can no longer be read.
States: disable, delete, recover, purge
| Statement | From | To |
|---|---|---|
VAULT v DISABLE SECRET 'name' | active | disabled |
VAULT v ENABLE SECRET 'name' | disabled | active |
VAULT v DELETE SECRET 'name' | active or disabled | deleted |
VAULT v RECOVER SECRET 'name' | deleted | active |
VAULT v PURGE SECRET 'name' | deleted, once RETAIN DELETED has passed since the delete | purged |
Only an active secret is served. A PURGE before the retention has passed is refused (secret 'x' is purge-protected for 2592000 s after its deletion).
A purge crypto-shreds the secret: its data keys are removed from the keyring, so its sealed values can never be opened again, by anyone. The rows and their digests stay, so the ledger still verifies. A purged secret cannot be recovered; setting the name again starts a new version after the old ones.
db/password purged: 2 version(s) can never be decrypted againPURGE and ROTATE KEY change the keyring at once, which a ROLLBACK could not undo, so they are refused inside a transaction block (SQLSTATE 25001). A batch of statements that holds one runs statement by statement. The other VAULT statements take part in the surrounding transaction: a SET that rolls back leaves no version.
Plain SQL on a vault
A vault's table has fixed columns: name, version, value, state, content_type, not_before, expires_at, tags, created_by, created_at and __ledger_ts. A role with SELECT on it can query them, but value holds only the sealed value (base64), never the secret. INSERT, UPDATE, DELETE and TRUNCATE on a vault are refused: only the VAULT statements write it.
Keys used in place
A vault can hold keys that the server uses and never returns:
VAULT app_secrets CREATE KEY 'pii'; -- AES-256-GCM, the default
VAULT app_secrets CREATE KEY 'tokens' TYPE 'mldsa65'; -- ML-DSA-65 signing
VAULT app_secrets CREATE KEY 'hsm-aes' TYPE 'hsm-aes256-gcm'; -- generated inside the HSM
VAULT app_secrets CREATE KEY 'hsm-sig' TYPE 'hsm-ecdsa-p256'; -- generated inside the HSM| Type | Operations |
|---|---|
aes256-gcm | ENCRYPT, DECRYPT. Also what an encrypted column is sealed with. |
mldsa65 | SIGN, VERIFY, PUBLIC KEY. |
hsm-aes256-gcm | ENCRYPT, DECRYPT, run on the token. Needs a pkcs11: vault. Can seal encrypted columns. |
hsm-ecdsa-p256 | SIGN, VERIFY (of SHA-256 of the value), PUBLIC KEY, run on the token. Needs a pkcs11: vault. |
A key's name has no :. A software key is a random 256-bit key wrapped in the keyring like any data key; an HSM key is generated on the token, cannot be extracted, and the keyring only records that it exists.
VAULT app_secrets ENCRYPT KEY 'pii' VALUE 'call me at 555-0100'; -- base64 ciphertext
VAULT app_secrets DECRYPT KEY 'pii' VALUE '<base64 from ENCRYPT>'; -- the plaintext
VAULT app_secrets SIGN KEY 'tokens' VALUE 'order 1182 approved'; -- hex signature
VAULT app_secrets VERIFY KEY 'tokens' VALUE 'order 1182 approved' SIGNATURE '<hex>'; -- true or false
VAULT app_secrets PUBLIC KEY 'tokens'; -- hex public keyEvery use is audited. A key appears in VAULT … LIST as key:<name>, with its type. The secret statements (GET, DISABLE, ENABLE, DELETE, RECOVER, PURGE) do not apply to keys and are refused (42602).
Rotating the key-encryption key
VAULT app_secrets ROTATE KEY; -- rewrap under the same provider
VAULT app_secrets ROTATE KEY TO 'mlkem:/etc/rasterizeddb/app_secrets-2026.mlkem;create';14 data key(s) rewrapped under mlkem:/etc/rasterizeddb/app_secrets-2026.mlkem (ML-KEM-768 + X25519)Rotation unwraps every data key with the current provider and wraps it again with the new one, replacing the keyring in one atomic step. TO moves the vault to another provider (another HSM key, from a file to an HSM, to a new ML-KEM key pair). Keys generated inside an HSM stay where they are. Secret values and encrypted-column values are not re-encrypted: their data keys are only rewrapped. Rotation is audited. Keep the old provider's key until the rotation has returned.
The audit trail
VAULT app_secrets AUDIT;
VAULT app_secrets AUDIT SECRET 'db/password';chained 1795701600000000 SET app_secrets 'db/password' v1 by deploy
chained 1795701660000000 GET app_secrets 'db/password' v1 by app
chained 1795701700000000 GET app_secrets 'db/password' by intern REFUSED: it is disabledEach line is one event (time in microseconds since 1970, what, which secret and version, which role), marked chained when the hash chain holds it or UNCHAINED when it does not: an UNCHAINED line was added to the audit file past the server. Reads and key uses are audited when they happen, whatever becomes of their transaction; changes (SET, DISABLE, ENABLE, DELETE, RECOVER, CREATE KEY) are audited when their transaction commits, and not at all if it rolls back. Values never appear in the audit.
Privileges
| Statement | Needs |
|---|---|
CREATE VAULT | Whoever may create a table. |
GET, GET ALL, LIST, VERSIONS, ENCRYPT, DECRYPT, SIGN, VERIFY, PUBLIC KEY | SELECT on the vault. |
SET, DISABLE, ENABLE, DELETE, RECOVER | INSERT on the vault. |
PURGE, ROTATE KEY, AUDIT, CREATE KEY | The vault's owner or a superuser. |
GRANT SELECT ON app_secrets TO app; -- the application reads its secrets
GRANT SELECT, INSERT ON app_secrets TO deploy; -- the deploy pipeline sets themSELECT on a vault is also what a role needs to read and write encrypted columns sealed with its keys.
Files beside the chain
A vault's keyring, the vault audit log and the encrypted-column keys are kept in the database's chain directory (see Where the chain lives):
| File | What it holds |
|---|---|
vault-<vault id>.keys | The vault's wrapped data keys, and the provider that wrapped them. Without it no secret of the vault can be read, even with the provider's key. |
vault-audit.log | The audit lines. Each is also chained. |
encrypted_columns | Each encrypted column's data key, wrapped by its vault key. |
Back up the chain directory with the data, and keep the provider's key (the HSM key, the ML-KEM file) backed up separately from both.
The Studio LEDGER page
Studio built with the enterprise features (rdb-studio-enterprise, see Installing) has a LEDGER tab for ledger tables and vaults. It builds the statements on this page and the ledger tables page and runs them as the logged-in role; the server decides what that role may do, and a refusal is shown as the answer. Destructive actions (placing or releasing a hold, raising a retention, acknowledging a rollback, deleting or purging a secret, rotating a key) ask for confirmation first.
- Chain. Tiles for the chain's entries, head, anchors and location, the server's warnings, and VERIFY ALL, which shows
VERIFY LEDGER's findings marked INTACT or PROBLEMS FOUND. - Ledger tables. A grid of the tables (rows, mode, retention, legal holds, own anchors), each with VERIFY, MANAGE and DATA. MANAGE raises the retention, places and releases holds, adds an anchor, and shows a row's history or receipt by its stamp. A form creates a ledger table, with versioned mode, a drop-idle time, an anchor and encrypted columns. AFTER A RESTORE runs
ACKNOWLEDGE LEDGER ROLLBACKwith your reason. - Encrypted columns. Every encrypted column, with its table, vault, key and type.
- Vaults. Per vault: tiles for its secrets, keys, key provider and deleted-secret retention; a grid of secrets with REVEAL (the value shows in a marked box until HIDE, and never past a tab or vault switch), VERSIONS, DISABLE or ENABLE, DELETE or RECOVER, and PURGE; forms to set a secret, create and use keys, and rotate the key; the audit trail; and a form that creates a vault with any of the providers above.
On a server without the enterprise features, the tab says the server has no ledger tables or vaults. Elsewhere in Studio, an encrypted value the role cannot decrypt shows as "🔒 encrypted (no access to its vault)". See Studio for the rest of Studio.
From a Rust application
The enterprise Rust client crate, rasterizeddb_client_enterprise (in the repository, not on crates.io), wraps these statements: Vault::new(&client, "app_secrets") then set, get, get_all, list, rotate_key, audit, create_key, encrypt and the rest, with values returned as a string that is zeroed when dropped, and cached(ttl) for a short-lived cache.
Replication and backups
- A vault replicates as a vault: a replica creates it from the same
CREATE VAULTstatement, without opening its key provider, and stores the same ciphertext. The keyring and audit log stay on the server that wrote them, so read secrets on the primary. - A backup carries the vault's ciphertext. Restoring it is useful only with the keyring of the same moment (see Files beside the chain) and the provider's key.
Limits
tpm:is not in the release builds; use a TPM throughpkcs11:and tpm2-pkcs11.- A secret value is a quoted literal in the statement; it cannot be a bound parameter.
- The value given to
ENCRYPT,SIGNandVERIFY KEYis not cut from statement text the server keeps: only statements carrying the wordSECRETare. - Values are text: a secret that is not valid UTF-8 cannot be read back.
- A
GETrefused because the role lacksSELECTon the vault is not audited: the privilege check comes first. - Secrets are read on the server that holds the keyring, not on replicas.
- A plain
SELECTon a vault shows its metadata (names, versions, states, who set them) to any role withSELECTon it. - Once a vault is used, the server turns off core dumps and debugger attachment for its process (on Linux), and keeps keys and values in locked memory.