Every application holds secrets: the database password, the payment gateway API key, the signing key for tokens, the cloud credentials used by CI. Leaked credentials are one of the most common ways attackers get in, and the leak is often mundane: a .env file committed to Git, a key pasted into a ticket, a Docker image with credentials baked in. Secrets management puts all of these in one controlled system and gives each workload only the secrets it needs.
What a secrets manager does
- Stores secrets encrypted, usually with keys held in a KMS or HSM.
- Controls access per identity: the payments service can read the gateway key, the reporting service can't.
- Delivers secrets at runtime through an API, environment injection or a mounted file, so they never enter the repository.
- Rotates secrets on a schedule or on demand, and updates the systems that use them.
- Audits every read and change.
- Issues dynamic secrets in some tools: short-lived database credentials created on request and revoked automatically. Common tools are AWS Secrets Manager, Google Secret Manager, Azure Key Vault, HashiCorp Vault and OpenBao. AWS Systems Manager Parameter Store is a lighter option for less sensitive configuration.
Example: rotating a database password on AWS
A FinTech API on ECS connects to PostgreSQL on RDS.
- The password lives in AWS Secrets Manager as
prod/payments-api/db, never in the task definition or code. - The ECS task role has
secretsmanager:GetSecretValueon that one secret ARN, following least privilege. - ECS injects the value into the container at start-up. The app also re-reads it on authentication failure.
- Rotation runs every 30 days. Secrets Manager creates a new password, sets it on the database, tests it and marks it current. The previous version is kept briefly so running tasks don't fail mid-rotation.
- CloudTrail logs every read. An alert fires if anything other than the task role reads the secret. A developer who leaves the company never held the production password, so there's nothing to change when they go.
Secrets management in Kubernetes
A Kubernetes Secret is only base64-encoded, which is an encoding, not encryption. By default it's stored unencrypted in etcd and readable by anyone with permission to read Secrets in the namespace. To harden it:
- turn on encryption at rest for Secrets, ideally with a KMS provider
- limit RBAC so only the workloads that need a Secret can read it
- or sync secrets from an external manager with the External Secrets Operator or the Secrets Store CSI Driver
Best practices
- Prefer no secret at all. Workload identity (IAM roles, GKE Workload Identity, GitHub Actions OIDC to the cloud) replaces long-lived keys with short-lived tokens.
- Scan for leaks in repositories, CI logs and container images, and block commits that add secrets.
- Rotate after any exposure, at once. Deleting the commit isn't enough, because Git history and forks keep it.
- Separate environments, so a staging key can never reach production data.
- Keep secrets out of mobile and browser code. Anything shipped to a device can be extracted.
- Treat infrastructure as code state as sensitive, because Terraform state can contain secret values in plain text. For card data environments, PCI DSS v4.0.1 requirements 8.6.1 to 8.6.3 forbid hard-coding system and application account passwords and require them to be protected and changed periodically. Secrets handling is part of how we set up cloud and infrastructure platforms. See PCI DSS 4 requirements developers miss.