CSE Roadmap

Core tier · about 3 hours · 6 parts

Part 2 of 6 · 2 min read

Least privilege

Think of a building where every key opens every door. The cleaner, the accountant and the guard all carry the master key, because each of them needs one door. A lost key now opens the safe. The analogy stops in one place: a building can cut new keys, but a program that holds the power of root cannot choose to forget it unless the system gives it a way.

In plain words: The principle of least privilege says that each program, user or part of a system should hold only the rights it needs for its task, and only for as long as it needs them. Classic Unix has two levels: ordinary users, and user 0, which passes every check (page 2). A web server needs one privileged act, binding to a port below 1024, and in the old design the only way to get it was to run as root. A flaw in that server then gives an attacker the whole machine. Cutting the power of root into pieces removes that choice.

A worked example. Count the damage. A web server that runs as root can read every file, load kernel code, change the clock, kill any process and change any file's owner: about 40 powers (section 2 counts them). The same server with only the bind power has 1 of 40. If an attacker takes it over, 39 of 40 acts are still refused.

The key lines. Least privilege does not stop a flaw. It limits what the flaw is worth.

Principle of least privilege

The principle of least privilege says that a subject (a user, process or module) should hold only the rights that its task needs, and only while the task needs them. It limits the damage when the subject is misused or taken over.

Example: a web server that needs to bind port 80 is given that one right, not the full power of user 0.

Check yourself: 1. State the principle of least privilege in one sentence. 2. Why does a root-only design for port 80 break it? 3. What does least privilege limit when a flaw exists?