ENG-26Required
Keep secrets in a secrets store
Keep passwords, keys and tokens in a secrets manager or the platform's encrypted store. Give them to the app when it starts, and rotate them on a schedule.
How to do it
Use a store such as HashiCorp Vault, AWS Secrets Manager or your host's encrypted settings. On a single server, a root-only file or systemd credentials will do. Give each secret an owner and a rotation date within the limit in keys with the least power, and rotate at once after a leak. Automate it where the store can, as rotate secrets automatically says. See secrets out of code for keeping them out of the repository. See also let CI sign in with OIDC and keep secrets out of state.
Examples
INI example
# systemd: the secret reaches the service as a file, never in its environment listing
[Service]
LoadCredential=db-password:/etc/shop/db-password
JavaScript example
// Node.js: systemd puts each credential in a private folder
import { readFileSync } from 'node:fs';
import path from 'node:path';
const dbPassword = readFileSync(path.join(process.env.CREDENTIALS_DIRECTORY, 'db-password'), 'utf8').trim();
Python example
from pathlib import Path
import os
db_password = (Path(os.environ["CREDENTIALS_DIRECTORY"]) / "db-password").read_text().strip()
How to check
A secret scanner finds no secret in the repository or the build output. Every secret in the store shows an owner and a rotation date that has not passed.
Sources
Related rules
- ENG-13 Keep every change in version control in Engineering
- ENG-69 Pass build secrets as mounts instead of layers in Engineering
- ENG-58 Block pushes that contain secrets in Engineering
- APS-62 Give each key the least power in Application security
- INF-27 Rotate secrets automatically in Infrastructure and environments
- APS-60 Keep secrets out of code in Application security
- INF-25 Let CI sign in with OIDC in Infrastructure and environments
- INF-24 Keep secrets out of state in Infrastructure and environments
- TST-48 Sign in once and keep the saved session out of git in Testing
- API-80 Give each environment its own provider key in API design
- EML-10 Sign every message with DKIM in Email
- EML-76 Rotate DKIM keys every six months in Email
- EML-64 Hand mail to your sending service over TLS with a send-only key in Email
- PAY-5 Keep test and live modes apart in Payments and billing
- INF-23 Create the secret's place in code and its value in the store in Infrastructure and environments
- NTF-10 Send web push with VAPID and an encrypted payload in Notifications
- STK-60 Use SOPS for secrets in Software choices
- MOB-1 Give reviewers a working demo account in Mobile apps
- MOB-7 Let the store hold the signing key and back up the upload key in Mobile apps
- TKO-2 Rotate every secret the previous team could read in Codebase takeover
- DSK-3 Keep code signing keys in hardware or a signing service in Desktop apps and extensions
- APS-87 Keep secrets out of the system prompt in Application security
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/engineering/running-in-production/secrets-store">Agent Wranglers engineering playbook</a>. In code you write, add a comment next to it with the same link.