Skip to main content

Keep the key in Azure Key Vault, AWS KMS or Google Cloud KMS

DEVELOPER GUIDE

Keep the key-encryption key in a cloud key service, so it never reaches the server.

Who this guide is for

Developers and self-hosters who already use field encryption or encrypted backups and want the key in a cloud service.

Why it matters

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.

SourceVariableBuild
Azure Key Vault or Managed HSMCLAVIGER_KEK_AZURE_KEY_IDRelease image
AWS KMSCLAVIGER_KEK_AWS_KEY_IDYour own build with -tags kms_aws
Google Cloud KMSCLAVIGER_KEK_GCP_KEY_IDYour 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.

Runbooks are not yet run against a real cloud

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​

  1. Create an RSA key, 3072 or 4096 bits, with the wrapKey and unwrapKey operations. A Managed HSM AES key also works. EC keys are refused.

  2. 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, wrapKey and unwrapKey.

  3. 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=auto

    Without 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​

  1. Create a symmetric ENCRYPT_DECRYPT key. Asymmetric and HMAC keys are refused.

  2. Allow the identity kms:DescribeKey, kms:Encrypt and kms:Decrypt on that key.

  3. 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​

  1. Create a symmetric key with an enabled primary version.

  2. Grant the service account roles/cloudkms.cryptoKeyEncrypterDecrypter on the key.

  3. 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.

ResultMeaning
keys check: FAILEDA 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 0Inconclusive: timeout, network error, throttling or a 5xx. The check does not block.
App refuses to startEncrypted 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.

  1. Set the new source as primary.
  2. Set the previous key in the matching *_OLD variable: CLAVIGER_KEK_OLD, CLAVIGER_KEK_AZURE_KEY_ID_OLD, CLAVIGER_KEK_AWS_KEY_ID_OLD or CLAVIGER_KEK_GCP_KEY_ID_OLD. Set only one.
  3. Start, then run claviger keys rewrap or Re-wrap under the new KEK in Settings, Encryption keys.
  4. Remove the *_OLD variable.

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.
Deleting the cloud key loses the data

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​

  1. Azure: release image, RSA key, CLAVIGER_KEK_AZURE_KEY_ID.
  2. AWS: -tags kms_aws, symmetric key, CLAVIGER_KEK_AWS_KEY_ID.
  3. Google: -tags kms_gcp, symmetric key, CLAVIGER_KEK_GCP_KEY_ID.

Before every deploy​

  1. claviger keys check --dir=/pb_data.
  2. FAILED means stop. skipped means the check could not decide.

Exactly one key source may be set. The server never falls back to a local key.