Skip to main content
THE_COLUMN // AI

Agent Credential Rotation: How Infrastructure Teams Rotate the Keys Production Agents Hold Without Breaking Live Workflows

Written by: iSimplifyMe·Created on: Nov 23, 2026·12 min read

What happens to an agent that is on step four of a seven-step CRM update when the Salesforce token it picked up at step one stops working? If you run agents in production, you have probably already seen the answer in a dead-letter queue: three records updated, four untouched, and a ticket nobody can close without reading the logs line by line.

Production agents now hold API keys, OAuth tokens and service-account secrets across Salesforce, HubSpot, Zendesk, ServiceNow, Snowflake and the AWS accounts underneath them. Scoping decides what those credentials are allowed to do, and we covered that ground in our piece on agent identity and access management. This piece covers what scoping does not: rotating those credentials on schedule, or after an incident, without stranding an agent halfway through a workflow.

Agent credential rotation is the scheduled or emergency replacement of the keys an agent uses to call other systems. Done well, in-flight runs either finish on the new credential or park cleanly, with no partial writes.

Why Credential Rotation Is Harder For Agents Than For Services

A conventional service makes short, stateless calls, so a rotated key affects one request at a time, and a retry with the fresh key usually fixes it. An agent run, on the other hand, is a long-lived chain of tool calls that can span minutes or hours, often with a human approval gate parked in the middle.

That difference changes the failure shape. When a stateless service hits a 401, it fails one request; when an agent hits a 401 at step four, it fails a transaction that has already written to three systems and cannot simply be replayed from the top.

What's more, agents tend to read credentials once at startup and hold them in memory for the life of the run. This is why a rotation that looks clean in the secrets store can still break every run that was already in flight when the old version was revoked.

Agents break on rotation because a single run can last minutes or hours and write to several systems. A key revoked mid-run fails a partly finished transaction, not one isolated request.

What Breaks When A Key Rotates Mid-Workflow

The failure modes are predictable once you have seen them a few times. The ones we see most often in production agent fleets include but are not limited to:

  • Stale in-memory credentials. The agent cached the secret at run start, so the new version in Secrets Manager or Vault never reaches it. Every call after the revocation fails until the run ends.
  • Partial writes with no compensation. Steps one through three committed to HubSpot and Snowflake, and step four failed on auth. Without a compensating transaction, the systems are left disagreeing with each other.
  • Blind retries against a dead key. A generic retry policy treats a 401 like a 503 and hammers the provider. Some vendors read that pattern as credential stuffing and lock the integration user.
  • Refresh-token races. Two parallel workers refresh the same OAuth grant at the same moment. When the provider rotates refresh tokens on use, one worker holds a token that is already invalid.
  • Approval-gate timeouts. A run waits eight hours for a human sign-off, and the short-lived credential it was issued expires before the approver clicks. The approved action then fails at execution time.

All of these trace back to the same root cause. The rotation was designed around the secrets store, not around the lifetime of the runs that depend on it.

The Overlap Window Is The Whole Design

The single most important decision in agent credential rotation is how long two versions of a credential stay valid at the same time. That overlap window has to be longer than your longest realistic run, including any time a run can sit at an approval gate or in an exception queue.

AWS Secrets Manager gives you the mechanics for this through its staging labels: AWSCURRENT, AWSPENDING and AWSPREVIOUS. Its rotation Lambda walks four steps (createSecret, setSecret, testSecret and finishSecret), and the alternating-users strategy keeps the previous credential working while the new one takes over.

Keep in mind that the overlap window lives at the target system, not in the secrets store. If Salesforce, Zendesk or Postgres invalidates the old credential the instant the new one is issued, no amount of label management upstream will save your in-flight runs.

Different credential types give you very different levers. Here's how the common ones compare:

Credential typeTypical lifetimeOverlap supportRotation lever
AWS STS role session15 minutes to 12 hoursNative; each session is independentSet session duration longer than the run, re-assume per step
Secrets Manager secret (database, vendor key)Your schedule; as often as every 4 hoursAWSCURRENT plus AWSPREVIOUS with alternating usersRotation Lambda with a testSecret step that exercises a real call
OAuth access tokenUsually minutes to an hourNatural expiry, refreshed by grantCentral token broker, never per-worker refresh
OAuth refresh tokenDays to indefinite, provider-dependentNone if the provider rotates on useSingle-writer refresh with a lock
GCP service account keyUntil deletedUp to 10 keys per service accountAdd new key, migrate, then disable and delete the old one
Static vendor API keyUntil revokedDepends on whether the vendor allows two active keysIssue second key, cut over, drain, revoke

The pattern across the table is simple. Wherever the vendor supports two live credentials, use that support, and wherever it does not, put a broker in front of the agents so only one component ever has to change.

The overlap window is the period when old and new credentials both work. It must outlast your longest run, including time parked at approval gates, or rotation will strand in-flight work.

How Do You Rotate On Schedule Without Stranding A Run?

Scheduled rotation is the easy case, because you control the timing. That said, it still needs a defined sequence, and skipping a step is how most rotation incidents start.

Here's the sequence we run for scheduled rotation on production agent fleets:
  1. Issue the new version. Create the new credential at the target system and store it as AWSPENDING, or the equivalent in Vault or your secrets store. Nothing reads it yet.
  2. Test it with a real call. The testSecret step should make an actual read against the target, not only check that the string parses. A credential that authenticates but lacks a scope will otherwise surface as a failure at step four of a live run.
  3. Promote it. Move AWSCURRENT to the new version so that every fresh fetch returns it. The old version is now AWSPREVIOUS and still valid at the target.
  4. Drain. Wait until every run that started before promotion has finished, parked or been cancelled. Check this against your orchestration state, not against a timer.
  5. Revoke. Disable the old credential at the target system, then confirm the auth-failure rate stays flat for a full run cycle.

The drain step is the one teams most often replace with a fixed sleep. However, a sleep only works until the first run that outlasts it, and agent runs have long tails, especially when a human approver is involved.

If your orchestrator exposes run state (Step Functions, Temporal and most custom state machines do), the drain check is a query: no active runs with a start time earlier than the promotion timestamp. We walk through that kind of run-state plumbing in our guide to production agent orchestration.

Read Credentials At The Step, Not At The Run

The design change that removes most rotation pain is late binding. Instead of loading a credential when the run starts, the agent fetches it from the secrets store immediately before each tool call that needs it.

Of course, a Secrets Manager call on every step adds latency and cost. A local cache solves that, as long as the cache TTL is shorter than your overlap window; a five-minute TTL against a 24-hour overlap means a promoted credential reaches every worker well before the old one is revoked.

Late binding also fixes the approval-gate problem. A run that waits eight hours for sign-off fetches a fresh credential when it resumes, rather than carrying an expired one forward.

For AWS-native targets, the cleanest version of this is to skip static secrets entirely. Each step assumes an IAM role through STS, gets a session scoped to that step, and the session expires on its own, which leaves nothing to rotate on the agent side.

Fetch the credential right before each tool call, with a cache TTL shorter than the overlap window. Promoted versions then reach every worker before the old version is revoked.

Why OAuth Refresh Tokens Need A Single Writer

OAuth deserves its own section, because it fails in a way the other credential types do not. The OAuth 2.0 Security Best Current Practice (RFC 9700) recommends refresh token rotation, and providers that follow it invalidate the old refresh token as soon as they issue a new one.

That is a sound security control, and it is also a race condition waiting for a parallel agent fleet. If two workers notice an expired access token and both refresh at once, one gets the new pair and the other presents a refresh token that is already dead.

Some identity providers go further and treat the second request as evidence of token theft. Their reuse detection then revokes the entire token family, which disconnects every agent using that grant until someone re-authorizes the integration by hand.

The fix is architectural. Put a token broker in front of the agents, make it the only component allowed to call the refresh endpoint, guard the refresh with a lock (a DynamoDB conditional write or a Redis lock both work), and have workers ask the broker for an access token rather than holding the grant themselves.

Emergency Rotation After An Incident Is A Different Procedure

Everything above assumes you control the timing. After a leaked key, a compromised integration user or a vendor breach notice, you do not, and the priority order flips from protecting runs to cutting off access.

In an emergency, revoke first and repair the runs afterward. An overlap window that keeps a compromised credential alive for 24 hours to protect in-flight work is a window that also keeps the attacker in.

This is why emergency rotation depends on work you did before the incident. Specifically, every agent run needs three properties already in place:

  • Checkpointed state. The orchestrator records which steps completed and what they wrote. A run killed by revocation can be resumed from the failed step instead of restarted from the top.
  • Idempotency keys on every write. When the run resumes, the steps that already landed in Salesforce or Zendesk are recognized and skipped. Without keys, resumption creates duplicate records.
  • Auth-aware failure routing. A 401 or 403 stops retries and sends the run to an exception queue tagged with the credential version. Blind retries against a revoked key only add noise to the incident timeline.

Those three properties map directly onto the retry and failure-isolation patterns in reliability engineering for regulated AI. Moreover, the exception-queue side of it is covered in more depth in our piece on agent exception queues.

Emergency rotation order of operations. Revoke the compromised credential at the target, issue and promote a new version, let auth failures route runs to the exception queue, then resume parked runs from their checkpoints once the new credential passes a real call.

Keep the CloudTrail or vendor audit log for the compromised credential's last 90 days before you delete anything. Your incident review will need it.

Naturally, the rotation itself is only one part of the incident. The containment, communication and post-incident review steps belong in your broader agent incident response runbook, with credential rotation as a named, rehearsed step inside it.

In an emergency, revoke the compromised credential immediately and repair runs afterward. Checkpoints, idempotency keys and auth-aware failure routing make that recovery possible.

How Do You Know Rotation Is Working?

A rotation that nobody noticed is the goal, but silence is also what a broken monitoring setup looks like. You need signals that prove the rotation happened and that no run paid for it.

The metrics we instrument on every agent fleet include:
  • Auth-failure rate per credential version. Tag every 401 and 403 with the version ID the agent presented. A spike on AWSPREVIOUS after revocation means something is still caching the old secret.
  • Runs active across a promotion boundary. Count runs that started before promotion and are still active. This number should reach zero before revocation, every time.
  • Parked runs by cause. Track how many runs landed in the exception queue with an auth reason. After a scheduled rotation, that count should be zero.
  • Secret fetch latency at P95. Late binding adds a call to every step, so watch the P95 on Secrets Manager or Vault reads. A slow secrets store becomes a slow agent fleet.
  • Credential age. Alert on any credential older than its policy allows. A rotation Lambda that has been failing quietly for weeks is a common finding in fleet reviews.

CloudTrail records every GetSecretValue and AssumeRole call, which gives you an audit trail of which agent identity read which version and when. Pair that with your orchestrator's run log and you can answer the question auditors actually ask: which runs used the credential that was compromised?

Testing Rotation Before It Tests You

Rotation is rarely exercised, which is exactly why it fails. The first time many teams run a full rotation against a live agent fleet is during an incident, and that is the worst possible time to discover a hard-coded key.

Run a forced mid-run rotation in staging on a regular schedule. Start a batch of shadow-mode runs, rotate the credential partway through, revoke the old version, and confirm that every run either finished on the new version or parked with a clean checkpoint and zero duplicate writes.

Then make the drill part of release. Any change to an agent's tool set or credential handling should pass the rotation drill before promotion, the same way it passes the validation suite, which is the gate structure we describe in our guide to agent release management.

Where Scoping Ends And Rotation Begins

Scoping and rotation answer different questions. Scoping decides how much damage a credential can do, while rotation decides how long a stolen or stale credential stays useful.

Both need an owner. In most fleets we operate, the platform team owns the secrets store, the rotation schedule and the revocation step, and each agent's operator owns the overlap window, the drain check and the runbook for parked runs, written into the same agent operator playbooks that cover every other production procedure.

All of this adds up to one principle. Design rotation around the lifetime of your runs rather than the convenience of your secrets store, and the keys can change as often as your security policy requires without anyone downstream noticing. For the rest of the operating model these practices sit inside, start at our AI agent operations hub.

Get A Second Set Of Eyes On Your Rotation Design

If you're preparing to rotate credentials across an agent fleet that touches Salesforce, ServiceNow, Snowflake or your own AWS accounts, the team at iSimplifyMe builds and operates production agent systems across CRM, ticketing and data warehouse environments every week. Reach out for a working session: we'll map every credential your agents hold, size the overlap window each one needs, and leave you with a tested rotation and revocation runbook your operators can execute on schedule or at 2 a.m.

Frequently Asked Questions

How often should production agent credentials be rotated?

Match the cadence to the credential type. Prefer STS role sessions that expire in 15 minutes to 12 hours, rotate stored secrets on a 30- to 90-day schedule, and rotate static vendor keys whenever an agent's owner or scope changes.

What should happen to an agent run that fails authentication mid-workflow?

It should stop retrying and park. Route it to an exception queue with the failed step, credential version and idempotency key recorded, then resume from that step once a valid credential passes a real test call.

Why do parallel agent workers break OAuth refresh token rotation?

When a provider rotates refresh tokens on use, two workers refreshing at once race: one gets the new token, the other presents a dead one. Some providers treat that as reuse and revoke the whole token family.

Can you test agent credential rotation before production?

Yes. Rotate the credential partway through a batch of shadow-mode runs in staging, revoke the old version, and confirm every run either finished on the new version or parked cleanly with zero duplicate writes.

Who should own credential rotation for an agent fleet?

The platform team that runs the secrets store should own the schedule and the revocation step. Each agent's operator owns the overlap window, the drain check and the runbook for runs parked by auth failures.

Ready to Grow?

Let's build something extraordinary together.

Start a Project
Apex Architecture

Every site we build runs on Apex — sub-500ms, AI-native, zero maintenance.

Explore Apex Architecture
⌘ K