Least privilege

Why you need it

The shop app was given a key that opens every database, because that was quicker than working out what it needs. The day that key is stolen, the thief gets everything written on it, not just what the shop ever used.

Think of it like this

A cleaner's key that opens the office and the storeroom, but not the safe. If the cleaner loses it, you lose very little. A master key that opens everything is a much worse thing to lose.

Where you’ll find it

  • AWS: IAM lets you write exactly which actions each app may take, and on which things.
  • Google Cloud: The role recommender spots permissions an app has never used and suggests removing them.
  • PostgreSQL: GRANT gives a database user only the tables and actions you name, like read-only on orders.
  • Kubernetes: RBAC gives each program in the cluster only the rights it is given, and nothing by default.

What to know first

The key. The password or token the app uses to get in, kept in a secret store. See Secrets management.

Permission. One thing a key is allowed to do, like "read orders". A key is its list of permissions.

How it works

  1. A key is its list. The names written on the shop app's key are users, payments and orders. Whatever is on the list, the key opens. This is the first beat of the animation.
  2. A stolen key opens all of it. Keys do leak: a log, a laptop, a bug. When this one is stolen, all three databases are open, even the two the shop never touches.
  3. Give only what is used. The shop only reads orders. So its key gets only orders, and only to read. This is least privilege: each app gets the smallest list that still lets it do its job.
  4. Now the damage is small. Stolen again, the key opens only orders. Users and payments are untouched. You still have a problem, but a much smaller one.
  5. Lists grow back. Under deadline, someone adds "everything" to make an error go away. Check what each key really uses and trim the rest. Press "put every database on the key" in the animation to see what that costs.

An example

A company has 3 databases: users (2 million people), payments (card records) and orders.

The shop app's key opens all 3. It leaks in a log file. The breach is every customer, every payment, every order.

With least privilege the key reads only orders. The same leak exposes order history, and the 2 million user records and all payments stay closed.

Further reading