Home / Learn Secure SQL / The Principle of Least Privilege
The Principle of Least Privilege
Give every account only what it needs, nothing more.
What's actually going on
Definition
Least privilege means every database account (and every person) should be granted only the specific permissions required for its job, and no more — not out of distrust, but because it limits how far any single mistake or compromise can reach.
Why you need this
If a web application's database account can only SELECT/INSERT/UPDATE on a few specific tables, then even a serious bug in the application cannot drop the whole database or read unrelated tables.
How it works
For every database account, list exactly which operations on exactly which tables it needs, grant precisely that, and review the list periodically as the application changes.
Where you'll see this
- Web application code review
- Backend development
- Database administration
The code block alongside this example shows the exact GRANT statement for PostgreSQL/MySQL.
CREATE ROLE webapp LOGIN PASSWORD '...';
GRANT SELECT, INSERT, UPDATE ON orders, order_items TO webapp;
-- Notably NOT granted: DELETE, DROP, CREATE, or access to other tablesTest what you just read
1. Least privilege mainly limits...
Blast radius, not performance.