Imagine a routine Friday task: rotate the production database password. Someone changes it in the database, updates the value in Key Vault, and moves on. Ten minutes later the API starts returning errors. One instance still has the old password cached. A nightly job reads its own copy from a CI variable. A support script on someone's laptop has a .env file nobody remembered.
Nothing was leaked and nothing was attacked. The rotation itself caused the outage, because the old password stopped working before everything that used it had the new one.
Microsoft's own single-credential rotation tutorial describes this gap honestly. After the password changes in the database and before Key Vault and the app catch up, there's a window in which the stored secret can't authenticate.
The fix is an overlap window:
- Create the new credential while the old one still works.
- Move every consumer to the new credential.
- Verify that nothing is still using the old one.
- Only then revoke the old credential.
- Where you can, skip all of this by removing the secret entirely with managed identity or federated credentials.
Why a one-step rotation causes an outage
A one-step rotation replaces the only valid credential in place. From that moment, every consumer that hasn't picked up the new value fails, and consumers pick up new values at very different speeds:
- An app reading a Key Vault reference may refresh on a schedule, not instantly.
- A container may only read the secret at startup.
- A CI system may hold its own copy of the value.
- A connection pool may keep using connections that were opened before the change.
Even if everything updates within a few minutes, those minutes are an outage. A rotation that's safe has to tolerate the slowest consumer.
The pattern: two valid credentials, then revoke
The AWS Secrets Manager documentation on rotation strategies gives a clear, vendor-neutral model. It describes a "single user" strategy, where one user's password is changed, and an "alternating users" strategy, where two users take turns being current. Its rotation function is split into four steps: create the new secret, set it on the target system, test it, and finish by promoting it to current.
The same model works whatever tools you use:
- Create: generate the new credential and store it as a new version, without making it current yet.
- Set: make the target system accept it, alongside the old one.
- Test: connect with the new credential before any consumer depends on it.
- Finish: make it current, roll consumers over, and revoke the old credential later, once nothing uses it.
AWS keeps the previous value under a label (AWSPREVIOUS) as the last known good version. That's worth copying even if you're not on AWS: keep the old value available, but not active, until you're sure you won't need to roll back.
Find every consumer first
Most rotation outages come from a consumer nobody listed. Before you rotate, write down every place the secret is used and how that place gets a new value:
- App configuration: environment variables, Key Vault references, and settings in your hosting platform.
- CI and CD: GitHub Actions secrets are copies that you update separately. Azure DevOps variable groups linked to Key Vault read values when a pipeline runs.
- Scheduled jobs and scripts: cron jobs, maintenance scripts, and admin tools often carry their own copy.
- Local files:
.envfiles on developer machines and shared support laptops. - Derived credentials: tokens or signatures created from the secret, such as storage SAS tokens.
- Open connections: pooled database connections that authenticated before the change.
Refresh speed differs by platform, so check yours:
- On Azure App Service, Key Vault references to a secret without a version are re-fetched within 24 hours, and you can force a refresh.
- On Azure Container Apps, the secrets documentation says a Key Vault reference without a version picks up the latest version within 30 minutes, and active revisions that use the secret in an environment variable are restarted to load it. Secrets stored directly in the app are different: changing one doesn't affect running revisions until you restart them or deploy a new revision.
These figures were current as of November 2026, so confirm them against the live docs. Either way, the overlap window has to be longer than the slowest refresh on your list.
A reference pinned to a specific secret version never sees a rotation. If an app setting points at an exact version, it keeps reading the old value no matter how many new versions you create. That's useful for a deliberate rollback, but a silent problem if nobody knows it's pinned.
Database passwords: two roles, not two passwords
A PostgreSQL role has one password at a time. The CREATE ROLE documentation has no way to keep the old password valid alongside the new one on the same role. So the overlap has to come from two roles.
A common layout:
- A group role without login owns the privileges: table grants, schema usage, and so on.
- Two login roles, for example
app_aandapp_b, are members of that group and inherit its privileges through role membership. - The app uses one login role at a time. To rotate, set a new password on the idle role, test it, switch the app's secret to that role, and later disable or re-password the other one.
Because both login roles inherit the same privileges, the switch doesn't change what the app can do. It's the database version of AWS's "alternating users" strategy.
Two PostgreSQL details are worth knowing:
- The password expiry setting covers the password only. The documentation describes
VALID UNTILas an expiration time for a password, and it isn't enforced for logins that don't use password authentication. It can help as a safety net, but it isn't a full lifecycle control. - Existing connections are a separate question. The PostgreSQL documentation doesn't say what happens to sessions that are already open when a password changes, so test that in your own environment rather than assuming. Pools matter here too. In node-postgres, the pool option
maxLifetimeSecondsis off by default, so connections can live for a long time. Setting a maximum lifetime makes old connections retire on a predictable schedule.
Keys that come in pairs: storage accounts
Some services build the overlap in for you. An Azure Storage account has two access keys, and Microsoft's access key guidance describes the order:
- Update every app to use the secondary key.
- Regenerate the primary key.
- Move apps back to the new primary key.
- Regenerate the secondary key.
The pair only helps if everyone moves together. If one app uses key1 while another uses key2, regenerating either key breaks someone. Regenerating a key also invalidates account SAS tokens that were signed with it, so those tokens belong on your consumer list too.
Third-party API keys: roll, don't replace
Many providers support overlapping keys. Stripe's API key documentation describes rolling a key: you get a new key, and the old one can keep working for up to seven days. Stripe also advises expiring the old key only after its request volume has been at zero for a while.
That advice generalizes well:
- Prefer "roll" or "create second key" over "regenerate" whenever a provider offers it.
- Use the provider's logs or dashboard to confirm the old key has stopped receiving traffic.
- Don't forget related secrets, such as webhook signing secrets, which are often managed separately from API keys.
JWT signing keys: rollover with kid
If your API issues its own JWTs, the signing key needs rotation too, and here the overlap is built into the standards. RFC 7517 describes the kid (key ID) parameter as a way to choose among keys in a JWK Set during key rollover. OpenID Connect Core expects verifiers to fetch keys again when they see an unfamiliar kid, and issuers to keep recently retired keys for a reasonable period. Microsoft's signing key rollover guidance tells apps to expect more than one valid key at any time.
A safe rollover sequence:
- Publish the new public key first. Add it to your key set, with its own
kid, before you sign anything with it, so verifiers can find it. - Start signing with the new key. Put the new
kidin every token header. - Keep the old key for verification until every token it signed has expired. With a 15-minute access token, that's a short wait; refresh tokens and long-lived sessions need more care.
- Remove the old key from the key set.
In a NestJS API that validates tokens with Passport, passport-jwt's secretOrKeyProvider option lets you choose the key at verification time instead of passing a single fixed secret. A common pairing is the jwks-rsa library, which looks up the key by kid and caches it, for ten minutes by default as of November 2026. Check the current docs for both libraries, because option names and defaults change between versions.
If you sign with a single shared secret (HS256), the same idea still applies: keep a small list of secrets keyed by kid, verify against the matching one, and retire old entries only after their tokens have expired.
When is it safe to revoke?
"After a while" isn't a revoke signal. Pick something you can measure:
- Database: no sessions or logins for the old role, checked in the database's activity views or login logs.
- API keys: zero requests with the old key in the provider's logs.
- JWT keys: the longest token lifetime has passed since you stopped signing with the old key.
- Everything: no authentication errors in your own logs since consumers switched.
Then set a time box. The overlap should end on a known date, because a "temporary" second credential that never gets revoked is just one more long-lived secret.
Plan the rollback before you start. If something breaks after the switch, the fastest recovery is to point consumers back at the old credential. That only works if you haven't revoked it yet, which is another reason to revoke last.
Planned rotation versus a leaked secret
Everything above assumes a planned rotation. A leaked secret changes the trade-off. The overlap window keeps the leaked credential valid, so that window is exposure.
After a leak, revoke quickly and accept that some consumers may briefly fail. The OWASP Secrets Management Cheat Sheet makes a related point: restarting an application doesn't revoke stolen credentials. Revocation has to happen at the system that accepts the credential.
The consumer list you built for planned rotation is what makes an emergency rotation fast. If you already know every place the secret lives, you can update them all quickly instead of discovering them through errors.
Automating it in Azure
Azure Key Vault has built-in rotation policies for keys, with a minimum rotation interval of seven days as of November 2026. Secrets are different. They don't rotate themselves, because Key Vault can't change a password inside your database or a third-party service.
For secrets, Microsoft's pattern uses events:
- Key Vault publishes a
SecretNearExpiryevent through Event Grid, 30 days before a secret's expiry date. - An Azure Function subscribed to that event creates the new credential on the target system and stores it as a new secret version.
- For services with two credentials, the dual-credential tutorial alternates between them, which gives consumers a full rotation cycle to pick up the new value.
Automation only helps if the consumer side is ready. Apps should use version-less references, and the overlap should be longer than their refresh time.
The best rotation is no secret at all
The safest secret to rotate is one that doesn't exist. Microsoft's rotation tutorials recommend managed identities or Microsoft Entra authentication where possible, before you reach for rotation:
- Azure SQL supports Microsoft Entra authentication, and managed identities remove the need to store a password.
- Azure Database for PostgreSQL supports Microsoft Entra authentication, where a short-lived token takes the place of the password. As of November 2026, the documentation lists token lifetimes of up to one hour for users and up to 24 hours for system-assigned managed identities. Your app requests fresh tokens instead of storing a password, so there's no long-lived database password to rotate, but it does need to fetch a new token before the old one expires.
- CI and CD can use workload identity federation. GitHub Actions and Azure Pipelines service connections can authenticate to Azure with short-lived federated tokens instead of a stored client secret.
Not everything can go passwordless. Third-party API keys and some legacy systems still need rotation. But every secret you remove is one less entry on the consumer list.
How often to rotate, and why to rehearse
Rotation frequency is often driven by habit rather than risk. For people, NIST SP 800-63B says verifiers shouldn't require users to change passwords periodically. That guidance is about memorized user passwords, not machine credentials. For machine secrets, OWASP recommends automated rotation and, where possible, dynamic short-lived credentials.
A practical approach for a small team:
- Rotate on a schedule you can actually sustain, and automate it where the platform allows.
- Rotate immediately when someone with access leaves, or when a secret may have been exposed.
- Rehearse in staging. Give a staging secret a short expiry and let the rotation run end to end, so you find the forgotten consumer there instead of in production.
A rotation you've never practiced is the one most likely to cause the outage you're trying to avoid.
Checklist
- List every consumer before you rotate: apps, CI copies, variable groups, jobs, scripts, local files, derived tokens, and open connections.
- Know each consumer's refresh time, and make the overlap longer than the slowest one.
- Create the new credential while the old one still works.
- For PostgreSQL, alternate between two login roles under one group role instead of changing one role's password in place.
- For paired keys, move everyone together: secondary, regenerate primary, back to primary, regenerate secondary.
- For API keys, roll rather than regenerate when the provider supports it.
- For JWTs, publish the new key first, sign with its key ID, and keep the old key until its tokens expire.
- Use version-less references unless you're pinning on purpose.
- Revoke on evidence: zero sessions, zero requests, or an expired token window, within a fixed time box.
- Keep the previous value for rollback until revocation.
- After a leak, revoke fast and accept brief disruption.
- Remove secrets where you can with managed identity, Entra authentication, and workload identity federation.
- Rehearse in staging with a short expiry.



