Safeguard
Security Guides•

Rotate a secret without downtime: the dual credential pattern

How to rotate an API key or database password with no outage: create the new credential, let both work, move consumers, then revoke the old one.

Safeguard Security Team
3 min read

To rotate a secret without downtime, create the new credential while the old one still works, move every consumer to the new one, confirm nothing uses the old one, then revoke it. The overlap window is what prevents an outage. Skipping the check before revocation is where most rotations break.

Why rotations cause outages

A secret is usually copied into more places than anyone remembers: services, CI variables, scripts, laptops. Swapping the value in one place and revoking the old one breaks the rest. OWASP's secrets guidance asks for metadata on each secret, including ownership, purpose and rotation requirements, for this reason.

The pattern in five steps

  1. Inventory consumers. List who reads the secret. Use the owner metadata, access logs and a search of code and CI settings.
  2. Issue a second credential. Many systems allow two active keys or two database users. If yours allows only one, plan a short, announced window instead.
  3. Deploy the new value to consumers gradually, watching error rates.
  4. Watch the old credential. Check its last-used time or logs until traffic stops. OWASP recommends logging secret usage and monitoring who accesses secrets and from where.
  5. Revoke the old credential and record the date.

Make it routine

OWASP says to limit human handling and automate rotation of static secrets, and to set expiration dates. Short-lived dynamic credentials go further: issued per session with short leases and revoked when no longer needed, which removes most rotation work. Restarting an application does not revoke a stolen credential, so tie invalidation to lease expiry or explicit revocation.

When rotation is urgent

After a leak, speed matters more than grace. OWASP says to revoke exposed secrets immediately, rotate through an automated process where possible, and delete them from code and logs. Weigh the side effects before rewriting git history. Accept a short outage if the secret is live in the wild.

Rotation checklist

  • Does each secret have an owner and a purpose recorded?
  • Can the system hold two valid values at once?
  • Is there a way to see last use?
  • Is the new value stored in a manager and not in a ticket or chat?
  • Did you test the rollback?

For cloud-specific walkthroughs see API key rotation automation.

Practise on a low-risk secret first. Pick a key used by one service, run the whole pattern, and note where the inventory was wrong, because it usually is. Those gaps are the real value of the exercise. When an urgent rotation arrives, you will already know the owners, the dashboards to watch and the rollback steps, and the first live attempt will not be under pressure.

Quick check

How often should secrets rotate?

OWASP says to rotate regularly and set expiry, and notes user credentials are generally rotated only when compromise is suspected. Pick intervals by sensitivity.

What if a system supports only one key?

Schedule a short maintenance window, update every consumer in order, and keep the old value ready for rollback until you confirm.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.