Skip to main content

Rotating a leaked secret: a 60-minute runbook

Someone pastes a production API key into a pull request, a CI log prints a token, or a secret scanner flags a password in a commit from last spring. The instinct is to delete the line and rewrite history. That is the wrong first move. Until the credential stops working, every copy of it, in clones, forks, caches, logs and the attacker's notes, is still a working key.

This runbook puts the steps in the order that limits damage, with rough timings for the first hour. Adapt the commands to your providers; the order is the part that matters.

Minutes 0 to 5: scope it, do not spread it

Answer four questions in your incident channel, without pasting the secret itself:

  1. What is it? Provider, account, environment (production, staging, a developer's own key) and what it can do.
  2. Where was it exposed? Public repository, private repository, CI log, container image, client-side bundle, chat, ticket, screenshot.
  3. Since when? The commit or log timestamp. That is the start of the window you will search later.
  4. Who owns it? The person or team who can revoke it right now.

A public exposure is urgent in minutes, not days. Automated scrapers watch public commits. GitHub's own partner program documentation recommends "considering any secrets that GitHub sends you messages about as public and compromised", and some providers revoke a key the moment they are told about it, which may be how you found out.

Minutes 5 to 15: revoke or disable first

Make the leaked value stop working before anything else. GitHub's guide to removing sensitive data says the same: "as a first step you need to revoke and/or rotate that secret".

For an AWS access key, deactivate it rather than deleting it, so you can still look up its activity:

aws iam update-access-key --user-name ci-deploy --access-key-id AKIA... --status Inactive

AWS's routine rotation procedure creates the new key first, moves applications over and waits several days before deactivating the old one. That is right for planned rotation and wrong for a leak. For a leaked key, accept a short outage over an open door: deactivate now, then fix what breaks.

If revoking would take down a critical system, create the replacement first, deploy it, and revoke within the hour. Do not let "we will rotate it next sprint" become the plan.

Minutes 15 to 30: replace it, all at once

Issue the replacement with the least privilege the system actually needs, store it in your secret manager, and deploy.

Rotate everything the leak touched in one coordinated step. A CI breach that exposed one secret probably exposed all the secrets that job could read. The March 2026 advisory for a compromised scanner action, GHSA-69fq-xp46-6x23, traces the second wave of that attack to an earlier rotation that "was not atomic (not all credentials were revoked simultaneously)", which let the attacker collect the new values. Our post on the security scanner as the attack path covers that incident.

Credential Revoke Watch out for
Cloud access key Deactivate the key, then delete New keys, users or roles the attacker created
Source host token (PAT, deploy key, app key) Revoke in the provider settings Repositories, workflows or webhooks it changed
Payment or messaging API key Roll the key in the provider dashboard Charges, refunds, payouts, messages sent
Database password Change it and kill existing sessions Connections that stay open on the old login
Webhook signing secret Rotate on both sides Forged events accepted during the window
OAuth client secret Regenerate it and revoke issued tokens Refresh tokens that outlive the secret
Private key (TLS, signing, SSH) Revoke the certificate or key, issue a new one Artifacts signed with the old key, authorized_keys entries

Minutes 30 to 45: check what it was used for

Now search the provider's logs from the start of the exposure window to the moment of revocation.

  • Cloud: search the audit log for the access key ID and for anything it did, especially identity changes. An attacker's first move with a cloud key is often to create a second key or a new user so the first one can be thrown away.
  • Source host: check the organisation audit log for new tokens, deploy keys, collaborators, workflow changes and releases.
  • SaaS APIs: check the dashboard's API request log for calls from unfamiliar IP addresses or user agents.
  • Database: check connection logs and look for unexpected exports or schema changes.

If you find use you cannot explain, this is no longer a rotation. It is an incident: preserve the logs and bring in whoever owns incident response.

Minutes 45 to 55: clean up the copies

With the value dead, removing it from history is hygiene, not containment. Decide whether it is worth the cost. Rewriting history breaks every clone and open pull request, and GitHub warns that the data stays reachable in forks and other users' clones, and through cached views and pull request references until GitHub Support removes them. If you do rewrite, the documented tool is git-filter-repo with --sensitive-data-removal.

Then clean the places history rewriting does not reach: CI logs and artifacts, container image layers, build caches, error-tracker events, chat messages and tickets where the value was pasted.

Minutes 55 to 60: stop the next one

Write down how it leaked and close that route:

  • Before commit: a pre-commit secret check and push protection on the source host.
  • In code: read secrets from the environment or a secret manager, with no literal fallback value in code.
  • In CI: short-lived OIDC credentials instead of stored keys where the provider supports it, and no set -x or debug logging in jobs that hold secrets.
  • Afterwards: check that the old value is really dead, and that no other file still carries it.

Where Vulkro helps

Vulkro Core finds hardcoded secrets in source, config, .env files, Terraform, Helm and Kubernetes manifests, and in git history (up to the last 500 commits within the last two years), with the commit that added each one. Two rules are aimed at rotation itself:

Rule What it flags
secret-survives-rotation A secret removed by a "rotation" commit that is still present at HEAD, or replaced in one file while the same value stays in another
secret-rotation-overdue A committed secret first seen more than 90 days ago and still present at HEAD
env-fallback-hardcoded-secret A literal fallback value for a secret environment variable

Values are compared by hash, so the history rules never print a raw secret. To confirm the leaked key is dead after rotation, opt in to a live check, which is the only part of secret scanning that uses the network:

vulkro scan . --validate-secrets      # tags each secret [live], [dormant] or [unknown]
vulkro install-hook --pre-commit      # block new findings, secrets included, before commit

FAQ

Should I delete the commit or rotate the secret first?

Rotate (or revoke) first. Deleting the commit does not remove the value from clones, forks, caches or logs, and it can take hours. Revoking takes minutes and makes every copy useless.

Is rewriting git history necessary after rotating a secret?

Not always. Once the credential is revoked, the copy in history is harmless, and GitHub notes that rewriting may be unnecessary. Rewrite when policy requires it or the value cannot be revoked, and plan for broken clones and open pull requests.

How do I know if a leaked key was used?

Search the provider's audit or request logs for the key's identifier between the time it was exposed and the time you revoked it. Look especially for new credentials or users created with it, which an attacker uses to keep access after you rotate.

See the secrets detection docs and the supply chain use case, or start a 14-day trial. Related: secrets in git history and hardcoded secrets in private repos.