Safeguard
Security Guides•

How do you rotate a CI registry token without breaking builds?

Rotate a registry token in CI with an overlap window: create the new one, update secrets, canary, then revoke the old. Steps, timing and rollback.

Safeguard Security Team
4 min read

Create the new token before you touch the old one, run both for an overlap window, update every secret store, test with one canary pipeline, then revoke the old token and watch for 401 errors. Never revoke first. Set an expiry on the new token so the next rotation is already scheduled.

Why rotations break builds

Most failed rotations share one cause: the old token was revoked before every consumer had the new one. Tokens are copied into more places than anyone remembers: CI secrets, runner images, developer machines, scripts, mirror upstream settings, and container build arguments. Revoke early and one forgotten copy fails at 3 a.m.

What the registry lets you do

Using npm as the example, the access token documentation says granular tokens can be given an expiration date at least one day in the future, can be limited by package, scope and IP range, and can be read only. An account can hold up to 1000 granular tokens. That headroom is what makes an overlap possible: you can hold the old and new tokens at the same time without deleting anything. Check the limits for your own registry.

The rotation steps

  1. Inventory the consumers. Search your repositories, CI settings and secret stores for the token name or the registry host. Write the list down.
  2. Create the new token. Same scope, read only if the old one was read only, with an expiry date. Name it with the date so it is obvious later.
  3. Update the secret stores. Replace the value in each place. Do the least critical pipelines first.
  4. Run a canary. Pick one low risk pipeline and one clean install. Confirm that it authenticates with the new token, not a cached credential from an earlier run.
  5. Wait through an overlap window. Keep the old token alive for a day or a full cycle of your scheduled jobs, so nightly and weekly pipelines also run with the new one.
  6. Watch the logs for 401s. A 401 from the old token tells you a consumer was missed. A 401 from the new one tells you a mistake in the new value. See registry errors in CI.
  7. Revoke the old token. Only after the overlap window and a quiet log.
  8. Record it. Note the date, the owner, the consumers and the next expiry.

A timing table

StepWhenRollback if it fails
Create new tokenDay 0Delete it, nothing else changed
Update secretsDay 0 to 1Put the old value back
Canary runDay 1Fix the value, repeat
Overlap windowDay 1 to 3Old token still works
Revoke oldDay 3 or laterCreate another new token

Rotating after a leak is different

If a token leaked, skip the overlap. Revoke first, accept the breakage, and fix consumers quickly, because the leaked token is already in someone else's hands. The checks are in leaked registry token: what to check on npm and PyPI. Planned rotation and incident rotation are two procedures. Write both down.

Make the next rotation cheap

Where Safeguard fits

Rotation reduces the window in which a stolen credential works. Safeguard's asset discovery and SBOM and dependency scanning help you find which repositories and pipelines depend on a registry, so the consumer list in step one is not a guess.

Quick check

How long should the overlap window be?

Long enough for your slowest scheduled pipeline to run once. For many teams that is a few days. Use your own schedule to decide.

Should I rotate on a fixed schedule?

A schedule is useful, and an expiry on each token enforces it. Rotate immediately if you suspect exposure.

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.