What is the Principle of Least Privilege, and how would you apply it to users, services and infrastructure in a real web application?
Answer
The Principle of Least Privilege (PoLP) says every user, process, service account and API key should have only the minimum permissions it needs to do its job, and only for as long as it needs them. The goal is to limit the blast radius: when something is compromised or misused, the damage is capped by what that identity was allowed to do.
What "minimum" actually means
Least privilege applies along several dimensions at once, not just "admin or not admin":
Actions: read vs write vs delete. A reporting service needs SELECT, not DROP TABLE.
Resources: one S3 bucket prefix, not every bucket in the account. One database schema, not the whole cluster.
Time: standing access is riskier than access granted for a 2-hour incident window and then revoked automatically (just-in-time access).
Context: allowed only from the corporate network, a managed device, or with MFA.
Where it shows up in a typical stack
Layer
Over-privileged
Least privilege
Database
App connects as postgres superuser
App role with SELECT, INSERT, UPDATE on its own tables only
Read-only by default, break-glass elevation with approval and audit
API tokens
One master key used by every integration
Scoped tokens per integration, e.g. read-only payouts key
A payments company like Razorpay or a food delivery platform like Swiggy runs hundreds of services. If the notification service can read the payments ledger, a bug or RCE in the notification service becomes a payments breach. Least privilege is what stops that lateral movement.
Why it matters
Limits damage from compromise: a leaked CI token that can only push to one container registry repo is a nuisance, not a catastrophe.
Limits damage from mistakes: an engineer running a bad migration with a read-only role cannot wipe production.
Supports compliance: PCI DSS, SOC 2 and ISO 27001 audits all ask for evidence of role-based access and periodic access reviews.
Makes audits meaningful: when each identity has a narrow purpose, unusual actions stand out in logs.
Common mistakes
Starting with wildcards ("Action": "*") "to get it working" and never tightening them.
Sharing one service account across many services, so you cannot narrow or rotate it without breaking everything.
Privilege creep: people change teams and keep old access. Fix it with periodic access reviews and group-based grants.
Forgetting non-human identities. Service accounts, CI pipelines and third-party integrations usually hold far more power than humans.
Giving the frontend a token that can do more than the logged-in user could do through the UI.
How teams implement it in practice
Inventory what each identity actually does (cloud tools such as AWS IAM Access Analyzer can generate policies from recorded activity).
Grant through roles and groups, never directly to individuals.
Default deny, then allow specific actions on specific resources.
Use short-lived credentials (OIDC federation for CI, STS sessions) instead of long-lived keys.
Review and prune access on a schedule, and alert on use of high-risk permissions.
Least privilege pairs naturally with separation of duties (no single person can both approve and execute a sensitive action) and is a core building block of zero trust.
Rolling out least privilege. A repeatable loop for shrinking permissions without breaking production.
Inventory identities: List users, service accounts, CI jobs and API keys.
Observe real usage: Use access logs to see which actions each identity performs.
Default deny: Start from no access and grant only observed needs.
Scope by resource and time: Restrict to specific resources and short-lived sessions.
Review and prune: Remove unused grants on a regular schedule.
The service can read invoice objects under one prefix and nothing else. No list, write or delete, and no other buckets.
Least-privilege database role in PostgreSQL
-- Role used by the orders service, no superuser, no DDL
CREATE ROLE orders_app LOGIN PASSWORD 'from-secrets-manager';
REVOKE ALL ON SCHEMA public FROM PUBLIC;
GRANT USAGE ON SCHEMA orders TO orders_app;
GRANT SELECT, INSERT, UPDATE ON orders.orders, orders.order_items TO orders_app;
-- Separate read-only role for analytics
CREATE ROLE analytics_ro LOGIN PASSWORD 'from-secrets-manager';
GRANT USAGE ON SCHEMA orders TO analytics_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA orders TO analytics_ro;
The application can modify only its own tables and cannot delete rows or alter schema. Analytics gets a separate read-only role.
Kubernetes pod running with minimal privileges
apiVersion: v1
kind: Pod
metadata:
name: api
spec:
automountServiceAccountToken: false # no K8s API access unless needed
containers:
- name: api
image: registry.example.com/api:1.4.2
securityContext:
runAsNonRoot: true
runAsUser: 10001
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
The container cannot run as root, gain new privileges, write to its filesystem or talk to the Kubernetes API. An RCE in this pod has very little to work with.
Key points
Least privilege covers actions, resources, time and context, not just admin vs non-admin.
Non-human identities (service accounts, CI tokens, API keys) are usually the most over-privileged.
Prefer short-lived, scoped credentials over long-lived master keys.
Privilege creep is the default; fight it with group-based grants and periodic reviews.
It directly limits blast radius and lateral movement after a compromise.
Common follow-up questions
How would you find and remove unused permissions in an existing AWS account?
What is just-in-time access and how does break-glass access work?
How does least privilege relate to separation of duties?
How would you scope a third-party integration's API key?
Interview tips
Give a concrete example at more than one layer: a DB role, an IAM policy and a container setting.
Mention blast radius and lateral movement, which shows you understand why it matters, not just the definition.
Acknowledge the trade-off: too tight breaks things, so teams start from observed usage and iterate.
Concepts covered
Least Privilege, Access Control, IAM Policies, RBAC, Blast Radius, Just-in-Time Access
More Web Security (OWASP, JWT, XSS, CSRF) questions