Least privilege: limit the blast radius
Every user, service and key should have only the permissions its job needs, and nothing more. You can't prevent every compromise, but you decide how far a compromise can spread.
In one sentence
Assume something will get hacked. Least privilege makes sure that when it does, the attacker gets the keys to one room, not the whole building.
The idea
A small image-resizing service gets a vulnerability in a library it uses. How bad is that? It depends entirely on what that service is allowed to touch. If it runs with the same admin cloud key as everything else, the answer is: your database backups, your customers, everything.
Where to apply it
| Layer | Too much | Least privilege |
|---|---|---|
| Cloud IAM | One key with AdministratorAccess in every service | One role per service with only the actions and resources it uses |
| Database | App connects as the owner/superuser | App user can SELECT/INSERT/UPDATE its tables; migrations use another user |
| People | Every engineer is admin in production | Read-only by default, elevated access on request and time-limited |
| API tokens | Personal token with full account scope in CI | Fine-grained token for one repo, expires in 30 days |
| Containers | Runs as root with the host's network | Non-root user, read-only filesystem, no extra capabilities |
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::shop-images/*"
}Making it practical
- Start from zero and add permissions when something fails, instead of starting from admin and removing.
- Separate identities per service and per environment: staging keys can't touch production.
- Short-lived credentials (cloud roles, OIDC in CI) instead of long-lived keys in env files.
- Review regularly: cloud providers show which permissions were actually used in the last 90 days.
Key takeaways
- 01Give every identity the minimum permissions its job needs.
- 02Design for compromise: limit what a hacked component can reach.
- 03Prefer short-lived, scoped credentials over shared long-lived keys.
- 04Separate environments and services so one leak doesn't become all leaks.
Check your understanding
1 of 3
What is the principle of least privilege?
Related concepts
Defense in depth
Every control has holes. Line up several independent ones and the holes rarely align: the Swiss cheese model.
6 min read →Threat modeling
Threat modeling is answering four questions: what are we building, what can go wrong, what are we going to do about it, and did we do a good job?
8 min read →SSRF
Your server sits inside your network. If a user picks the URL it fetches, they borrow that position. Allowlist destinations, block private addresses after DNS resolution, and lock down cloud metadata.
7 min read →