Lifecycle and security · Engineering
Vault collections and per-tenant keys
Whole-document encryption with tenant keys, restricted queries, and the operational cost of giving up indexes.
Some data should not sit as plaintext JSON in LMDB, backups, or snapshots. NonoDB’s vault collections encrypt the whole document body with a per-tenant key. They are opt-in and deliberately restrictive.
The trade-off is simple: encryption at the document level, in exchange for giving up most query features on that data.
Creating a vault collection
{ "op": "create_collection", "coll": "vault", "profile": "vault"}Every collection has one immutable profile: standard or vault. A standard collection cannot be converted to vault in place, and a vault collection cannot be converted back. Create a new collection and migrate.
Credentials are headers
Every request against a vault collection includes:
X-NonoDB-Tenant: acmeX-NonoDB-Key-Id: acme:v1X-NonoDB-Key: <base64-encoded-32-byte-key>The key is never placed in the request body. The daemon never logs these headers.
- missing headers:
vault_key_required; - vault headers on a standard collection:
vault_key_unexpected; - malformed key:
invalid_vault_key; - wrong key, tenant, or corrupted envelope:
decryption_failed; - lookup by
_idunder another tenant: no document.
The key id is not secret. The key is.
Stored format
{ "_id": "8f2c...", "tenant_id": "acme", "_enc": { "v": 1, "alg": "xchacha20poly1305", "kid": "acme:v1", "n": "base64-nonce", "ct": "base64-ciphertext" }}_id and tenant_id stay plaintext so primary-key lookup and tenant isolation do not require decrypting every document. The complete original document, including its own _id and tenant_id, is encrypted into _enc.ct.
The cipher is XChaCha20-Poly1305. The nonce is random 24 bytes. Associated data binds the ciphertext to the collection, tenant, _id, and key id, so moving an envelope to another document or tenant fails decryption.
What is supported
- insert and insert_many with headers, same tenant;
- find/find_one/count with only
_idortenant_idequality; - update by exactly one
_id; - delete by exactly one
_id; - history and get_version with headers;
- insertion-based TTL;
- list_collections (names only).
What is not supported:
- search, fuzzy, vector search;
- aggregation;
- secondary, text, fuzzy, vector indexes;
- arbitrary filters, sorting, range queries;
batchandwrite_batch;- multi update/delete;
- date-field TTL;
- MongoDB wire access (the listener cannot carry the vault headers).
Vault collections are not a way to keep some fields queryable while encrypting others. The MVP encrypts the whole body.
TTL and history
Insertion-based TTL is supported. Expiry metadata is plaintext, and the sweeper never decrypts the body.
History snapshots are encrypted too. Reading history requires the tenant headers and decrypts each returned revision. A deleted document has a tombstone; the body is absent.
purge_history on TTL settings deletes stored revisions instead of keeping tombstones.
Key rotation
The daemon does not keep a keyring of retired keys. Key rotation is an offline read-with-old-key/write-with-new-key procedure.
Plan it before you need it:
- Add the new key id to the application configuration.
- Read documents with the old key.
- Re-encrypt and write with the new key.
- Verify a sample and a full restore.
- Retire the old key only after all backups that need it have expired.
A lost tenant key means the encrypted bodies are unrecoverable. Back up keys separately from the database and test recovery.
Security boundaries
Vault protects document bodies at rest, including backups and snapshots. It does not protect:
_id,tenant_id, collection names, TTL metadata;- query patterns, access logs, or index metadata;
- data in daemon memory while a request is being served;
- a compromised host or a daemon that can read the tenant key.
Vault is not end-to-end encryption. The daemon receives plaintext and the raw key while serving the request. For data that must be unreadable to the daemon, encrypt client-side and store ciphertext as an ordinary field.
When to use it
Use vault collections for:
- tenant secrets and credentials;
- personal notes or payment metadata;
- a small number of sensitive resources;
- workloads that only need lookup by
_idor tenant.
Do not use vault for:
- full-text or vector search over encrypted data;
- analytics, sorting, or arbitrary filters;
- per-field encryption with queryable fields;
- a replacement for volume encryption.
The vault guide and encryption at rest describe the API, threat model, backups, and key handling.