Skip to content
Post Mortem

Lesson ยท 5 min

Secret keys: the codes that must stay private

A leaked key can turn into a surprise bill or a break-in within hours.

A secret is a code that proves who you are to a service. Examples are an API key (a code that lets one program talk to another and charge your account), a password, or an access code.

Secrets leak in ordinary ways: saved into a shared project, pasted into a chat or an AI tool, shown in a screenshot, or visible in a record of what a program did.

Once a secret is exposed, assume it has been copied. Deleting the file does not help. Cancel the key and make a new one. Cancelling and replacing a key is called rotating it.

If a key has leaked, cancel it first and accept a short outage. A broken app is cheaper than a stolen key. If you are just replacing it on a schedule, make the new key, switch to it, check it works, then cancel the old one.

If you cannot cancel a key in five minutes, you are not ready for a bad day yet. Find out where each key lives and how to replace it before you need to.

Words you will see

Secret
A string that proves who you are to a service: a key, token or password.
Rotate
Replace a secret with a new one and cancel the old one.
Secret manager
A safe place built for keeping secrets, with access controls and an audit trail.

Decision

You find a secret key sitting in a public place you own. What is the first action?

What to do instead

  • Keep keys in the place your service provides for them, never in the project itself.
  • Never paste keys into AI tools or chats.
  • Set a spending limit and an alert on every service you pay for.

Common mistakes

  • Pasting keys into chats or AI prompts.
  • Committing keys to code, even in a private repository.
  • Using one key for everything.

References and further reading

Finished this one?

Add it to What I learned and earn 50 Trust. You can open your list from the badge at the bottom of the page.