StoicBuilder

HandbookXIV the VallumRotating secrets

XIVthe Vallum, Defend it

Rotating secrets

1 min readUpdated 28 November

In plain words

Rotating a secret means issuing a new key, deploying it, confirming everything uses it and then revoking the old one, done on a schedule and immediately whenever the key may have leaked.

Where you see it

A Harbor engineer pastes a Stripe secret key into a public gist by mistake. Deleting the gist isn't enough, because the key may already be copied. The fix is to roll the key in Stripe's dashboard, update the secret store, redeploy, and check Stripe's logs for calls you didn't make.

docs/runbooks/rotate-a-key.mdconfig
1. Create the new key; leave the old one valid for now2. Store it in the secret manager or host env vars, never the repo3. Deploy, and confirm every service uses the new key (logs, last-used dates)4. Revoke the old key5. Check the provider's logs for any use of the old key you can't explain
Overlap the two keys so nothing breaks, then close the old one. Skipping step 4 leaves the leak open.

What goes wrong

  1. Revoking before deploying

    Switch the old key off first and every service still using it fails at once. Run old and new side by side, move everything over, then revoke.

  2. Deleting the commit and calling it done

    Automated scanners find keys in public repos within minutes, and removing the commit doesn't take the key back. Rotate it, then clean the history if you need to.

  3. Secrets that can't be rotated quickly

    A key hardcoded in a dozen files or a shipped mobile app takes days to change. Read secrets from one place at runtime, so rotating is a config change and a restart.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
List every secret this app uses, where it's stored, which services read it, and whether the provider allows two active keys at once. Write a rotation runbook for each that overlaps old and new keys, and change the code so every secret is read from the environment or our secret manager at runtime, never from the repo.

Quick check

Sign in to earn +10 XP for it

A Harbor API key was committed to a public repo an hour ago, and you've deleted the commit. What's left to do?

Got a prompt that touches rotating secrets?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.