What it is
Secrets management is how a system stores, distributes, uses, rotates and revokes credentials: database passwords, API keys, signing keys, TLS private keys, OAuth client secrets. In practice it combines a secrets manager (HashiCorp Vault or its fork OpenBao, AWS Secrets Manager, Azure Key Vault, Google Secret Manager, CyberArk Conjur), workload identity so software can authenticate to it without a password, and practices that keep secrets out of artefacts.
Why it exists
The default is to put credentials where the code is: a config file, an environment file, a Dockerfile ENV, a CI variable echoed into logs. Every copy of the artefact is then a copy of the secret: repository history, forks, developer laptops, image layers in every registry the image was pushed to, crash dumps and logs. Credential leaks are among the most common initial access paths in breach reports, and bots scan public repositories for keys continuously. Static shared credentials also make incidents worse: nobody knows which service used them, rotating them breaks everything at once, so they are rarely rotated.
How it works
Central storage. Secrets live in the manager, encrypted at rest (often envelope encryption with a key held in a KMS or HSM). Applications reference secrets by name; artefacts contain no values.
Identity-based access. Each workload authenticates with an identity the platform issues: a projected Kubernetes service-account token (short-lived JWT with an audience), a cloud workload identity (instance or pod role), a SPIFFE certificate, or an OIDC token from the CI system. The manager verifies it and applies a policy (orders may read database/creds/orders). This solves secret zero: there is no bootstrap password to ship.
Dynamic credentials. For systems the manager can administer (databases, cloud IAM, message brokers), it creates a credential on request with only the needed grants and a lease (for example one hour), and deletes it when the lease ends or is revoked. Each workload instance gets its own credential.
Leases, renewal and revocation. Clients renew leases while they need them, up to a maximum TTL. Revocation removes a credential immediately: on pod shutdown, or for every credential of a compromised service.
Rotation of static secrets. Third-party API keys and similar secrets rotate with an overlap: create the new version, roll it out, confirm use, revoke the old one. Applications reload secrets at runtime.
Delivery. Common patterns: the app calls the manager's API with an SDK; a sidecar or agent (Vault Agent, the Secrets Store CSI driver) writes secrets to an in-memory volume and renews them; or an operator (External Secrets Operator) syncs them into Kubernetes Secrets, which then need encryption at rest and tight RBAC.
When to use it
Always, for production credentials. Even a small system benefits from a cloud provider's secrets manager plus workload identity, which removes static cloud keys entirely. Dynamic database credentials are worth it once several services share a database or audits ask who ran a query.
When not to
Do not use a secrets manager as a general configuration store: non-secret settings belong in config, where they can be reviewed. Avoid calling the manager on every request (see Failure modes). For local development, use separate, low-privilege credentials rather than production secrets.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Dynamic credentials | Unique, expiring, revocable per workload | The manager must administer the target; more moving parts |
| Short leases | Smaller exposure window | More renewals; a vault outage bites sooner |
| SDK calls from the app | Fine control, no extra containers | Vault-specific code in every service |
| Sidecar or CSI agent | Apps read files; renewal handled for them | An extra component per pod |
| Syncing into Kubernetes Secrets | Works with any app unchanged | Secrets now also live in etcd; RBAC and encryption at rest are essential |
Alternatives
- Workload identity with no secret at all: for cloud APIs, a pod role or federated identity replaces API keys entirely. Prefer this where available.
- Encrypted secrets in git (SOPS, Sealed Secrets): GitOps-friendly; still static secrets that must be rotated by hand, and access to decrypt is the new secret.
- Platform environment variables: simple, but visible to anything that can read the process environment, and easily logged.
- Cloud KMS for keys: for signing and encryption keys, keep the key in a KMS or HSM and send data to it, so the key never leaves.
Failure modes
- Secret committed or baked into an image: rotate first; history rewriting is secondary.
- Vault on the request path: every request depends on the manager's latency and availability (step 7).
- Lease longer than you can afford to lose, or shorter than an outage you must survive: pick TTLs deliberately and alert on renewal failures.
- Broad policies: one identity that can read every secret makes the vault a single point of compromise.
- Secrets in logs and error messages: request dumps, debug output and crash reports. Scrub and scan.
- Root or unseal keys handled casually: protect them with auto-unseal via KMS and split access.
- Apps that read secrets only at startup: rotation forces restarts, so teams avoid rotating.
In production
Run the secrets manager highly available across zones, with backups and tested restores. Use workload identity for every service and CI pipeline; ban long-lived cloud access keys. Turn on secret scanning in repositories and CI (pre-commit hooks, push protection). Start with dynamic database credentials for the most sensitive stores. Ship audit logs to your SIEM and alert on unusual reads. Practise rotating every static secret, so a real leak is a routine operation. Track lease renewal failures as a key health signal.
Common misconceptions
- "Private repositories are a safe place for secrets." Access to the repository is broad, clones live on laptops and CI, and repositories leak.
- "Deleting the commit removes the secret." History, forks, caches and image layers keep it. Rotate.
- "Environment variables are secure." They are visible to the process, its children, debug endpoints and often logs; in images they are plain metadata.
- "Kubernetes Secrets are encrypted." By default they are base64-encoded in etcd. Encryption at rest must be enabled, and RBAC still decides who can read them.
- "Using a vault means fetching the secret every time." Fetch once, cache in memory, renew in the background.
Interview angle
Expect to be asked how a service gets its database password. A strong answer: workload identity to authenticate to a secrets manager, a dynamic per-instance credential with a lease, delivered by an agent or SDK, renewed in the background, revoked on shutdown; static secrets rotated with an overlap; nothing in code, images or logs; and a highly available vault, with the lease TTL as the outage budget. Mention secret scanning and what you do when a key leaks.
Model assumptions
Steps 1–6 are a scripted illustration, not a simulation: commits, image builds, identity tokens, credential issuance, leases and rotation are drawn as hand-placed packets with illustrative durations (8 ms per hop). The engine has no notion of secrets or credentials. Steps 7–9 use the simulation: Poisson arrivals at 200 requests per second, an orders pod with 32 workers and 5 ms mean service time (lognormal, cv 0.3), a database with 24 connections and 3 ms reads 1 ms away, and in step 7 a vault with 16 workers and 3 ms per read, 3 ms away. A vault that is down refuses connections and the pod fails the request. That gives about 39 ms per request with the vault on the path and about 30 ms without it. Lease expiry is not modelled: in step 8 the credential is assumed to stay valid for the whole run. Numbers are illustrative, not benchmarks of any product.