Blog

Agent-driven key rotation without losing the new key

How BotPassword lets an agent rotate an API key through a durable state machine, so a crash or timeout never strands you without a working credential.

BotPassword team5 min read

BotPassword lets an agent rotate an API key or change a password without being handed the value by default, using a durable state machine that writes the new credential into the vault before anything can lose it. This post summarizes ADR 0010 and the rotation section of the broker design. Status: partly built. The state machine and the Cloudflare and AWS IAM adapters run today, and an agent can reach rotate only under a grant with autopilot. Password changes (change_password) and the other strategies are planned, not built yet.

Why is rotation the hard intent?

Most intents read from the vault. Rotation changes two systems at once: the provider, which issues a new credential and eventually revokes the old one, and the vault, which has to end up holding the working value. Anything that fails between those two writes can leave you worse off than before. Imagine the provider creates a new key, the process crashes, and the only copy of that key was in memory.

If you do this by hand, you know the manual version of the problem: create the new key, update every consumer, check the old one is unused, then delete it. How to rotate API keys walks through it. BotPassword turns those same steps into something a machine can run safely and resume.

What are the states?

ADR 0010 defines a durable state machine: Planned, Created, Stored, Verified, Promoted, OldRevoked, and NeedsAttention. In order:

  1. Planned. The request is accepted and recorded, with an idempotency key, before the provider is called.
  2. Created. The provider issued a new credential.
  3. Stored. The new value is written to the vault as a pending revision.
  4. Verified. The new credential authenticated successfully in a non-destructive call.
  5. Promoted. The pending revision becomes the current one, and consumers listed on the credential are notified.
  6. OldRevoked. After a grace period, the old credential is revoked at the provider.

A failure to verify, or to revoke the old key, moves the record to NeedsAttention with exact instructions. If the provider refuses at the start, the rotation ends as Failed with nothing changed.

Why persist before every external call?

Because a timeout is ambiguous. If the call to create a key times out, did the provider create it or not? BotPassword records the Planned state first, carrying an idempotency key. After a restart, an interrupted Planned rotation queries the provider by that key, or by a deterministic name derived from the rotation id, before trying again. A timeout therefore cannot create a second credential by accident.

The same logic applies to the new value. It is stored as a pending revision immediately after creation and is never held only in memory. The rule is that no step runs twice blindly: each step either checks provider state first or uses a provider idempotency key. Where neither is possible, the answer is unknown_outcome, not an automatic retry.

The rotation record lives in the local store and syncs, so another trusted device can finish or report an interrupted rotation.

Why wait before revoking the old key?

Because the new key is not the whole story. Systems that still hold the old one will break the moment it dies. The default grace period for personal credentials is 10 minutes, and company policy can change it. Consumers listed on the credential, such as a deploy script or CI variable, are notified when the new revision is promoted.

Providers differ in what they allow, and the manual rotation guidance in the dataset shows why a grace window matters:

  • Stripe’s dashboard lets old and new keys both work for up to 7 days when you choose an expiry (/keys/stripe).
  • AWS allows two access keys per IAM user, which is what makes zero-downtime rotation possible, and recommends deactivating a key before deleting it so you can reactivate it if something still depends on it (/keys/aws).
  • Cloudflare’s Roll invalidates the old token secret as soon as you confirm (/keys/cloudflare).

A fixed grace period is a starting point. The ADR notes that consumer lists are needed so rotation does not cause outages.

What if the provider has no rotation API?

Each provider adapter gets a declared strategy, because providers differ:

Strategy When it applies
api The provider offers an API to create or roll credentials. Fully automatic, using a separate management credential the grant names.
delegated The provider offers short-lived scoped credentials, so there is nothing long-lived to rotate.
browser_assisted Rotation exists only in the dashboard. The agent drives the page, BotPassword handles sign-in, and the new value is read from the page straight into the pending revision.
human_assisted Nothing else works. BotPassword opens the right page and captures the value you paste through its own interface.

The ADR is candid that the fully automatic strategy is available only where the provider supports it. Adapter capabilities are checked against the real providers, not assumed. For example, GitHub does not document an in-place regenerate flow for personal access tokens, so BotPassword uses a browser-assisted route there and recommends moving long-lived automation to a GitHub App with short-lived installation tokens. See /keys/github.

Who decides that an agent may rotate?

The user. rotate (partly built) and change_password (planned, not built yet) are separate grant flags, set in BotPassword’s interface, so a grant that lets an agent run a command with a credential does not automatically let it replace that credential. A personal grant can be switched to an autopilot mode where rotation runs without confirmation, and company policy can forbid autopilot for company credentials. The agent receives rotated and a revision reference, never either key.

For the reasoning behind withholding values, see intents, not values. To understand where the state machine runs, read why a local daemon holds the keys.

What does this not solve?

It does not make rotation free. Consumers outside the vault, such as a forgotten cron job, still break when the old key is revoked, which is why consumer lists and grace periods exist. And if a key has leaked, speed matters more than grace: follow what to do when an API key leaks and revoke first.

More from the blog

Give agents access. Keep the keys.

BotPassword is in early access. Request an invite and we'll email you when your spot opens.