FresherTechnicalAuthentication & security
What is the principle of least privilege and how do you apply it?
Try answering first
Model answer
The principle of least privilege says every user, service and process gets only the permissions it needs for its job, and only for as long as it needs them. If an account is compromised or buggy, the damage stays small.
How to apply it in a backend:
- Database: the application connects with a role that can
SELECT,INSERTandUPDATEits own tables, notDROPor superuser. Use a separate role for migrations and a read-only role for reporting. - Cloud and services: give each service its own identity and an IAM policy listing exact actions and resources, not
*. - Users: start with no access and grant roles by job; review them regularly and remove them when people change teams.
- Tokens and keys: narrow scopes, short lifetimes, no shared all-powerful credentials.
- Runtime: run containers as non-root, drop capabilities and mount file systems read-only where possible.
- Time: prefer temporary elevated access with approval over permanent admin rights.
Takeaway: start from deny, add the minimum, and revisit it often, because permissions only tend to grow.
Key points
- Grant only the permissions a task needs
- Limit scope, resources and time
- Separate database roles for app, migration and reporting
- Review and remove permissions regularly
Likely follow-ups
- How would you audit existing IAM permissions for excess access?
- What is just-in-time access?
Common mistakes
- Giving the application the database owner account for convenience
- Granting wildcard permissions in IAM policies