Safeguard Docs
Credentials Vault

Choosing a key manager for a self-hosted install

Pick the key manager that protects the Credential Vault on your own Safeguard deployment: AWS KMS, Azure Key Vault, Google Cloud KMS, HashiCorp Vault Transit, a PKCS#11 HSM, or a local master-key file. Configuration, switching, and what happens when it is down.

Choosing a key manager for a self-hosted install

On a self-hosted or on-prem deployment you choose where the vault's root key lives. The vault supports seven choices and uses exactly one at a time.

How the keys fit together

Root key (your KMS, HSM, Vault Transit or key file)   never leaves it
  tenant data key      wrapped by the root key
    vault key          wrapped by the tenant key, one per vault
      each secret      AES-256-GCM

Only the small tenant data keys are ever sent to the key manager to be wrapped or unwrapped. Secret values never are. Switching key manager re-wraps the tenant keys only, so no secret is re-encrypted and nothing is unavailable while you switch.

Which one should I use

Key managerChoose it whenAssuranceCredentials the service uses
AWS KMSYou run on AWSHigh, keys in AWS KMS or CloudHSM-backed keysInstance or task role, IRSA, or the standard AWS environment
Azure Key VaultYou run on AzureHigh, optionally Managed HSMManaged identity, workload identity, or the standard Azure environment
Google Cloud KMSYou run on Google CloudHigh, optionally HSM protection levelAttached service account, workload identity, or an application default credentials file
HashiCorp Vault TransitYou already run Vault or OpenBaoHigh, as strong as your VaultToken file, token variable, AppRole or Kubernetes auth
PKCS#11 HSM (Compose installs)You own an HSM and run Docker ComposeHighest when the key is created non-extractable on the HSMHSM PIN from a file or an environment variable you name
Local master-key file (Compose installs)Single node, evaluation, or no key manager availableLower, see belowFile mode 0600, owned by the service user
OCI VaultYou run on Oracle CloudHighOCI API signing identity

The local master-key file is lower assurance

Anyone who can read the key file and the database can decrypt every secret. Use it only on a single node. Keep the file on an encrypted volume, owned by the service user, mode 0600 or stricter, and back it up separately from the database. The service checks the file on every use and refuses to run if the path contains a symbolic link (the file or any parent directory), the file is owned by someone else, or it is readable by group or others. The check is race-safe: a file swapped while it is being read is refused. Because it refuses symbolic links, a Kubernetes Secret volume mount will not work with it. Move to one of the other choices when you can; the switch is the migration described below.

Configure one

Set vault.kms.provider (or the environment variable VAULT_KMS_PROVIDER). Nothing secret goes in these settings: they hold names, paths and endpoints. Credentials come from the environment of the platform, a mounted file, or workload identity.

Providervault.kms.providerSettings
OCI Vaultocioci.key-ocid, oci.region, oci.crypto-endpoint, oci.tenancy-ocid, oci.user-ocid, oci.fingerprint, oci.private-key-path (PKCS8 PEM file), optional oci.retired-key-ocids
AWS KMSawsaws.key-id (ARN or alias), aws.region, optional aws.retired-key-ids
Azure Key Vaultazureazure.vault-url, azure.key-name, optional azure.retired-key-names
Google Cloud KMSgcpgcp.key-name (full resource name), optional gcp.retired-key-names, gcp.key-ring
HashiCorp Vaultvaultvault.address, vault.key-name, vault.mount (default transit), vault.auth and its path settings, vault.namespace, vault.ca-cert-path
PKCS#11 HSMpkcs11pkcs11.library, pkcs11.slot or pkcs11.slot-list-index, pkcs11.key-label, pkcs11.pin-file or pkcs11.pin-env, optional pkcs11.retired-key-labels
Local filefilefile.path, optional file.retired-paths

All settings are prefixed vault.kms.. Example, Vault Transit with AppRole:

vault.kms.provider: vault
vault.kms.vault.address: https://vault.internal:8200
vault.kms.vault.key-name: safeguard-kek
vault.kms.vault.auth: approle
vault.kms.vault.role-id: 00000000-0000-0000-0000-000000000000
vault.kms.vault.secret-id-file: /run/secrets/sg_vault_secret_id

Docker Compose examples for every provider, and Helm examples for AWS KMS, Azure Key Vault, Google Cloud KMS and Vault Transit, ship in deploy/self-hosted/kms/ in the notification service.

PKCS#11 and the local key file are supported on Docker Compose (single host) installs today. The Helm chart cannot yet mount a key file, an HSM PIN or a vendor module, so on Kubernetes use a cloud key service or Vault Transit.

The key id and the Vault address you configure are part of what identifies a key. Once values are written, keep the same form of the key id (do not swap an ARN for an alias) and the same Vault address and key name, or stored keys will not find their key. That fails closed, but it is an outage.

What each provider needs from you

  • AWS KMS. A symmetric key (ENCRYPT_DECRYPT). Grant the service role kms:Encrypt and kms:Decrypt on it, and kms:DescribeKey if you will use the destroy route. Create, rotate and delete keys with AWS's own tooling.
  • Azure Key Vault. An RSA key (3072 bit recommended) with wrapKey and unwrapKey permitted. The key version is stored beside each wrapped value, so rotating the key does not break older values.
  • Google Cloud KMS. A symmetric encrypt/decrypt key. Grant cloudkms.cryptoKeyEncrypterDecrypter.
  • HashiCorp Vault. A Transit key of type aes256-gcm96. The policy needs update on transit/encrypt/<key> and transit/decrypt/<key>. The address must be https://. The service refuses key names with path characters, and plain http:// unless a developer flag is set.
  • PKCS#11 HSM. An AES-256 key with a label, created non-extractable on the HSM, on a module that supports CKM_AES_GCM (tested with SoftHSM2). Safeguard uses the JDK's own SunPKCS11 provider, so there is nothing extra to install except your vendor's module.
  • Local file. 32 random bytes, as raw bytes, 64 hex characters, or base64 (a 32-character passphrase is refused). Create one with umask 077; head -c 32 /dev/urandom | base64 > vault-master.key, then sudo chown 1003:1003 vault-master.key: the file must be owned by the user the container runs as, and Compose secrets keep the host owner.

If the key manager is down

The vault fails closed. Tenant keys are kept unwrapped in memory for at most five minutes. After that, if the key manager cannot be reached, requests that need a key return 503 and nothing is served from a stale key. Error messages carry a fixed phrase and the exception class only: never key material, ciphertext or a response body. The local-file provider names the file path and its mode.

Check health at any time with GET /api/v1/admin/vault/keys/kek/status. It reports the active provider, how many tenant keys sit under each provider and a live round-trip health check.

Switch to another key manager

You can move between any two choices, including from the old environment master key onto a KMS. Switching is resumable and audited, and only platform administrators who are people (the SUPER_ADMIN role, not agent or service tokens) can run it.

  1. Make sure the new key can both encrypt and decrypt with the service identity. A key that can encrypt but not decrypt is caught by the verify step below, but you save a failed run by checking first.
  2. Configure the new provider as vault.kms.provider. Keep the old one reachable and list it in vault.kms.read-providers (for example file) so it can still unwrap what it wrapped.
  3. Call GET /api/v1/admin/vault/keys/kek/status. needingRewrap is the number of tenant keys still under the old provider. It also shows a live health check of the new provider.
  4. Call POST /api/v1/admin/vault/keys/kek/migrate?dryRun=true, read the counts, then run it with dryRun=false. Every call to this route, dry runs included, must come from a signed-in person with the SUPER_ADMIN role and carry an X-Vault-Keys-Request header: a fresh value for each call, 16 to 64 characters from A-Za-z0-9-. A missing header is refused with 428, and a repeated value with 409. Only one key operation runs at a time (409 RUN_IN_PROGRESS otherwise).
  5. For each tenant key the service wraps with the new provider, unwraps that new wrap again through the new provider, compares it with the key, and only then replaces the old wrap, and only if the row still holds the old wrap. If anything fails, that key keeps its old wrap. The run stops at the first failure and is recorded as ABORTED.
  6. Fix the cause and run it again. Keys already moved are skipped. A real run also refuses to start while the new provider fails its health check.
  7. When needingRewrap is 0, remove the old provider from read-providers.

Every real run writes a closed audit row (who, from, to, counts and the outcome COMPLETED or ABORTED) and one row per tenant key (tenant, key version, old and new key tag, outcome, error class).

Rotate and shred

  • Rotate the root key by making a new key in your key manager with its own tooling, pointing the configuration at it, listing the old key as retired, and running the migration. AWS KMS can also rotate the backing key by itself and Vault Transit can add a key version; older values keep unwrapping either way.
  • Destroy a retired key only after needingRewrap is 0 and the old provider is out of read-providers. The service can do it for you: POST /api/v1/admin/vault/keys/kek/destroy-retired?provider=<id>&keyRef=<retired key> (same caller and X-Vault-Keys-Request rules as migrate). It refuses a key that is not listed as retired, a key that is the active one under any name (an alias and an ARN of the same key count as the same key), and a key that still wraps any tenant key. To destroy a key that still wraps tenant keys on purpose, add acknowledgeLoss=<exact count>: that data becomes permanently unreadable. The call clears the in-memory key cache and writes an audit row.
  • Destruction takes effect on the provider's schedule. AWS KMS has a 7 to 30 day pending-deletion window, Azure Key Vault soft-deletes the key (purge protection extends the recovery window), and Google Cloud KMS schedules the destruction of each key version. The key stays recoverable until then. The service holds unwrapped tenant keys in memory for at most five minutes, so after the provider's window ends, restart the service or wait five minutes and nothing stays readable.
  • Deleting a single vault shreds that vault's own key and leaves every other vault untouched.

Pick the right one in a minute

  1. Do you own an HSM and run Docker Compose? Use PKCS#11 (Compose installs).
  2. Do you already run HashiCorp Vault or OpenBao? Use Transit.
  3. Are you on AWS, Azure or Google Cloud? Use that cloud's key service with workload identity.
  4. None of the above, one node on Docker Compose, and you can protect a file? Use the local file (Compose installs), and plan to move.

On this page