Rotating Credentials After a Leak: The Checklist You Hope You Never Need
What to actually do in the first hour, and why order matters more than speed

Contents
The first time I had to rotate a leaked credential for real — a Cloudflare API token, sitting live in a public repo for about forty minutes before a scanning bot found it — I did the rotation itself in under two minutes, and then spent the next hour second-guessing whether I’d actually covered everything the token could have touched. That gap between “the immediate fix is done” and “I actually know the exposure is closed” is where the real risk sits, and it’s exactly the gap a written checklist closes, because a stressed brain at midnight reliably forgets steps a calm read-through wouldn’t. This is the checklist I now keep somewhere I can find it without thinking, and the order is deliberate — each step exists because skipping it, or doing it out of sequence, has a specific, real failure mode.
Step one: scope it before you touch anything
Before rotating anything, spend the first few minutes establishing exactly what leaked and what it could reach — those few minutes matter because rotating the wrong credential, or only one of several related ones, gives a false sense of closure while leaving a door open. What kind of credential is it — an API token, a database password, an SSH key, a GPG key? What permissions does it actually carry — read-only, or does it have write and delete scope? Where was it exposed, and for how long — a public GitHub repo for forty minutes has a very different exposure profile than a Slack message to a channel of three trusted people, because the first is realistically indexed by scanning bots within minutes and the second may never leave that room. Answering these before acting means the rotation that follows actually matches the real scope of the problem, rather than being a guess made under time pressure.
Step two: revoke before you rotate
This ordering trips people up, because it feels backwards: revoke the old credential first, as a separate action from issuing the new one, even though it means a short window where nothing valid exists until the replacement is in place. The alternative — generating a new credential and only revoking the old one afterward, “to be safe” — leaves the compromised credential valid for longer than necessary, and if whoever has it is actively using it, that extra window is exactly the time they get to keep using it after you already know it’s compromised. For most services, the API or dashboard supports issuing the replacement and revoking the old one in nearly the same breath:
| |
For a database password, this looks like changing the password immediately and only then updating the services that connect with it — accepting a brief outage while every consumer picks up the new value — rather than leaving the old, known-compromised password valid while you carefully coordinate a zero-downtime rollout. A few minutes of service disruption is a much smaller cost than an extended window where a credential you know is compromised is still accepted.
Step three: rotate everywhere it’s used, not just the source
The credential itself is only half the job — every place that consumes it needs the new value before the old one’s revocation actually takes effect for them too, and finding every consumer is the step people most often under-scope. Grep your infrastructure-as-code, CI variables, .env files across every environment (not just production — staging and dev copies of the same key are exactly the kind of thing that gets forgotten), and any secrets manager entries:
| |

For anything managed through sops and age or Kubernetes secrets, the update needs to happen at the source of truth those systems read from — re-encrypting the sops file, updating the sealed secret — not just in whatever’s currently running, because a running deployment that isn’t redeployed will keep the old value cached in memory or mounted volumes until it restarts, giving you a false sense that rotation is complete when it’s only complete for the next deploy.
Step four: check whether it was actually used
Rotation closes the exposure going forward; it says nothing about what happened during the window the credential was live and valid. Every major provider keeps some form of audit log — API request logs, access logs, authentication history — and checking it for the exposure window is the step that tells you whether this was a near-miss or an actual incident:
| |
That single log line is the difference between “the token leaked and nothing happened” and “the token leaked and someone added a DNS record” — a genuinely different severity, requiring genuinely different follow-up, including checking whatever that DNS record was pointing at and whether it’s been used for anything since. Skipping this check because the rotation itself felt like “handling it” is how a real compromise gets treated as a false alarm.
Step five: check for lateral reach
Some credentials are doors to other doors — an SSH key that grants access to a box which itself holds other credentials, a database password for an account with broader grants than the one thing you thought it was scoped to, a GPG key used to sign commits that also gets treated as an identity proof elsewhere. Before closing out the incident, confirm the leaked credential’s actual permission scope matched what you assumed, rather than what you intended when you created it — permission scope creep, where a token was widened for a one-off task and never narrowed back, is common enough that it’s worth explicitly re-checking rather than trusting memory:
| |
“All zones” rather than the single zone I thought I’d scoped it to, in the incident that prompted me to start writing this checklist down in the first place — the token had been widened months earlier for a one-off migration task and never scoped back afterward. That’s the exact kind of drift step five exists to catch.
SSH and GPG keys are a different rotation shape
The steps above assume a credential you can regenerate at the source and revoke centrally — an API token, a database password. SSH and GPG keys rotate differently, because the trust relationship is distributed across every place the public key was ever added, rather than validated centrally by the service that issued it.
For a compromised SSH private key, generating a new key pair is the easy part; the harder part is removing the old public key from every authorized_keys file it was ever added to, across every server, which for a homelab with a handful of boxes is a short manual pass but for anything larger needs to be tracked somewhere rather than trusted to memory:
| |
If you’re managing more than a handful of hosts, this exact pain point is the strongest argument for moving to SSH certificates instead of bare authorized_keys entries — a certificate-based setup revokes trust centrally, at the certificate authority, rather than requiring you to hunt down and edit every individual host’s key list by hand during an incident.
A compromised GPG private key needs the revocation certificate generated when the key was created — this is the one credential type on this list where “generate the fix at the moment you need it” doesn’t work, because generating a fresh revocation certificate requires the private key you may no longer trust or may no longer have. Import the pre-generated revocation certificate, push the now-revoked key to any keyserver it was published to, and generate a fresh key pair to replace it — and if no revocation certificate exists because one was never generated ahead of time, there’s no clean way to tell the world to stop trusting the old key at all, which is precisely why generating one on day one matters more than it seems to at the time.
| Credential | Where trust is stored | How to revoke |
|---|---|---|
| API token | The provider, checked on every request | Revoke in the dashboard or API, then issue a new one |
| Database password | The database, checked at login | Change the password, then update every consumer |
| SSH key | Every authorized_keys file holding the public key | Remove the key from each host, or revoke centrally with certificates |
| GPG key | Keyservers and anyone who imported the public key | Publish the pre-generated revocation certificate |
Rotating routinely, before a leak forces it
Everything above describes reactive rotation — something leaked, now respond. A quieter, complementary practice is rotating high-value credentials on a fixed schedule regardless of whether you know of a leak, specifically because the entire point of a leak is that you often don’t find out about it through your own detection. Scheduled rotation bounds the maximum exposure window to the rotation interval even for a leak that never gets noticed:
| |
A quarterly rotation for anything with real blast radius — cloud provider API tokens, database passwords for production systems — costs a predictable, scheduled few minutes of coordinated update rather than an unpredictable emergency response, and it has a second, less obvious benefit: it keeps the rotation process itself rehearsed. A checklist you’ve actually walked through eight times on a calm Tuesday afternoon executes far more reliably during a genuine incident than one you’re reading for the first time under pressure.
Step six: the postmortem that stops a repeat
Once the immediate exposure is closed, the last step is the one that’s easiest to skip because the pressure’s off by then: a short, honest note focused on how the leak actually happened, more useful than a bare confirmation that it was fixed. Was it a token in a .env.example, an accidental git add . that swept up a real config file, a screenshot with a key visible in a terminal window? The layered prevention worth adding afterward is specific to how this particular leak happened — a pre-commit gitleaks hook prevents the “committed a real value into an example file” pattern specifically, but does nothing for a key pasted into a Slack message or a screen-shared terminal, which needs a different kind of habit change entirely. Writing this down even for an incident that never left your own machine is worth the ten minutes — the goal isn’t documentation for its own sake, it’s making the next version of you, under less pressure, less likely to make the same mistake twice.
Quick reference: the order, stated plainly
- Scope it — what leaked, where, for how long, what can it reach.
- Revoke the old credential before or simultaneously with issuing the new one, never after.
- Rotate everywhere it’s consumed — every environment, every CI variable, every secrets-manager entry, not just the source.
- Check the audit log for the exposure window to know whether it was actually used.
- Re-verify the credential’s actual permission scope for any lateral reach you didn’t expect.
- Write down how it happened, specific enough to prevent the same mechanism next time.
Keep this somewhere you’ll actually find it at 1am, rather than buried in a wiki you haven’t opened in a year. The value of a checklist during an incident isn’t teaching you anything new — it’s making sure stress doesn’t cost you a step you already knew mattered.




