Skip to content
Talk to our solutions team

Providing encryption keys

A field declared compliances: [{type: encrypted}] is encrypted with AES-256-GCM on write and decrypted on read. The key is not part of the schema — the schema names a key, the deployment supplies it — so declaring the field is half the job, and this page is the other half.

A deployment with no key does not fall back to plaintext. Writes to an encrypted field are refused, 500 with details.code encryption_key_missing, and the boot log names every field that will refuse. That is deliberate: a value declared confidential is never stored in the clear, and never under a key that is not a secret.

A field says which key protects it. The datastore says where that key comes from. The deployment overrides that where it must. The key name is what joins them.

entities:
- name: employee
fields:
- name: date_of_birth
type: date
compliances:
- type: pii
- type: encrypted
key: pii_key # this field's key
- name: annual_ctc
type: money
compliances:
- type: pii
- type: encrypted
key: financial_key # a different key, same entity
- type: mask
value: '***'
- name: ssn
type: string
compliances:
- type: encrypted # no key: → "default"
- name: passport_no
type: string
compliances:
- type: pii # classified, no at-rest choice → encrypted under "default"

Two fields on one entity can hold genuinely different keys. That is the whole point of the name: a compromise of one does not read the other, and they can be rotated and destroyed separately.

A field with no key: uses default, which is also what an implicitly-encrypted classified field (pii, phi, pci, gdpr) uses — so a deployment that has not thought about key separation needs default and nothing else.

2. The datastore says where the key comes from

Section titled “2. The datastore says where the key comes from”

On the datastore that holds those entities:

datastores:
- name: main
type: postgresql
encryption:
keys:
- name: pii_key
key: vault://erp/pii-key # each tenant's own key
- name: financial_key
key: vault://erp/financial-key
- name: signing
key: vaultcluster://erp/signing-key # one key for the cluster's tenants
- name: everywhere
key: vaultkey://global/erp-key # one key everywhere

One entry per key name. The scheme says where the key lives and who shares it:

Declared asScopeSealed as
vault://PATHthe tenant’s own key: each tenant reads its own secret at that patht:<name>@<version>
vaultcluster://PATHone key for every tenant of the cluster<name>@<version>
vaultkey://PATHone key everywhere<name>@<version>
anything elsethe key material itself<name>, never versioned

Whether a key is shared is stated in the document, not inferred from code. An operator reading the block knows which without reading Go.

  • A path may have several segments. No {tenant} is needed: the vault scopes the path by the requesting tenant.
  • An older per-tenant path that names the tenant (vault://fieldkeys/{tenant}/default) still reads the secret it always did.
  • A vaultcluster:// or vaultkey:// path that names the tenant is refused, because it could not be one key for every tenant.
  • On the file-backed local vault (vault.file), which keys a secret by name alone, a vault:// key’s name carries the tenant: <customer>/<env>/<product>/<tenant>/PATH.

The declaration site is a datastore, but the key namespace is not per datastore — the names are merged across every datastore in the composed schema, because a field asks for a name and nothing else. Two datastores declaring the same name with different sources is refused at boot, naming both; declaring it identically in two places is fine.

properties:
encryption:
keys:
- name: financial_key
key: vault://operators/financial-key # a different vault path
- name: imported
key: "literal key material" # no vault at all

Merged by name, and the deployment wins — the same layering as the datastore type:, where the schema states the intent and the deployment holds the physical truth. A name only the product declares keeps the product’s source; a name only the deployment declares is the deployment’s alone.

A key whose vault secret is missing or empty is an error naming the path it resolved to, never a silent fallback to some other key: field-encryption: key "payments": vault secret "secret/erp/acme/test/shop/t1/payments" is empty.

A malformed entry is named at boot and skipped — it does not take the well-formed keys with it — and the fields that wanted it then refuse their writes:

field-encryption: properties.encryption.keys[1] (payments): no key — give it material, or a vault://… source
field-encryption: datastores declare key "pii_key" with two different sources ("vault://a" and "vault://b");
a field asking for it could mean either

Whatever the source gives is a passphrase, not a raw key: it is stretched to a 32-byte AES-256 key with SHA-256, bound to the key id, so two names never collapse onto one key even when the material behind them is the same. A tenant-scoped key binds the tenant as well. You do not need to supply 32 bytes, and a long random string is a better passphrase than a short one.

Vault reads are cached per (tenant, key id), so a key costs one round trip per tenant per key rather than one per write.

A deployment that has declared no keys at all — neither on a datastore nor in properties — keeps the older arrangement, unchanged. A key name not covered by the block falls through to it too.

#SourceConfigureUse it for
1Vault, by conventionRegister a secret store (vault.url, or vault.file for the file-backed local one); a tenant’s own key lives at fieldkeys/<customer>/<env>/<product>/<tenant>/<name> in the local vault, or as fieldkeys.<name> in the tenant’s scope in the remote vault; a tenant with none uses the bare <name>A deployment predating the encryption: block
2Local passphraseproperties.fieldencryptionkeyA deployment with no vault yet. Warns at boot
3Development keyproperties.fieldencryptiondevkey: trueLocal development only. Never a deployment

Here per-tenant keys are a convention with a probe rather than a declaration: the service asks the vault whether fieldkeys/<cept>/<name> exists, uses it if so, and otherwise falls back to the service-wide secret — saying so once per tenant:

field-encryption: this tenant has NO key of its own, so its encrypted fields share one key with
every other tenant on this deployment — a single compromise reads them all, and the tenant cannot
be crypto-shredded. Create the vault secret to give it one secret=fieldkeys/acme/test/shop/t1/default

Without a vault there is nothing to probe, so the local passphrase derives a different key per tenant by itself. One passphrase, many keys.

Prefer the encryption: block for anything new. It says in the document what the probe has to discover at runtime, it lets one key be deliberately shared and another deliberately not, and it can point at a customer-held path the convention has no way to express.

A missing or empty secret is an error naming the secret, not a silent fallback: field-encryption: vault secret "payments" is empty.

With no vault registered, one passphrase serves every key name:

properties:
fieldencryptionkey: "a long random string from your secret manager"

The boot log says what this costs, once per process:

field-encryption: using the LOCAL key from properties.fieldencryptionkey — no vault is
registered, so the key is only as protected as the boot config and rotation is manual.

Different key names still derive different AES keys (the id is bound into the derivation), so default and payments are not interchangeable even when both come from this one passphrase.

properties:
fieldencryptiondevkey: true

This uses a constant compiled into the binary. Anyone holding the binary can decrypt every field it wrote, which is why it is never the default and why the boot log repeats it on every start. It exists so a developer can run the service without inventing a key, and for nothing else.

A tenant’s vault key rotates in place, while the service runs:

Terminal window
kis data keys rotate default --tenant acme:prod:shop:t1 --wait

or POST /admin/data/keys/rotations with {"key": "default"} (the admin maintenance role). The key is the name a field asks for. What happens:

  1. A new version of the tenant’s key secret is saved in the vault, with no expiry. The old version stays in the vault.
  2. New values are sealed under the new version — at once on the instance that rotated, within a minute everywhere else. Every value names the exact version that sealed it, so the old ones keep opening under theirs.
  3. A background rekey rewrites the tenant’s rows under that key onto the new version. A user’s write that lands in between wins. --wait follows it to the end; kis data keys status <id> (GET /admin/data/keys/rotations/<id>) shows its progress.
  4. kis data keys inventory (GET /admin/data/keys) counts the tenant’s rows under each version — nothing should be left under the old one once the rekey is done.

This needs fieldencryption.enabled: true and a vault that reads versions. A key that is a literal, or a vaultcluster:// or vaultkey:// key (one secret for every tenant), is not rotated per tenant: the request is refused, 409 key_not_rotatable.

A vaultcluster:// or vaultkey:// key is versioned too: its values name the secret’s version ($enc$cards@<version>$…), so saving a new value over it loses nothing. No single tenant rotates it. Instead:

  1. Save a new value of the secret in the vault. Within a minute every instance seals new values under it, and the old version keeps opening the values that name it.

  2. Rekey each tenant, which moves that tenant’s rows and no other’s:

    Terminal window
    kis data keys rekey cards --tenant acme:prod:shop:t1 --wait

    or POST /admin/data/keys/rekeys with {"key": "cards"}.

On a vault that does not read versions, the shared key is not versioned. The rekey is then refused, and a new value saved over the secret makes every value sealed under it unreadable.

Every rotation (a refused one too), each rekey’s start and end, and every value no key version opens are recorded in the tenant’s audit stream (data_audit_events), under whoever asked. Each rekey’s report is kept in data_key_rotation, so kis data keys status <id> answers on any instance, even after a restart.

A local-passphrase key has no vault to keep versions in. It rotates the older way, by a new entry and a version number:

  1. Publish the next key as a new entry named <key>.v<n> — default.v2:

    properties:
    fieldencryptionkeys:
    default:
    v2: "the next passphrase"
  2. Point the current version at it, and restart:

    properties:
    fieldencryptionkeyversion:
    default: 2

New rows are written under default.v2; rows under default keep decrypting, because their envelope names it. Keep the old entry for as long as any row carries its id — deleting it makes those rows undecryptable, and nothing warns first. For the vault’s keys fieldencryptionkeyversion is deprecated: rotate in place instead.

Ciphertext is stored as $enc$<key id>$<base64>, so the key that wrote a value is known when reading it, whatever the current key is. That is what makes every change on this page non-breaking — a row written before any of it keeps decrypting, because its id still resolves the way it did when it was written.

Id in the envelopeResolved by
paymentsthe declared entry payments — or, with no encryption: block, the legacy ladder
t:paymentsthe same, with the tenant of the reading request
payments.v2the declared entry payments.v2
t:payments@<version>exactly that version of the tenant’s key in the vault — never another

An id with no @<version> was written before keys were versioned; it is opened by trying the key’s versions newest first, and a rekey moves it to a versioned id.

A value that cannot be opened is returned as null, with a warning: decrypt_failed when the key could not be had (the vault unreachable — transient), decrypt_integrity when no version of the key opens it. The ciphertext is never returned as though it were the value.

compliances: [{type: hash}] is one-way, so it takes no key — but it does take a salt, from the vault secret hash-salt, or properties.fieldhashsalt without a vault. Without one the hashes are unsalted and the boot log names the fields:

boot: fields declare hash but no salt is configured (vault secret hash-salt or
properties.fieldhashsalt); their hashes are unsalted fields=customer.email_hash

Changing the salt changes every future hash, so existing hashes stop matching new ones. Treat it as set-once.

compliances: [{type: tokenize}] does not encrypt. The value is filed elsewhere and the row holds an opaque tk_ token, so the configuration is a store:

properties:
tokenizer: vault # production: the value goes to the configured vault

The vault tokenizer files each value under tokens/<customer>/<env>/<product>/<tenant>/<token>, so only that tenant’s requests can reverse a token; reads are cached in process for five minutes. tokenizer: memory keeps tokens in the process and loses them on restart — development and test only. With neither, writes to a tokenized field are refused with tokenizer_missing, the same way encryption refuses.

The boot log is the authority, and it says one of these once per process:

Log lineMeaning
declared keys are serving keys=… from_schema=… from_properties=…The encryption: block is in force, and the line says which names came from the schema and which from the deployment
(nothing)No block; a vault is registered and serving keys by convention — this case is silent
using the LOCAL key from properties.fieldencryptionkeyNo block, no vault
using the built-in DEVELOPMENT keyNot a deployment
NO KEY CONFIGURED — writes to every encrypted field will be refusedNothing configured. Also names the fields

Errors naming an entry (properties.encryption.keys[1] (payments): no key) sit above whichever of these applies: those entries were skipped, and only the fields that asked for them are affected.

If writes are being refused, the error carries the reason rather than a generic failure:

{"errors":[{"code":"create_failed","details":{"code":"encryption_key_missing"}}]}

What turning encryption on does to existing rows

Section titled “What turning encryption on does to existing rows”

With the vault’s keys (fieldencryption.enabled: true), each tenant’s rows stored in the clear are sealed in the background when the tenant loads, without touching updatedon or the version token. Until a row is sealed it reads as it is. With a local key, rows become ciphertext as they are written.

The reverse is not true: once a value is encrypted, removing the key makes it unreadable. Removing the encrypted declaration does not decrypt anything either — it stops new writes being encrypted while the old ciphertext stays as it is.