Guides · ← All guides
How to Rotate Credentials After an AI Agent Compromise
By the Ingenious AI team · Published: November 14, 2026 · Reviewed: November 14, 2026 · 8 min read
The short answer
Rotate for reach, not for proven use: every key, token and session that sat inside the agent's environment during the incident window is presumed copied until the preserved audit trail proves it was never within reach. Rotate in dependency order — identity and vault keys first, then the stores the agent read, then downstream API keys — and revoke sessions, do not just change passwords, because a session token copied before rotation keeps working after a password change. Finish by proving death: call each old credential once and watch it fail. In Rogue-Agent Defense the rotation list is generated from the agent's permission record, which is why the smallest possible keys turn an incident-week into an incident-hour.
Generate a free canary token → No signup, nothing stored: plant a tripwire where your agent works while you read — most controls in this guide start working the moment a canary, a policy check, or a spend cap is in place.
What is credential rotation after an agent compromise? the replacement of every API key, token and session an agent could have reached during an incident window, with revocation of the old copies, so a stolen credential stops working everywhere at once.
Why reach beats proof
The tempting shortcut is rotating only the credentials the logs show the agent using. It fails twice. First, logs show tool calls, not reads: an agent that loaded a secrets file into context has every key in that file, whether or not any later call used them. Second, the window is uncertain — you scope from the first off-policy call you can find, and the honest phrase is can find. Anything reachable before that moment is a judgement call; make it in favour of rotation, because the asymmetry is brutal: rotating an unused key costs minutes, missing a used one costs a second incident on the attacker's schedule.
This is the same logic as the quarantine scope in the quarantine guide: breadth first, narrowed by evidence. A credential the trail affirmatively clears — it entered the environment after the window closed, it lives in a store the agent's policy denied with the denial logged — can stay. Everything else rotates.
The order: identity, stores, leaves
Rotate from the root outward. First, identity credentials: the keys that mint other keys — vault unseal tokens, cloud IAM keys, the OAuth grants that can request new sessions. Until these rotate, every later rotation can be quietly undone by whoever holds the root. Second, the stores: database passwords, queue credentials, the mail and CRM tokens the agent's tools authenticate with. Third, the leaves: third-party API keys scoped to single services.
Within each tier, create the new credential before revoking the old one wherever the service allows two live keys — deploy the new, verify a call succeeds, then revoke. The exception is a credential you know is in hostile hands: revoke first and accept the outage. A broken integration is a ticket; a live stolen key is a breach with a fuse.
The session trap
The most common rotation failure is invisible: the password changed, the dashboard shows the new key, and the attacker's copied session — a refresh token, a long-lived cookie, a personal access token minted weeks ago — keeps working, because nobody revoked sessions. Agents accumulate these quietly: every tool connection, every approved integration, every remembered login is a session that survives password rotation.
So the rotation checklist has a second column: for each credential, list its sessions and revoke them explicitly. In Rogue-Agent Defense's incident flow this is mechanical — the kill and quarantine controls revoke sessions as part of the hold, per the kill switch guide — but in a hand-rolled stack it is the step to write down and tick off, service by service, with the revocation confirmation saved next to the rotation record.
Canaries: the rotation list that writes itself next time
There is a way to make the next rotation provable instead of presumptive: plant canary tokens among the real credentials. A canary that never fired tells you that store was likely never read; a canary that fired tells you exactly when the reading happened, anchoring the window. Placement strategy is covered in where to plant canary tokens.
Canaries also solve the verification problem after rotation. Plant fresh canaries alongside the new credentials: if the attacker retained a path you missed, the new canaries are the tripwire most likely to catch the return visit — and this time the quarantine is automatic and the window is minutes, not days.
Proving the old keys are dead
Rotation is not done when the new keys work; it is done when the old keys provably do not. Test each retired credential with a harmless call and record the failure — a 401 with a timestamp, saved to the incident record. Services differ: some keys die instantly, some propagate over minutes, and a few providers leave revoked keys readable in caches longer than anyone expects. The test is how you find out which kind you have while you are still watching.
Close the loop in the incident record: the rotation list, the order, the session revocations, the death tests, and the one line that matters for the postmortem — how long the full rotation took, and what would make it faster. If the honest answer involves a person hunting through three dashboards, the fix is a permission inventory kept before the incident, not heroics during it.
Five actions to take today
- Build the reach list now. For each agent, record every credential in its environment and every store its policy lets it read — before an incident asks.
- Order it root-first. Identity and vault keys, then stores, then leaf API keys; new key live before old key revoked, unless the key is known-hostile.
- Add the session column. Every credential entry names its sessions and tokens, with an explicit revocation step.
- Plant canaries among the keys. One per store at minimum, so the next window anchors itself.
- Death-test every old key. One harmless call per retired credential, the failure recorded with a timestamp in the incident file.
A worked example: rotation in 52 minutes at Northbeam Outfitters
The following is a fictional example built from real threat classes and controls. The company and numbers are invented; the mechanics are not.
Northbeam Outfitters, a 40-person outdoor retailer, discovers its returns agent touched a canary at 10:06 — an exfil-secret event, auto-quarantined by 10:07. The agent's pre-built reach list names nine credentials: the returns database password, the mail token, the shipping API key, the payments read key, three integration tokens, a vault session and one legacy key nobody remembered issuing.
Rotation runs root-first: vault session revoked and re-minted by 10:15, database and mail by 10:31, the leaf keys by 10:47. The legacy key produces the incident's second scare — its death test at 10:52 succeeds instead of failing: the provider had two key slots and the revocation had hit the wrong one. The team revokes the correct slot and re-tests at 10:58: 401, dead, recorded.
The postmortem maths: nine credentials, 52 minutes, one trap found by the death test that dashboards alone would have missed. Northbeam's fix is not faster hands — it is deleting the legacy key class entirely and moving the remaining eight behind the agent gateway, so the next rotation list is shorter and every death test runs from one screen.
Frequently asked questions
Which credentials do I rotate after an agent compromise?
Everything the agent could reach during the incident window: keys and tokens in its environment, secrets in stores its policy allowed it to read, and every live session it held. Rotate for reach, not proven use — logs record tool calls, not context reads, and a key loaded into context is a key presumed copied.
In what order should credentials be rotated?
Root-first: identity and vault credentials that can mint other keys, then the stores (databases, mail, queues), then leaf API keys for single services. Create the new credential before revoking the old where the service allows two live keys — unless a key is known to be in hostile hands, in which case revoke first and accept the outage.
Why is changing the password not enough?
Because sessions survive it. Refresh tokens, long-lived cookies and personal access tokens minted before the change often keep working until explicitly revoked. Every rotation needs a session column: list the sessions each credential carries and revoke them one by one, saving the confirmations.
How do I know the old credentials are really dead?
Test them. Make one harmless call with each retired credential and record the failure with a timestamp. Propagation delays and multi-slot key setups mean a dashboard claim of revoked is not proof — the worked example above found a live legacy key exactly this way.
How can canary tokens help with credential rotation?
Planted among real credentials, canaries turn presumption into evidence: an unfired canary suggests its store was never read, while a fired one timestamps the read and anchors the incident window. Plant fresh canaries with the new credentials to catch any return visit through a path you missed.
Related guides
- AI Agent Incident Response: The First 24 Hours — where rotation sits in the full sequence.
- How to Quarantine an AI Agent — the hold that makes rotation safe to perform.
- Agent Permission Scoping — why short reach lists rotate in an hour.
- Where to Plant Canary Tokens — making the next rotation list write itself.
- Keep API Keys Out of Your Agent's Context — shrinking what rotation has to cover.
- How to Kill Switch an AI Agent — the control that revokes sessions automatically.
Generate a free canary token → No signup, nothing stored: plant a tripwire where your agent works, and let the next rogue action announce itself.