Skip to content

Lesson 10 of 12 · 14m

Rotation Is an Overlap Problem

Rotating a live credential without downtime means running two valid credentials through a drain window — pools, JWTs, and mounted files all hold the old one.

Change the DB password, restart the app, watch prod 500 in waves. The pool held eight connections opened under the old password; some reconnect fine, some hold open transactions, a few long-lived ones retry on stale creds and rack up auth failures until the account locks. The credential itself worked fine. Rotation broke you because it isn't a write — it's a migration with in-flight holders: connection pools, JWTs minted under the old signing key, SDK clients that resolved the credential once at boot, mounted secret files that nothing re-reads, DNS-resolved service entries still pointing at last week's instance, and every replica that hasn't reloaded yet.

The pattern that works

Overlap. Mint the new credential while the old still works, move clients across, drain, then revoke. The sequence is publish → wait → revoke, never change → hope.

AWS Secrets Manager implements it literally: the rotation Lambda creates a new version labeled AWSPENDING, tests it, then promotes it to AWSCURRENT — for single-user rotation the password changes in place (a blip, tolerable for many apps); the alternating-users strategy creates app and app_clone and swaps which user is current, giving zero-downtime rotation because both accounts stay valid through the window.

Your own rotation runbook should follow the same contract: the store keeps the old version retrievable by stage label until the new one is proven in production, and consumers fetch by stage name (AWSCURRENT) rather than a pinned version ID — pinning a version ID is how you end up chasing "why did the old secret come back" at 2 a.m.

JWT signing keys show the same shape via JWKS: publish the public keys for both the old and new kid, start signing with the new key, and keep the old key in the set until the last token issued under it expires — the overlap window equals your max token TTL plus clock skew. Pull the old key early and every still-valid session 401s at once.

Kubernetes has its own version of the trap: secrets mounted as volumes refresh via kubelet (under a minute in practice, up to ~2 with cache TTLs), but env:-injected secrets are frozen at process start — rotating them without restarting pods changes nothing and confuses your postmortem.

The wrong mental model

"Rotation = update the secret value." That sentence skips the holders. Every consumer that pinned the credential — an open connection, a parsed config, a signed cookie, an SDK client constructed at boot — keeps working only as long as the old value remains valid. Revoke first and you turned your rotation into an outage. The complementary mistake is never revoking: leaving the old credential valid "just in case" means the rotation accomplished nothing — an attacker holding the old one has exactly the access they had before you celebrated.

Concrete practice

  • Clients must support credential change without restart: reconnect-on-auth-failure, re-read the mounted file, or fetch creds per-session. Apps that can't do this get a rolling restart during the drain window.
  • Always leave the old credential valid for one full drain cycle: longest-lived connection + max token TTL + a margin.
  • Monitor auth failures through the window — a spike of 401s after revoke is normal; before revoke, something didn't reload.
  • Prefer issuing short-lived credentials (Vault's database engine, OIDC-assumed roles) over rotating long-lived ones. A credential that dies in an hour never needs a rotation runbook at all.

Rotation is plumbing: two pipes, a drain, then the valve. Skip the drain and the valve hits the floor — and you get to explain a self-inflicted outage in the same postmortem as the credential change that caused it.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.