Runtime secrets
Runtime secrets are the credentials a running service needs, such as database passwords, API keys and certificates. This practice decides how each one reaches the process, from a secrets manager or the platform's workload identity, so that no copy lives in the image, the repository or a long-lived environment file.
A secret built into an image can be read by anyone who can pull the image, and a static key shared by every replica stays valid until someone rotates it. With workload identity the platform gives each service a short-lived token tied to its own identity, so there is no stored key to leak. OWASP's Top 10:2025 recommends federation and short-lived credentials over static keys in code, configuration or pipelines.
- Who
- Platform engineers who run the secrets manager and identity setup, with developers who decide how the application reads and reloads secrets
- When
- When a service first needs a credential, and before each release that adds one or changes how one is delivered
- How often
- Rotation runs automatically, by schedule or lease; access rules reviewed when workloads, teams or namespaces change
- You end up with
- An inventory of each workload's secrets and identities, least-privilege access rules, and a rotation that has been tested
Do this
Inventory each secret and its consumers
For every credential, record its owner, the issuer, which workloads use it, where each copy lives and how it rotates. Copies in CI variables, Helm values and
.envfiles count. The list shows which secrets you can replace with workload identity and which must move into a secrets manager; Secrets out of code keeps them out of the repository.Prefer workload identity to stored keys
When the workload calls a cloud API, let the platform issue it short-lived credentials instead of storing a key: EKS Pod Identity or IAM roles for service accounts, Workload Identity Federation for GKE, or Microsoft Entra Workload ID on AKS. Each maps a Kubernetes service account to a cloud identity, so give that identity only the resources the workload uses, and give each workload its own service account.
Keep the rest in a secrets manager
Store remaining secrets in a manager such as HashiCorp Vault or OpenBao, AWS Secrets Manager, Google Secret Manager or Azure Key Vault, as ASVS 5.0 requirement V13.3.1 asks, and authenticate to it with the workload's own identity, not a static token. Prefer dynamic credentials where possible: Vault's database secrets engine creates a database user per request, with a lease that expires.
Deliver secrets as mounted files
Never put a secret in an image,
ARGorENVline. Mount secrets read-only on an in-memory volume, through the Secrets Store CSI Driver, a Vault Agent sidecar or a Kubernetes Secret volume, rather than environment variables, which other processes can read and logs or crash dumps can capture. If secrets land in Kubernetes Secrets, encrypt etcd at rest, preferably with a KMS v2 provider.Let each workload read only its own secrets
In Kubernetes, grant
geton named Secrets withresourceNames, neverlistorwatch, which return the contents of every Secret in scope. Anyone who can create a pod in a namespace can mount any Secret there, so keep deploy rights as narrow as Secret rights and separate namespaces by trust. Scope secrets manager policies the same way: one path per workload.Make rotation reach the running process
Pick one mechanism per workload and test it: the application re-reads the mounted file when it changes or after an authentication failure, or a controller restarts the deployment. Environment variables and
subPathmounts never change in a running container. Rotate by issuing the new credential, moving every consumer, then revoking the old one at the issuer and proving it fails.Audit access and rehearse revocation
Turn on the secrets manager's audit log and alert on unusual reads, such as one identity reading many secrets in a short time, which the Kubernetes good-practice guide also suggests. In a test environment, revoke a credential on purpose and confirm the service recovers with a new one, so you know the steps before a leak forces them.
Done when
Each workload can read only its own secrets, and they rotate without a code change.
Mark it in the gap checkCommon mistakes
- Giving the workload a static key to log in to the secrets manager. That only moves the secret one step; authenticate with the platform's workload identity instead.
- Granting
liston Secrets to a monitoring agent or developer role. Kubernetes returns the contents of every Secret in scope, not just their names. - Rotating a value the application reads from an environment variable. The process keeps the old value until it restarts, so either it breaks or the old credential has to stay valid.
- Treating a Kubernetes Secret as encrypted. Base64 is an encoding, and by default the API server stores Secrets unencrypted in etcd, so anyone with etcd or its backups can read them.
- Leaving the node's credentials reachable from pods. On EKS, unless access to the instance metadata service is restricted, a container can also reach the node's IAM role.
How a secret can reach the process
Choose by where each copy of the value lives and how a rotation reaches the running process. Mounting from the store keeps values out of etcd; syncing into Kubernetes Secrets brings the etcd encryption and RBAC duties with it.
| Pattern | Where the value lives | How a rotation reaches the app |
|---|---|---|
| Workload identity (EKS Pod Identity, GKE, Entra Workload ID) | No stored secret: the platform issues a short-lived token | The token is refreshed automatically; SDKs pick up the new one |
| Kubernetes Secret as an environment variable | etcd, then the process environment | Only when the pod restarts |
| Kubernetes Secret as a volume | etcd, then an in-memory file | The kubelet updates the file after its sync delay; never with subPath |
| Secrets Store CSI Driver | The external store, then an in-memory file | Re-fetched only when its alpha rotation feature is on |
| External Secrets Operator | The external store, copied into a Kubernetes Secret | At the refresh interval, then a file update or a restart |
| Vault Agent sidecar | Vault, rendered into an in-memory volume | The Agent renews leases and rewrites the file |
| Application calls the manager's API | The secrets manager, then process memory | The application fetches again, or caches with a time limit |
Tools and guides
- Secrets at runtime: Vault, Kubernetes Secrets, CSI driver, External Secrets and SOPS
How a running workload should get its credentials: encrypt Kubernetes Secrets with a KMS v2 provider and lock down RBAC, mount from an external store with the Secrets Store CSI Driver, sync with External Secrets Operator, issue dynamic credentials with Vault and its Agent Injector, keep Git copies encrypted with SOPS, and make rotation reach the process.
- Workload identity federation: short-lived, scoped identities for services and CI
Trace how a running workload obtains a short-lived identity, write cloud trust policies that match immutable claims instead of names or wildcards, and keep the resulting credential limited by audience and authorization.
- Secrets management: storage, rotation and leaked-secret response
Follow one application credential from issuance through caching, rotation, revocation and restored backups, prove that its old value stops working, and respond correctly when a secret leaks.
Standards
- OWASP SAMM 2
- Secure Deployment
Sources
- OWASP Secrets Management Cheat Sheet
- Kubernetes: good practices for Kubernetes Secrets. Kubernetes v1.37.
- Kubernetes: Secrets (volume updates and subPath). Kubernetes v1.37.
- Kubernetes: using a KMS provider for data encryption (KMS v2). Kubernetes v1.37.
- Amazon EKS: Pod Identity
- Google Cloud: Workload Identity Federation for GKE
- Microsoft Learn: Microsoft Entra Workload ID on AKS
- Vault: PostgreSQL database secrets engine
- Secrets Store CSI Driver: auto rotation of mounted contents
- OWASP ASVS 5.0.0: V13 Configuration (V13.3 Secret Management). Version 5.0.0.
- OWASP Top 10:2025 A02 Security Misconfiguration. OWASP Top 10:2025.
- OWASP SAMM: Secure Deployment (Secret Management stream)