C.W.K.
Stream
Lesson 12 of 12 · published

Secret Rotation

~11 min · rotation, lifecycle, incidents

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Rotation as a discipline, not an emergency

A secret that has never been rotated is a secret you cannot rotate. The first time you try, you'll discover three integrations you forgot about, two scheduled jobs that use the old value, and a Vercel environment with the same key set five months ago. Practice rotation when nothing is on fire.

Rotation cadence by type

  • OIDC tokens — auto, ~1 hour. Don't think about it.
  • Long-lived API keys (OpenAI, Anthropic, Stripe) — quarterly, or any time a contractor or employee with access leaves.
  • SSH deploy keys — annually, or on any laptop loss.
  • Database passwords — on-incident or quarterly.
  • GitHub PATs — phase out in favor of fine-grained tokens / GitHub Apps; rotate fine-grained ones quarterly.

The rotation procedure

  1. Generate the new value in the provider's UI.
  2. Store as a new secret name (e.g., API_KEY_V2) alongside the existing one.
  3. Update workflows / app config to use V2.
  4. Confirm V2 is in use in production for at least one full traffic cycle.
  5. Revoke the old value in the provider.
  6. Delete the old secret name in GitHub.

This pattern (rotate-with-overlap) avoids the dangerous single-cutover where a new key has a typo and prod goes dark.

Code

Rotation cheat sheet·bash
# 1. Add new secret (overlap)
gh secret set OPENAI_API_KEY_V2 --body "$NEW_KEY"

# 2. Update workflow to use V2 (PR + merge)
#    sed -i 's/OPENAI_API_KEY/OPENAI_API_KEY_V2/g' .github/workflows/*.yml

# 3. Trigger CI to confirm V2 works
gh workflow run ci.yml

# 4. Revoke old key in OpenAI dashboard, then:
gh secret delete OPENAI_API_KEY

# 5. Optional cleanup pass: rename V2 back to canonical name
gh secret set OPENAI_API_KEY --body "$NEW_KEY"
gh secret delete OPENAI_API_KEY_V2

External links

Exercise

Pick one long-lived API key in your repo's secrets. Run the full overlap rotation procedure end-to-end this week. Document the steps in a runbook so the next rotation is faster.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.