Quick reference
Store, inject, rotate, revoke: the four steps that make a secret a secret.
- Store once — One store per environment, encrypted at rest, with a named owner and a rotation method.
- Inject late — A file at run time, from a workload that proved its identity with OIDC.
- Rotate on a clock — A schedule for time and an event for people, rehearsed in staging.
- Revoke to prove it — Leases by prefix, keys to Inactive, sessions killed, and a list of what is left.
In one line: Store, inject, rotate, revoke. Skip the fourth step and the first three are decoration.
Start this week:
- Start with the secrets that are in a repo today.
- Pick one store and migrate the rest into it this quarter.
- Add a rotation to every secret, then a revocation test.
Explained
Store: one place per environment, encrypted at rest, with an owner and a rotation method beside it. A Kubernetes Secret is base64, not encryption, and etcd holds it unless encryption at rest is switched on.
Inject: at run time, into a file, from a workload that proved its identity. An environment variable is visible to every process in the container and survives in a crash dump.
Rotate: on a clock and on an event. The clock covers time; the event covers the day someone leaves. Prefer credentials that expire on their own, because a TTL cannot be forgotten.
Revoke: leases by prefix, keys to Inactive before you delete them, sessions killed at the identity provider. A rotation without a revocation is a rename.
Then find what leaked. Scan the whole history, verify each finding against the provider, revoke first and rewrite history second.
Checklist
Run it before the review and after every incident. Each line has a command or a log behind it, or it does not count.
Store
- One store per environment, and the README names it.
- Every secret has an owner and a rotation method.
- Kubernetes secrets sit on a cluster with encryption at rest.
Inject
- No secret in an image, a build arg or a Dockerfile.
- Workloads read a file, and fail closed when it is absent.
- Cloud access uses OIDC, not a stored access key.
Rotate
- The last rotation date is recorded per secret.
- Leavers trigger a rotation inside the hour.
- A staging rotation has run in the last quarter.
Revoke
- Leases are revoked by prefix, not one at a time.
- Old keys are set to Inactive before deletion.
- History was scanned and every finding was either dead or revoked.
The field guide
The full guide of the PDF (P976), page by page.
One place, not five (store)
A secret in five places is five secrets, and only one of them gets rotated. Pick one store per environment and make everything else read from it.
- One store per environment, named in the repo README.
- Encrypt at rest and restrict who can read, not only who can write.
- Never in a Dockerfile, a CI variable and a wiki page at once.
- Record the owner and the rotation method next to the secret.
| Store | Best fit |
|---|---|
| Vault KV | App config with an audit trail |
| AWS Secrets Manager | AWS-native rotation for RDS |
| Kubernetes Secret | Only with encryption at rest on |
| Sealed Secrets | GitOps, encrypted in the repo |
Write one, read one
vault kv put secret/payments/db password="$PGPASS"
vault kv get -field=password secret/payments/db
aws secretsmanager create-secret --name prod/payments/db \
--secret-string file://db.jsonA Kubernetes Secret is base64 It is encoded, not encrypted. Anyone who can get secrets in that namespace can read it, and etcd holds it unless encryption at rest is configured.
One store, one owner, one rotation method: anything else is a copy you forgot.
At run time, never in the image (inject)
The image should not contain the secret and the pipeline should not hold it either. Inject at start, into a file, and let the workload prove who it is.
- Keep the secret out of the image and out of the build args.
- Mount it as a file, not as an environment variable.
- Authenticate the workload with OIDC, not a long-lived key.
- Scope the read to one path and one role.
- Fail closed when the secret is missing.
A pod's annotations, then a ci job's permissions
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "payments"
vault.hashicorp.com/agent-inject-secret-db: "secret/data/payments/db"
permissions:
id-token: write
contents: read| Method | What it costs you |
|---|---|
| Env var | Visible in the process and in dumps |
| Mounted file | Needs a read path and a restart |
| CSI driver | One pod spec change per workload |
| OIDC exchange | Short-lived, but needs a trust policy |
If the secret is in the image, every registry copy is a copy of the secret.
On a clock and after people leave (rotate)
Rotation is a schedule plus an event. The schedule covers time; the event covers the day someone with access walks out of the door.
- Rotate on a fixed interval and record the last rotation.
- Rotate within the hour when anyone with access leaves.
- Prefer credentials that expire on their own.
- Rehearse the rotation in staging: a broken rotation is an outage.
Rotate a static secret, then mint a dynamic one
aws secretsmanager rotate-secret --secret-id prod/payments/db \
--rotation-lambda-arn arn:aws:lambda:eu-west-1:123456789012:function:rotate
vault write database/config/payments \
plugin_name=postgresql-database-plugin \
allowed_roles="payments-ro" \
connection_url="postgresql://{{username}}:{{password}}@db:5432/payments" \
username="vault" password="$VAULT_DB_PASS"
vault read database/creds/payments-ro| Credential | How it rotates |
|---|---|
| Human password | SSO, and the session is revoked |
| Static app secret | Scheduled, dual-credential swap |
| Dynamic database user | A TTL, revoked at expiry |
| CI token | OIDC, minutes rather than months |
Rotation without revocation is a rename, and the old credential still works.
The step everyone skips (revoke)
A revoked credential is the only proof the rotation worked. Revoke by lease where you can, by key status where you cannot, and write down what is left.
- List every credential the incident could have touched.
- Revoke leases by prefix, not one by one.
- Deactivate keys before deleting them; keep the audit trail.
- Kill sessions and refresh tokens, not only passwords.
- Write down what you could not revoke, and who accepted it.
Revoke, deactivate, purge
vault lease revoke -prefix database/creds/payments-ro
aws iam update-access-key --user-name svc-deploy \
--access-key-id AKIAIOSFODNN7EXAMPLE --status Inactive
git filter-repo --path config/.env --invert-paths| What | Where you revoke it |
|---|---|
| Vault lease | vault lease revoke -prefix |
| IAM access key | update-access-key --status Inactive |
| Service account token | Delete the token, then the pod |
| OAuth session | The identity provider, not the app |
A key set to Inactive still exists, and an unrevoked lease outlives the incident.
Find what already leaked (detect)
Assume one secret is already in the history. The only questions are which one, and whether it was ever valid.
- Scan the whole history, not just the working tree.
- Verify the finding against the provider before panicking.
- Rewrite history only after the credential is dead.
- Turn on push protection so the next one never lands.
Scan, verify, then rewrite
gitleaks detect --source . --redact
trufflehog git file://. --only-verified
git filter-repo --path config/.env --invert-paths| Place | Why it is missed |
|---|---|
| CI variables | Copied into every fork |
| Test fixtures | Real values with a fake name |
| Container layers | Deleted in a later layer |
| Terraform state | Readable by the whole team |
A rewrite is not a revocation Rewriting history leaves the secret in every clone, fork and CI cache. Revoke first, rewrite second, and tell the team to re-clone.
The secret is not the file you deleted; it is every copy anyone else kept.
The honest caveat: a vault does not stop an application logging its own config. The secret ends up in the log aggregator, which is usually readable by more people than the database was.
The lesson: store, inject, rotate, revoke - skip the fourth and the first three are decoration.
Your turn: Which of the four steps does your team finish?
Related on this site
More notes: Security engineering
Open in the notes app: search, filters, copy This note on GitHub