LumenForgee

Rotating secrets without downtime

Rotating a secret is simple in theory: create a new one, update every consumer, revoke the old one. In practice the middle step is where outages happen, because nobody knows every consumer, and some of them only read their configuration when they start. Reliable rotation is designed around that middle step.

Contents
  1. Why rotation causes outages
  2. Start with an inventory
  3. The overlap-window pattern
  4. Retrieving secrets at runtime
  5. Dynamic secrets remove most rotation work
  6. Auditing secret access
  7. Worked example: rotating a leaked database password
  8. Common pitfalls
  9. FAQ
  10. Checklist
  11. Primary sources

Key facts

  • Rotation is safe when old and new credentials are both valid during an overlap window longer than the slowest consumer's refresh interval.
  • Dynamic secrets are generated on demand with a short lease and revoked automatically, which removes most manual rotation.
  • OWASP's Secrets Management Cheat Sheet recommends automated rotation, central management and auditing of secret access.
  • NIST SP 800-57 describes key lifecycle stages, including cryptoperiods that limit how long a key is used.

Why rotation causes outages

A static database password is created when a service is first deployed. Over time it is copied into a second service, a reporting job, a migration script and a developer's local configuration. When it must be rotated — on schedule, after an employee leaves, or because it appeared in a CI log — the team changes it in the database and updates the configuration they know about. Everything they did not know about fails.

Even known consumers can fail. A service that reads its configuration only at start-up keeps using the old password until it restarts. If the password is changed in the database first, that service's connection pool fails as soon as it opens a new connection. If the service is restarted first, it fails because the new password does not exist yet. There is no safe ordering when only one credential can be valid at a time.

The fix is structural: allow two valid credentials at once, and make consumers able to pick up a new one without a restart.

Start with an inventory

Rotation automation is only as good as the list of secrets it knows about. Build an inventory with, for every secret: what it protects, who owns it, which workloads consume it, how they retrieve it, and how often it should rotate.

Secret scanning closes the loop from the other side. Scanners in pre-commit hooks and CI detect credentials committed to repositories or printed in logs; findings either become rotation tasks or prove that the inventory is incomplete. Treat every detected secret as compromised, even if the repository is private.

The overlap-window pattern

  1. Issue a new version of the credential while the current one remains valid.
  2. Overlap: both versions are accepted. For databases, this means two users or a user with two valid passwords where supported; for API keys, two active keys; for signing keys, publishing both public keys.
  3. Move consumers: they fetch the current version from the secret store at runtime, or their cached copy expires.
  4. Verify: authentication metrics show that the old version is no longer used.
  5. Revoke the old version and record the rotation in the audit log.

The overlap window must be longer than the slowest consumer's refresh interval. If a consumer caches secrets for one hour, the window must be well over an hour. Measuring actual use of each version — through database connection logs, API gateway metrics or key identifiers in signed tokens — turns the decision to revoke from hope into evidence.

Signing keys follow the same pattern with one twist: verifiers must trust the new public key before signers start using the new private key, and must keep trusting the old public key until every token signed with it has expired. Publishing keys in a JWKS document with key identifiers makes this explicit.

Retrieving secrets at runtime

Consumers should not hold secrets in images or long-lived files. Common patterns are fetching from a secret manager through an SDK with a short cache, mounting secrets through an operator that syncs them into the platform and lets the application reload, or using a sidecar that renews leases and writes files the application watches.

Whatever the mechanism, applications must handle a change of credential without a restart: connection pools that re-authenticate new connections with the current secret, HTTP clients that read the API key per request from a refreshed source. This is ordinary engineering work, but it is the part most often missing.

Dynamic secrets remove most rotation work

The best rotation is the one nobody has to schedule. With dynamic secrets, a secret manager creates a unique database user or cloud credential for each consumer on request, with a lease of minutes or hours, and revokes it when the lease expires. A leaked credential is valid only briefly and identifies exactly which workload it belonged to.

Dynamic credentials need consumers that renew leases and handle credential changes — the same capability the overlap pattern needs. Once that capability exists, moving from scheduled rotation to dynamic secrets is mostly configuration.

Auditing secret access

Rotation limits how long a leaked secret is useful; auditing tells you whether it was used. Central secret managers can log every read with the identity of the caller, which turns a vague question — who could have used this password? — into a list. Pair that with database and API logs showing which credential version authenticated each connection.

Review audit data with a purpose. Unexpected readers, secrets read far more often than their consumers' restart patterns explain, or reads from unfamiliar networks are all worth investigating. Alerting on a few such patterns is more useful than storing everything and never looking at it.

Worked example: rotating a leaked database password

A PostgreSQL password used by three services appears in a CI job log. The team decides to rotate immediately.

  1. The inventory lists the three services; secret scanning of all repositories finds a fourth consumer, a nightly export job.
  2. A second database role with identical privileges and a new password is created; both roles are now valid.
  3. The new password is written to the secret store. Three services reload it within their five-minute cache; the export job is updated and redeployed.
  4. Connection logs are watched until the old role has no new connections for longer than the longest cache interval.
  5. The old role is locked, then dropped; the CI log is purged and the job's log masking is fixed.

As a follow-up, the services move to dynamic credentials with one-hour leases, so the next leak would expire on its own.

Common pitfalls

  • Changing the password in place, with only one valid credential at any time.
  • Revoking the old credential on a timer instead of on evidence that it is unused.
  • Applications that read secrets only at start-up.
  • Secrets baked into images or committed to configuration repositories.
  • Rotating signing keys without publishing the new public key first.
  • Rotation that is only ever exercised during an incident.

FAQ

How often should secrets rotate?

It depends on the secret's exposure and value. Dynamic credentials rotate continuously; static secrets should rotate on a defined schedule and immediately after any suspected exposure.

Is encryption of secrets at rest enough?

No. Encryption protects storage; rotation limits the damage when a secret is exposed in use, in logs or on a developer machine.

What about secrets for third-party APIs that allow only one key?

Ask the provider for multiple keys or key versions. If that is impossible, schedule rotation in a low-traffic window and make consumers reload quickly.

Checklist

  • Inventory with owner, consumers and rotation interval for every secret.
  • Secret scanning in pre-commit and CI; findings treated as compromises.
  • Consumers retrieve secrets at runtime and reload without restart.
  • Overlap window longer than the slowest refresh interval.
  • Revocation based on measured non-use of the old version.
  • Dynamic, short-lived credentials wherever the target supports them.

Primary sources

  1. OWASP — Secrets Management Cheat Sheet
  2. NIST SP 800-57 Part 1 Rev. 5 — Recommendation for Key Management
  3. HashiCorp Vault documentation — Database secrets engine
  4. RFC 7517 — JSON Web Key (JWK)
  5. PostgreSQL documentation — Database Roles

Related research