Part 5 of 7 · 3 min read
ACLs and capabilities
Think of two ways to control entry to a concert. One is a guest list at the door: the guard looks for your name. The other is a ticket in your hand: the guard looks at the ticket. A guest list is easy to change, and a ticket can be handed on. The analogy stops in one place: a paper ticket can be copied, while a capability in an OS is protected by the kernel.
In plain words: With an ACL, the object holds the list. When a subject asks for access, the system looks up the subject in the object's list. It is easy to answer "who can use this file?" and easy to revoke: delete the entry. It is slow to answer "what can this user reach?", since all objects must be scanned. With capabilities, the subject holds an unforgeable token that names an object and rights. Possession of the token is the permission, and the check is quick. It is easy to answer "what can this process do?" and easy to pass a right on. It is hard to revoke: the system must find all copies of the token, or use an indirection.
A worked example. Alice's right to the report must be removed. With ACLs, the system edits one list: the list of report, a single change, whatever the number of users. With capabilities, copies may sit in alice's list and in any process that she passed one to. The system must search them all, or the capability must have named a table entry that can be cleared. On Unix the file descriptor is a capability: it was checked at open and stays valid until it is closed, even if the file's permissions change afterwards. A process that opened a file before its permission was removed can still read it through the open descriptor.
The key lines. Unix files use ACL-like permission bits, and open descriptors use the capability idea. Many modern systems mix the two. Capabilities also protect against the confused deputy problem, in which a program with power acts on behalf of a caller who has less. If the caller must hand over a capability, the program uses only what the caller could use.
Capability
A capability is an unforgeable token, held by a process and protected by the OS, that names an object and the rights that its holder has on it. The check is the possession of the token. An open file descriptor on Unix is a capability for the file.
Example: a process that has opened /etc/hostname for reading holds a descriptor that lets it read the file even if the file's mode is changed later.
Common mistake
Changing a file's permissions does not close descriptors that are already open. To stop a running program from reading a file, the program must be stopped or must close the file.
Check yourself: 1. Which is easier to revoke, an ACL entry or a capability, and why? 2. Which question is easy to answer from a capability list? 3. Why is an open file descriptor a capability?