Use when a secret is found in code or history, or for scheduled rotation: identify the provider, rotate the credential through its API (AWS IAM, GitHub, Stripe, GCP, Azure, Twilio, Slack and more), revoke the old one, log the audit trail and link the post-mortem. Scrubbing git history is not enough.
85%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Detecting a leaked secret in code is the easy part. Rotating it correctly - without breaking production, with full audit trail, across all the systems that referenced the old value - is the hard part. This skill is a build-an-X workflow for the rotation process.
Critical assumption: git-history rewrites (BFG Repo-Cleaner, git filter-repo) do NOT prevent compromise. The leaked secret IS exposed (forks / clones / mirrors / archives / human eyeballs). Rotation is mandatory; history scrub is at most cosmetic.
gitleaks-scanning)
found a leaked credential.The scanner output identifies the credential class:
| Detection | Provider | Rotation API |
|---|---|---|
| AWS key ID + secret (AKIA…) | AWS IAM | aws iam create-access-key + aws iam delete-access-key |
| GitHub PAT (ghp_…) | GitHub | github.com/settings/tokens (or GraphQL API) |
| GCP service account key | GCP IAM | gcloud iam service-accounts keys create + delete |
| Azure service principal | Azure AD | az ad sp credential reset |
| Stripe API key (sk_live_…) | Stripe | dashboard.stripe.com → API keys (manual roll in the dashboard) |
| Twilio account+token | Twilio | console.twilio.com → API Keys |
| Slack bot/user token (xoxb-…, xoxp-…) | Slack | api.slack.com/apps → OAuth & Permissions |
| Database password (DB conn string) | DB-specific | ALTER USER etc. |
| Custom JWT signing key | Internal | App-specific rotation logic |
For automation-friendly providers (AWS, GitHub, GCP, Azure, Twilio), rotation can be scripted. Payment-provider keys (Stripe) are rolled by a human in the provider dashboard, never by an unattended script. For others (often custom or on-prem), rotation is manual + documented.
Before rotating, identify everything that uses the old value:
# Local: where does the leaked key appear?
grep -r "AKIAEXAMPLE" .
# Across infrastructure: secret-management system
vault kv list -recursive secret/ # for HashiCorp Vault
aws secretsmanager list-secrets # AWS Secrets Manager
# Across application code: where's the env var consumed?
grep -r "MY_API_KEY" src/
# Across CI/CD: where's the secret injected?
gh secret list # GitHub Actions secretsThe blast radius shapes the rotation strategy:
The provider supports multiple active credentials simultaneously:
This minimizes downtime risk. Most modern providers support it (AWS allows 2 active access keys per IAM user; GitHub supports multiple PATs).
# Example: AWS IAM user "myapp"
NEW_KEY=$(aws iam create-access-key --user-name myapp)
NEW_KEY_ID=$(echo $NEW_KEY | jq -r '.AccessKey.AccessKeyId')
NEW_SECRET=$(echo $NEW_KEY | jq -r '.AccessKey.SecretAccessKey')
# Deploy new key to all consumers...
# (e.g., update Kubernetes secrets, Vault, AWS Secrets Manager)
# After verification, deactivate old:
aws iam update-access-key --user-name myapp --access-key-id $OLD_KEY_ID --status Inactive
# Wait observation window (e.g., 24h to confirm no consumer regressed)
aws iam delete-access-key --user-name myapp --access-key-id $OLD_KEY_IDSome providers only support one credential at a time:
Higher downtime risk; minimize via tooling that updates all consumers atomically.
If active exploitation is confirmed:
After rotation:
# AWS: check audit log for usage of old key after deactivation
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=AccessKeyId,AttributeValue=$OLD_KEY_ID \
--start-time $(date -u -v-7d +%Y-%m-%dT%H:%M:%S)
# GitHub: check audit log for PAT usage
gh api orgs/myorg/audit-log --paginate | jq '.[] | select(.actor_token_id == "leaked-token-id")'
# Stripe: dashboard.stripe.com → API keys → activity logAudit verifies:
Cross-ref post-mortem-author (in the qa-process plugin):
If the scanner missed the format that leaked, add a custom rule:
[[rules]] in .gitleaks.toml
(cross-ref gitleaks-scanning Step 4)gitleaks-scanning, its TruffleHog reference)This is the "test that catches the bug" pattern for security: make sure the same leak format gets caught at PR time going forward.
Beyond reactive rotation, schedule periodic rotation:
| Secret type | Recommended rotation cadence |
|---|---|
| Production cloud-provider service account keys | Quarterly |
| Long-lived API keys (Stripe, Twilio, Slack) | Quarterly |
| Database passwords | Quarterly + on personnel change |
| GitHub PATs | Quarterly + on personnel change |
| TLS certificates | Per provider (typically 1 year max) |
| JWT signing keys | Annually (with grace period for outstanding tokens) |
| Webhook signing secrets | Annually (with grace period for in-flight webhooks) |
Automate via the same workflow (Step 3 two-secret pattern); don't wait for an incident to discover the rotation runbook is broken.
For coordinated rotation across consumers, use a secrets-management platform:
These platforms handle the consumer-update-and-coordinate part (Step 3 deploy phase) more reliably than ad-hoc scripts.
After every rotation:
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| Trust git-history scrub to fix the leak | Leaked secret IS exposed; assume compromise | Always rotate (Overview) |
| Atomic swap without coordination | Brief outage during deploy | Two-secret pattern (Step 3A) |
| Skip audit-log review post-rotation | Miss unauthorized usage during exposure | Always audit (Step 4) |
| Rotate; skip post-mortem | Same leak pattern recurs | Document + add detection rule (Steps 5 - 6) |
| Ad-hoc rotation; no proactive cadence | Rotation runbook stale; emergency rotation breaks | Quarterly cadence per secret type (Step 7) |
gitleaks-scanning (gitleaks, plus TruffleHog in its references) -
the detection steppost-mortem-author -
cross-plugin: post-rotation incident documentation