Part 1, Code · Step 15: Rotate
Replace a key without breaking anything
Swap in a new key. Diego, the owner, creates a new key, sk_live_example_replaced, and gives it only what billing needs. Then Fatima updates the app, and Diego shuts off the old key. This is the step that removes the risk.
Why it matters. Every step before this found the problem. This step removes it.
See it in the lesson Part 1 recap
This really happened: Cloudflare, 2023
After the Okta breach, Cloudflare rotated thousands of credentials but skipped one service token and three accounts it believed were unused. Attackers used them to reach its wiki and Jira.
Why rotation is a pain for teams
- Making the new key takes a minute. Finding every app, job, and script that uses the old one can take weeks.
- Nobody has a full list of where the key is used. Missing one copy breaks production or leaves the old access alive.
- Order matters. Shut off the old key too early and the app breaks. Wait too long and the leaked key keeps working.
- Some services allow only one active key at a time, so there is no overlap to switch over safely.
- Hardcoded keys mean a code change, a review, and a redeploy, not just a settings update.
- Three groups have to coordinate: whoever leaked it, the owner who can replace it, and the team whose app might go down.
- Each kind of key rotates differently. A payment key, a cloud key, a database password, and a private key all have their own steps.
- Fear of an outage pushes rotation to a change window, so a live key can stay exposed for days or months.
Sources
Keep going
- Try TruffleHog open source Scan a repository or a folder on your laptop.
- See TruffleHog Enterprise Continuous scanning, routing to owners, and re-checks.
- Talk to the team Ask how this would work in your environment.
More topics
- A key kept in a vault still gets copied out
- Deleted from the code, and it still works
- Bundled scanners and the noisy queue
- What sits behind a key: owner, reach, permissions, activity
- The owner chase: whose key is this?
- Which key to fix first
- Proof it’s dead, time to fix, and what auditors ask for
- Keys in AI agents and AI training data
- Hosted or self-hosted: where the scanner runs
- Hooks, CI, history, chat, and builds: what each layer catches
- Keys outside the code: logs, vendors, and public files
- Live, dead, or unknown: triage the queue
- One key, three teams: rotate without an outage