Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Security engineeringMixed 21 series

Secrets management

Every secrets programme is four verbs, and most teams only do the first.

Quick reference

Store, inject, rotate, revoke: the four steps that make a secret a secret.

  1. Store once — One store per environment, encrypted at rest, with a named owner and a rotation method.
  2. Inject late — A file at run time, from a workload that proved its identity with OIDC.
  3. Rotate on a clock — A schedule for time and an event for people, rehearsed in staging.
  4. 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.
StoreBest fit
Vault KVApp config with an audit trail
AWS Secrets ManagerAWS-native rotation for RDS
Kubernetes SecretOnly with encryption at rest on
Sealed SecretsGitOps, 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.json

A 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.

  1. Keep the secret out of the image and out of the build args.
  2. Mount it as a file, not as an environment variable.
  3. Authenticate the workload with OIDC, not a long-lived key.
  4. Scope the read to one path and one role.
  5. 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
MethodWhat it costs you
Env varVisible in the process and in dumps
Mounted fileNeeds a read path and a restart
CSI driverOne pod spec change per workload
OIDC exchangeShort-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
CredentialHow it rotates
Human passwordSSO, and the session is revoked
Static app secretScheduled, dual-credential swap
Dynamic database userA TTL, revoked at expiry
CI tokenOIDC, 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.

  1. List every credential the incident could have touched.
  2. Revoke leases by prefix, not one by one.
  3. Deactivate keys before deleting them; keep the audit trail.
  4. Kill sessions and refresh tokens, not only passwords.
  5. 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
WhatWhere you revoke it
Vault leasevault lease revoke -prefix
IAM access keyupdate-access-key --status Inactive
Service account tokenDelete the token, then the pod
OAuth sessionThe 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
PlaceWhy it is missed
CI variablesCopied into every fork
Test fixturesReal values with a fake name
Container layersDeleted in a later layer
Terraform stateReadable 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?

More notes: Security engineering

Open in the notes app: search, filters, copy This note on GitHub