Secrets management

Why you need it

The database password is written in the code. The code is copied to every laptop, every backup and every build. Lose one laptop and the password is gone with it, and changing it means editing the code and releasing again.

Think of it like this

A hotel front desk. Guests do not carry a copy of every room key home. They are handed a key at the desk when they arrive, and if a key is lost, the desk changes the lock and hands out a new one.

Where you’ll find it

  • AWS: Secrets Manager stores passwords and keys, hands them to apps, and can change them on a timer.
  • HashiCorp: Vault is a secret store many companies run themselves, on any cloud.
  • Kubernetes: Secrets hold passwords apart from the app, and hand them to each copy as it starts.
  • GitHub: Secret scanning looks for passwords and keys pushed into code by mistake.

What to know first

Secret. Anything that grants access: a password, an API key, a private certificate.

One box, many places. The app is built once and runs on test and production. See Build once, deploy many. So a secret inside it would be the same everywhere, and copied everywhere.

How it works

  1. Code spreads. Ana writes the password in the code. The code is copied to Ben's laptop, to every build, to every backup. In the animation it lands on every laptop.
  2. One leak is enough. Ben's laptop is stolen. Nobody attacked the database, but the password left with the laptop, and now someone else has it.
  3. Keep it in one place. Take the password out of the code. Keep it in a secret store: one locked place, with a list of who may read it. The code now only names it, like DB_PASSWORD.
  4. Hand it over at start. When the app starts, it proves who it is to the store and is handed the password, kept only in memory. This is the store handing it to the server in the animation.
  5. Change it in one place. If a password may have leaked, change it in the store. Every server gets the new one, with no code change and no new release. Press "change the password" in the animation to see it.

An example

A team of 12 has the database password in the code. It is on 12 laptops, 2 years of backups and every build.

One laptop is lost. To be safe they must change the password, edit the code, and release again: about half a day, with the site at risk.

With a secret store, the password is in one place. They change it there in 2 minutes; the servers pick up the new one, and the lost laptop holds nothing useful.

Further reading

  • Secrets Management Cheat Sheet, OWASP. A clear, tool-free checklist: where secrets live, who reads them, how to change them. Start with this one.
  • Config, The Twelve-Factor App. Why settings like passwords belong outside the code, in one short page.
  • Rotate AWS Secrets Manager secrets, AWS docs. How a store changes a password by itself, without the app noticing.