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-GCMOnly 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 manager | Choose it when | Assurance | Credentials the service uses |
|---|---|---|---|
| AWS KMS | You run on AWS | High, keys in AWS KMS or CloudHSM-backed keys | Instance or task role, IRSA, or the standard AWS environment |
| Azure Key Vault | You run on Azure | High, optionally Managed HSM | Managed identity, workload identity, or the standard Azure environment |
| Google Cloud KMS | You run on Google Cloud | High, optionally HSM protection level | Attached service account, workload identity, or an application default credentials file |
| HashiCorp Vault Transit | You already run Vault or OpenBao | High, as strong as your Vault | Token file, token variable, AppRole or Kubernetes auth |
| PKCS#11 HSM (Compose installs) | You own an HSM and run Docker Compose | Highest when the key is created non-extractable on the HSM | HSM PIN from a file or an environment variable you name |
| Local master-key file (Compose installs) | Single node, evaluation, or no key manager available | Lower, see below | File mode 0600, owned by the service user |
| OCI Vault | You run on Oracle Cloud | High | OCI 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.
| Provider | vault.kms.provider | Settings |
|---|---|---|
| OCI Vault | oci | oci.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 KMS | aws | aws.key-id (ARN or alias), aws.region, optional aws.retired-key-ids |
| Azure Key Vault | azure | azure.vault-url, azure.key-name, optional azure.retired-key-names |
| Google Cloud KMS | gcp | gcp.key-name (full resource name), optional gcp.retired-key-names, gcp.key-ring |
| HashiCorp Vault | vault | vault.address, vault.key-name, vault.mount (default transit), vault.auth and its path settings, vault.namespace, vault.ca-cert-path |
| PKCS#11 HSM | pkcs11 | pkcs11.library, pkcs11.slot or pkcs11.slot-list-index, pkcs11.key-label, pkcs11.pin-file or pkcs11.pin-env, optional pkcs11.retired-key-labels |
| Local file | file | file.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_idDocker 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 rolekms:Encryptandkms:Decrypton it, andkms:DescribeKeyif 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
wrapKeyandunwrapKeypermitted. 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 needsupdateontransit/encrypt/<key>andtransit/decrypt/<key>. The address must behttps://. The service refuses key names with path characters, and plainhttp://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, thensudo 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.
- 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.
- Configure the new provider as
vault.kms.provider. Keep the old one reachable and list it invault.kms.read-providers(for examplefile) so it can still unwrap what it wrapped. - Call
GET /api/v1/admin/vault/keys/kek/status.needingRewrapis the number of tenant keys still under the old provider. It also shows a live health check of the new provider. - Call
POST /api/v1/admin/vault/keys/kek/migrate?dryRun=true, read the counts, then run it withdryRun=false. Every call to this route, dry runs included, must come from a signed-in person with theSUPER_ADMINrole and carry anX-Vault-Keys-Requestheader: a fresh value for each call, 16 to 64 characters fromA-Za-z0-9-. A missing header is refused with428, and a repeated value with409. Only one key operation runs at a time (409 RUN_IN_PROGRESSotherwise). - 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. - 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.
- When
needingRewrapis0, remove the old provider fromread-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
needingRewrapis0and the old provider is out ofread-providers. The service can do it for you:POST /api/v1/admin/vault/keys/kek/destroy-retired?provider=<id>&keyRef=<retired key>(same caller andX-Vault-Keys-Requestrules 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, addacknowledgeLoss=<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
- Do you own an HSM and run Docker Compose? Use PKCS#11 (Compose installs).
- Do you already run HashiCorp Vault or OpenBao? Use Transit.
- Are you on AWS, Azure or Google Cloud? Use that cloud's key service with workload identity.
- 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.
Run a command with vault secrets
Reference for safeguard vault exec, which runs a command with vault secrets set as environment variables and never prints them. Coming soon.
Using vault credentials in scans
Point DAST, API security, host scans and CLI scans at a shared vault entry by its handle, so the scan reads the secret when it runs and nobody pastes it into a scan target.