Why it matters
Applications need credentials to reach databases, providers and internal services, and the easy path is to put them in a config file next to the code. That works until the repository is shared, the image is pushed to a registry, or an engineer needs to rotate a key and finds it referenced in a dozen places. Separating secrets from configuration gives each a lifecycle: configuration changes with a deploy, secrets change on a schedule and on suspicion.
Mental model
It is the difference between a posted address and a house key: the address can be public, the key is handed to one person and replaced when lost. The analogy breaks because a software key can be copied without the holder knowing, which is why audit logs and short validity matter.
How it works
- 1Classify every setting: public configuration, environment-specific configuration, or secret, and record the classification.
- 2Store secrets in a manager that supports access policy, audit and versioning, and inject them at runtime.
- 3Grant each workload its own identity and the minimum set of secrets it needs, rather than a shared platform credential.
- 4Rotate on a schedule and after any suspected exposure, with an overlap so both values work during the change.
- 5Keep secrets out of images, logs and crash reports, and redact them in error handlers.
- 6Test that a missing or rotated secret produces a clear startup failure rather than a silent fallback.
Step 1 of 6
Classify every setting: public configuration, environment-specific configuration, or secret, and record the classification.
Figure. The mechanism in this page's own steps. The figure adds sequence, not new claims.
What to notice. A step can be read alone, but the order is the mechanism. The control lets you stop on any one.
Text version
The page's steps: 1. Classify every setting: public configuration, environment-specific configuration, or secr… 2. Store secrets in a manager that supports access policy, audit and versioning, and inject … 3. Grant each workload its own identity and the minimum set of secrets it needs, rather than… 4. Rotate on a schedule and after any suspected exposure, with an overlap so both values wor… 5. Keep secrets out of images, logs and crash reports, and redact them in error handlers. 6. Test that a missing or rotated secret produces a clear startup failure rather than a sile…
- Classify every setting: public configuration, environment-specific configuration, or secret, and record the classification.
- Store secrets in a manager that supports access policy, audit and versioning, and inject them at runtime.
- Grant each workload its own identity and the minimum set of secrets it needs, rather than a shared platform credential.
- Rotate on a schedule and after any suspected exposure, with an overlap so both values work during the change.
- Keep secrets out of images, logs and crash reports, and redact them in error handlers.
- Test that a missing or rotated secret produces a clear startup failure rather than a silent fallback.
Trade-offs
| Choice | Good for | Cost | Fails when |
|---|---|---|---|
| Environment variables | Simple and widely supported | Visible in process listings and crash dumps | The platform does not isolate processes |
| Secret manager with runtime fetch | Audit, rotation and least privilege | A dependency at startup and per refresh | The manager is unavailable during boot |
| Sidecar or agent | No application code change | Extra component and cache behaviour | The secret must be used by a non-HTTP client |
| Encrypted config in the repository | Versioned with the code | Key management becomes the problem | The decryption key is shared widely |
Good for
Simple and widely supported
Cost
Visible in process listings and crash dumps
Fails when
The platform does not isolate processes
- The platform does not isolate processes
- The manager is unavailable during boot
- The secret must be used by a non-HTTP client
- The decryption key is shared widely
Figure. Each choice with what it buys, what it costs, and the case where it loses.
What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.
Text version
Four trade-offs: Environment variables is good for Simple and widely supported, costs Visible in process listings and crash dumps, and fails when The platform does not isolate processes. Secret manager with runtime fetch is good for Audit, rotation and least privilege, costs A dependency at startup and per refresh, and fails when The manager is unavailable during boot. Sidecar or agent is good for No application code change, costs Extra component and cache behaviour, and fails when The secret must be used by a non-HTTP client. Encrypted config in the repository is good for Versioned with the code, costs Key management becomes the problem, and fails when The decryption key is shared widely
Failure modes
- Secret in a build log. A debug echo prints the value and the log is retained. Debug: scan continuous-integration logs for known secret patterns and fail the pipeline on a match.
- Shared platform credential. Every service uses one key, so revoking it breaks everything and attribution is impossible. Debug: list secret access by workload identity and look for a value used by more than one.
- Rotation without overlap. The old secret is disabled before consumers reload and requests fail. Debug: rehearse rotation with both versions valid and measure the reload window.
In production
Alert on secret age and on access from an unexpected identity, and keep an inventory with an owner per secret. Rehearse rotation for the credentials that would cause the largest outage.
Common misconceptions
People think: Environment variables are a secure place for secrets.
Actually: They are better than source code and still leak through process inspection, crash dumps and child processes.
People think: Deleting a secret from the repository removes the exposure.
Actually: History, forks and clones retain it; the only remedy is rotation.
Interview angle
Separate configuration from secrets, then cover storage, workload identity, rotation with overlap and audit. Name the leak paths. A credential in an environment variable described as secure is the weak answer.
Sources
- The Twelve-Factor App, Config — configuration separated from code.
- HashiCorp Vault documentation — secret storage, dynamic credentials and audit.