Secret managers
Nakama reads two kinds of secret from its environment:
NAKAMA_SECRETS_KEY, the master key that encrypts saved Settings keys, Telegram and Discord bot tokens, and scheduled backups. It is read only as an environment variable.- Key overrides such as
OPENAI_API_KEYorANTHROPIC_API_KEY. Each one can also come from a file: setOPENAI_API_KEY_FILE=/run/secrets/openaiand Nakama reads that file instead. A direct variable wins over its_FILEform.
Whatever the manager, the rules are the same:
- Pin the master key to one secret version, never "latest". A new version picked up on restart is a different key, and Nakama stops at startup because it cannot decrypt what it saved.
- Keep the key out of the data root and out of
NAKAMA_BACKUP_DIR. - Give every Nakama process that shares the database the same value.
HashiCorp Vault
Render an env file with Vault Agent and pass it to the container:
template {
destination = "/run/nakama/secrets.env"
perms = "0600"
contents = <<EOT
NAKAMA_SECRETS_KEY={{ with secret "kv/data/nakama" }}{{ .Data.data.secrets_key }}{{ end }}
EOT
}docker run --env-file /run/nakama/secrets.env -v nakama-data:/nakama/data ghcr.io/ahmadrosid/nakama:latestRender each override to its own file and point the _FILE variable at it. A KV v2 secret keeps its versions, so pin ?version= in the path when you rotate.
AWS Secrets Manager
On ECS, map the secret into the task definition. The ARN suffix pins the version:
"secrets": [
{
"name": "NAKAMA_SECRETS_KEY",
"valueFrom": "arn:aws:secretsmanager:region:account:secret:nakama-secrets-key::AWSCURRENT:"
}
]Replace AWSCURRENT with a version stage or ID you control before a rotation. On a VM, fetch it at boot with aws secretsmanager get-secret-value --secret-id nakama-secrets-key --version-id <id> --query SecretString --output text into an env file under /run.
GCP Secret Manager
On a VM, fetch a pinned version at boot:
printf 'NAKAMA_SECRETS_KEY=%s\n' \
"$(gcloud secrets versions access 3 --secret=nakama-secrets-key)" \
> /run/nakama/secrets.envOn GKE, sync it into a Kubernetes Secret with the External Secrets Operator, pinned to a version, then expose it as an environment variable named NAKAMA_SECRETS_KEY. The same operator also works for Vault and AWS. See rotation before changing the version.
Rotating the master key
- Stop every Nakama process and take a backup.
- Add the new key as a new secret version. Leave the old version in place.
- Start Nakama once with
NAKAMA_SECRETS_KEYset to the old version andNAKAMA_SECRETS_KEY_NEXTset to the new one. It re-encrypts the saved values and exits. - Point
NAKAMA_SECRETS_KEYat the new version and start Nakama normally.
Keep the old version while any backup made with it might still be restored.