Keep the key in Azure Key Vault, AWS KMS or Google Cloud KMS
Keep the key-encryption key in a cloud key service, so it never reaches the server.
Developers and self-hosters who already use field encryption or encrypted backups and want the key in a cloud service.
With a cloud key, Claviger asks the service to wrap and unwrap the data keys. Record data never goes to the cloud. If the cloud key is deleted, the data is unreadable.
What you will do, in one sentence
Pick one key source, give the server an identity that may wrap and unwrap, and for AWS or Google build with the right tag.
Screens are captured from a seeded test system. Every name, address and number on the screens is invented. Prepared 15 November 2026.
1. Choose one source
Set exactly one key source. Two sources at once is an error. The server never falls back to another key.
| Source | Variable | Build |
|---|---|---|
| Azure Key Vault or Managed HSM | CLAVIGER_KEK_AZURE_KEY_ID | Release image |
| AWS KMS | CLAVIGER_KEK_AWS_KEY_ID | Your own build with -tags kms_aws |
| Google Cloud KMS | CLAVIGER_KEK_GCP_KEY_ID | Your own build with -tags kms_gcp |
Calls happen only at start-up, when a new encrypted field gets its data key, and when you rotate or re-wrap. Reads and writes do not call the cloud. An outage while the app runs changes nothing.
The three runbooks in the engine repository say they have not been run against a real vault, account or project. The code is tested against fakes in CI. Run the drill in a throw-away environment first.
2. Azure Key Vault
-
Create an RSA key, 3072 or 4096 bits, with the
wrapKeyandunwrapKeyoperations. A Managed HSM AES key also works. EC keys are refused. -
Give the server's identity a role on the key. With Azure RBAC, use Key Vault Crypto User. On a Managed HSM, use Managed HSM Crypto User. With access policies, grant
get,wrapKeyandunwrapKey. -
Set the key id and let the server pick the identity:
CLAVIGER_KEK_AZURE_KEY_ID=https://<vault>.vault.azure.net/keys/<key>CLAVIGER_KEK_AZURE_AUTH=autoWithout a version, the current version is pinned at start. Add
/<version>to pin one.
auto tries workload identity, then a client secret, then managed identity. A client secret is for development. Use an identity without a secret in production. Client certificates are not supported.
Allow the server to reach <vault>.vault.azure.net on port 443. A blocked path looks like a timeout, and Claviger treats it as an outage.
Turn on soft delete and purge protection on the vault.
3. AWS KMS and Google Cloud KMS
Build your own binary or image. The release build has neither source:
go build -tags kms_aws,kms_gcp -o claviger ./examples/base
docker build --build-arg GO_TAGS=kms_aws,kms_gcp -t claviger:kms .
If the variable is set in a build without the tag, the app does not start. The error names the variable and the tag.
AWS KMS
-
Create a symmetric
ENCRYPT_DECRYPTkey. Asymmetric and HMAC keys are refused. -
Allow the identity
kms:DescribeKey,kms:Encryptandkms:Decrypton that key. -
Set the key. An ARN carries its region. A key id or alias needs
AWS_REGION:CLAVIGER_KEK_AWS_KEY_ID=<key-arn>AWS_REGION=<region>
Claviger stores the key ARN, so repointing an alias later cannot change the key. Do not write key policies that require an encryption context other than purpose=claviger-dek-wrap.
Google Cloud KMS
-
Create a symmetric key with an enabled primary version.
-
Grant the service account
roles/cloudkms.cryptoKeyEncrypterDecrypteron the key. -
Set the key resource name, with no version:
CLAVIGER_KEK_GCP_KEY_ID=projects/<project>/locations/<location>/keyRings/<ring>/cryptoKeys/<key>
Credentials come from GOOGLE_APPLICATION_CREDENTIALS (a service account key file), or from the metadata server on Google Cloud. Prefer an attached service account. Authorized-user files and workload identity federation files are not supported.
4. Check, start and fail
Run claviger keys check --dir=/pb_data before a deploy.
| Result | Meaning |
|---|---|
keys check: FAILED | A definite refusal: bad credentials, missing permission, key not found. The rollout stops before the handover. |
skipped (could not reach the key-encryption key service ...), exit 0 | Inconclusive: timeout, network error, throttling or a 5xx. The check does not block. |
| App refuses to start | Encrypted fields exist and the service cannot be reached or refuses the request. This is by design. |
Calls are retried with backoff first. Credentials, tokens and key material are never logged.
5. Rotate and move between sources
Moving between sources uses the same re-wrap flow as any key rotation.
- Set the new source as primary.
- Set the previous key in the matching
*_OLDvariable:CLAVIGER_KEK_OLD,CLAVIGER_KEK_AZURE_KEY_ID_OLD,CLAVIGER_KEK_AWS_KEY_ID_OLDorCLAVIGER_KEK_GCP_KEY_ID_OLD. Set only one. - Start, then run
claviger keys rewrapor Re-wrap under the new KEK in Settings, Encryption keys. - Remove the
*_OLDvariable.
New key versions need different handling per service:
- Azure: a new version is a KEK rotation. Restart, then re-wrap. Disable the old version only when nothing uses it.
- AWS: automatic key rotation keeps the ARN. Nothing needs re-wrapping.
- Google: new versions are transparent. Nothing needs re-wrapping.
Do not schedule deletion of an old key, or destroy a key version, before the re-wrap has finished. AWS key deletion is irreversible. Encrypted backups made under the key become unreadable too.
6. Quick reference card
Pick a source
- Azure: release image, RSA key,
CLAVIGER_KEK_AZURE_KEY_ID. - AWS:
-tags kms_aws, symmetric key,CLAVIGER_KEK_AWS_KEY_ID. - Google:
-tags kms_gcp, symmetric key,CLAVIGER_KEK_GCP_KEY_ID.
Before every deploy
claviger keys check --dir=/pb_data.FAILEDmeans stop.skippedmeans the check could not decide.
Exactly one key source may be set. The server never falls back to a local key.