Skip to content

Keys and Key Management

Self-Hosted Only

Some of what organizations store is sealed, encrypted inside the database with keys of their own: drafts and their conversations with the assistant, comments, single sign-on client secrets and authenticator-app secrets.

  • Data keys. Each organization has its own data keys (AES-256-GCM), one active at a time. The database holds them only wrapped.
  • The key-encryption key (KEK) wraps every data key. No sealed value is ever sent to it: it only wraps and unwraps data keys.
  • The folder of keys (Assistant:KeysPath) holds the keys that protect the credentials organizations store, such as their own AI key, and, unless the KEK lives in a key service, the KEK itself as forge-kek.key.

Revisions of models are not sealed: each keeps its SHA-256 fingerprint, which re-encrypting would break. The database’s own storage encryption covers them.

Encryption:Kek chooses:

Value Where For
file (the default) forge-kek.key in the folder of keys, made on first use One server, an install with no way to a cloud, development
aws-kms A symmetric key in AWS KMS An install on AWS
azure-key-vault An AES key (oct-HSM) in an Azure Key Vault Premium vault, or a Managed HSM An install on Azure
gcp-kms A symmetric key in Google Cloud KMS An install on Google Cloud

With a key service, the KEK never leaves it, every use of it is in the service’s own log, and turning the key off closes the sealed data within ten minutes.

  1. Make a symmetric key, usage “Encrypt and decrypt”. Keep the people who manage it apart from the role that uses it.
  2. Give the API’s role kms:Encrypt and kms:Decrypt on that key only, with the condition kms:EncryptionContext:purpose equals forge-dek. On EKS use Pod Identity, on ECS the task role.
  3. Set Encryption:Kek to aws-kms and Encryption:KmsKey to the key’s ARN, arn:aws:kms:<region>:<account>:key/<id>. An alias is refused: every data key records the name of the key that wrapped it, and an alias can be pointed elsewhere.
  4. For the FIPS endpoint, as in AWS GovCloud, set Encryption:AwsUseFipsEndpoint to true.
  1. Make a Premium vault, with role-based permissions, soft delete and purge protection on; or a Managed HSM.
  2. Make an oct-HSM AES-256 key with the operations encrypt and decrypt. RSA keys are refused, because wrapping with one needs only its public key.
  3. Give the API’s managed identity, or its workload identity on AKS, the role Key Vault Crypto User on that key.
  4. Set Encryption:Kek to azure-key-vault, Encryption:KmsKey to the key’s URL without a version (https://<vault>.vault.azure.net/keys/<name>), and Encryption:AzureClientId when the identity is user-assigned. Rotating the key in the vault is safe: what an older version wrapped still opens.
  1. Make a key ring in a regional location and a symmetric key in it; protection level HSM for FIPS 140 Level 3.
  2. Give the API’s service account roles/cloudkms.cryptoKeyEncrypterDecrypter on that key only.
  3. Set Encryption:Kek to gcp-kms and Encryption:KmsKey to the key’s name without a version: projects/<project>/locations/<location>/keyRings/<ring>/cryptoKeys/<key>.

None of these settings is a secret: the API reads only the key’s name, and its credentials come from the platform it runs on.

A customer can have its organization’s data keys wrapped by a key in its own AWS KMS, Azure Key Vault or Google Cloud KMS, in place of the instance’s KEK. Withdrawing the key, or the grant on it, closes that organization’s sealed data within ten minutes, and no one else’s.

Operators give an organization its key in the platform console: see The platform console. The key is tried before it is saved, and the application uses it only while its record opens under the instance’s own KEK, so someone who can write to the database alone cannot point an organization at a key of theirs.

Encryption:CustomerKeys in the instance’s settings does the same, and wins for an organization it names: list each organization’s id, Kek and Key, and for Azure its AzureTenantId.

Change the settings and restart the API. The old KEK stays in the instance’s ring, only to unwrap what it wrapped:

  • moving from the key file: the file stays in the folder;
  • moving from one key in a service to another: name the old one in Encryption:EarlierKmsKeys.

The background re-encryption then rewraps every data key under the new KEK, within minutes; the log says how many. When it has finished, the old key can go.

The same background work re-seals values when an organization’s data key is rotated, in small batches, and turns the old data key off once nothing uses it. An operator rotates an organization’s data key in the platform console, under Keys, with a reason; see The platform console. The console’s audit records the rotation and each round of re-sealing.

  • Data keys unwrapped in the last day go on working, so the organizations in use carry on as usual.
  • What needs a key this instance has not unwrapped lately, such as after a restart, answers 503 The encryption keys are not available. Nothing is half-written.
  • A key that is turned off, or a permission withdrawn, closes what it protects within ten minutes.
  • A call that takes longer than five seconds counts as unreachable (Encryption:KmsTimeLimit).
  • The database, with point-in-time recovery.
  • The folder of keys, separately from the database, readable by the API’s account alone. Every API instance must share it. With the KEK in a key service the folder still holds the keys of stored credentials.
  • The key service’s key is the service’s to keep. Never delete it while anything it wrapped may be restored from a backup.