Secrets - vaults and rotation
API keys, database tokens and secrets leave the repository and move to vaults with automatic rotation, short-lived identity and centralized audit logging.
What it is
A secret in the cloud is anything that grants access: an API key, a database password, a service token, a private certificate. The critical point is not storing the value, it is controlling who can read it, at what moment, and with what trail.
Three practices repeat in any mature architecture: the secret lives in a vault (Vault, Secrets Manager, Parameter Store), the application reads it at runtime (not at build), and the lifetime is short. A credential that lasts a year can be revoked up to 365 days after the leak, and that is where the real risk lives.
The classic incident pattern
The same plot shows up every week: someone commits an AWS Access Key to a public repository or a chat. Miner bots sweep GitHub in minutes, find the key, check whether it still works and start mining crypto on the victim's reserved instances. The bill arrives before the alert.
The detail that kills: the key was in an environment variable, so the team thought they had not 'committed a secret'. But the .env.example with a placeholder, the screenshot of the cloud console, the CI log with the value printed... each of these leaks. Scanning for 'AWS_ACCESS_KEY_ID' in the repository before merge is basic hygiene that almost nobody does.
Static secret versus workload identity
The old way is static: create an user for the application, generate Access Key + Secret, paste into .env and run. The secret stays valid until someone revokes it, and each new deploy multiplies who holds a copy.
The modern way is workload identity. On AWS it is called IRSA (IAM Roles for Service Accounts), on GCP it is Workload Identity, on Azure it is Workload Identity Federation. The idea is the same: the cluster (EKS, GKE, AKS) hands a short-lived token to the pod, and the cloud exchanges that token for temporary credentials via STS/OIDC. There is no static secret to leak.
apiVersion: v1
kind: ServiceAccount
metadata:
name: app-frontend
namespace: prod
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::111122223333:role/app-frontend-prodAWS_ACCESS_KEY_ID=AKIA... # NEVER do this
AWS_SECRET_ACCESS_KEY=wJalr... # leaves the code out of the build spaceReading from the vault at runtime
When the workload cannot assume a federated identity (common in older services or third-party SaaS), the alternative is to fetch the secret from the vault at application startup, mount it in memory and never persist it to disk.
The difference between fetching at runtime and copying at build is the difference between the secret existing in a Docker image (which someone can open) and existing only on the heap of the running process. The second scenario can still leak via log or dump, but it is orders of magnitude harder.
Rotation: why the 5-year-old key is a risk
Rotation is the exercise of replacing a secret before it expires on its own or before someone has compromised it. Modern vaults treat this as a first-class citizen: Secrets Manager has automatic rotation via Lambda, Vault has dynamic secrets that expire in minutes, Parameter Store supports event-driven rotation.
The practical rule: if you cannot rotate the key without downtime, you cannot revoke the key under pressure. And under pressure is when revocation needs to happen.
Where it fits in day-to-day work
- application startup: the vault SDK reads the secrets at boot, exposes them in-memory and fails closed if the vault is down
- CI/CD: pipeline secrets come from the provider's vault, never from the runner's global variables
- database deploy: automatic RDS password rotation via Lambda + Secrets Manager, with no maintenance window
- incident response: central revocation takes down all copies in seconds, and the next startup picks up the new value
Strengths
- centralization: a single panel shows who has which secret and when it was last used
- immediate revocation: remove access in the vault, and all applications lose the secret on the next request
- rotation without downtime: databases, API keys and tokens can be swapped with the application live
Limitations
- workload identity requires fine-grained configuration (OIDC, trust policy, audience) that is easy to get wrong in new clusters
- secrets still leak through logs, dumps or code errors: nothing replaces log scanning with a vault
- cost and latency: reading per request can add hundreds of milliseconds and a few cents per million calls
connections on the map
- KMS & crypto - keys and envelopesencrypts the secretsSecrets - vaults and rotation
updated on 14/10/2026 · sources to go deeper · report an error
in other domains
- Secrets Scanningappsecit is the same problem: secrets out of the code
- CI/CD hardeningsecengOIDC instead of static secrets in the pipeline
Study before
test what you learned
Loading questions…