Data structureintro
Access control list
Also called ACL.
Stores the access matrix by column, so that each object keeps the list of subjects that may use it and the rights of each.
- Time
- O(s) worst
- Space
- Θ(n + o) extra
- Where
- n = the number of nonempty cells of the access matrix; o = the number of objects; r = the number of rights; s = the number of subjects
- Model
- Word RAM
- Properties
- not concurrentnot externalnot persistent
- Evidence
- Proof sketchCode in 1 languages
An access control list (ACL) stores the access control matrix by column: each object keeps a list of entries , one for each subject that has some right on it, with the set of rights of . To decide a request "may do to ?", the system scans the list of for the entry of and tests . Lampson (1971) named the structure, Multics used it for every segment, and it is the mechanism of almost every file system and many cloud services today. It makes "who can use this object?" cheap, and makes "what can this subject use?" and "remove this user everywhere" cost a scan of every list; the capability list has the opposite trade-off.
In plain words
Think of a guest list at the door of each room. The list names the people who may come in and what each may do inside: look, change things, or invite others. To check a visitor, the guard at the door reads the list of that room only. The guard does not care what other rooms the visitor can enter.
This makes it easy to answer "who can get into this room?": read one list. It also makes it easy for the room's owner to add or strike a name. It is hard to answer "which rooms can this person enter?", because the answer is spread over the lists of all rooms. To ban a person from the whole building, someone must visit every door and strike the name from each list.
The abstract type
An ACL system stores a protection state with subjects , objects and the matrix over a finite set of rights. It supports these operations:
- CHECK returns true when .
- GRANT sets .
- REVOKE sets .
- REVOKE-SUBJECT sets for every object .
- ENTRIES returns column : the pairs with .
- CREATE-OBJECT and DELETE-OBJECT add or remove a column.
Who may call GRANT and REVOKE is not part of the structure. It is the policy: in discretionary access control it is the owner of the object, in mandatory access control it is only the system administrator, and a reference monitor makes every call go through the check.
Representation
For each object the structure keeps a list of entries , where is a subject and is a set of rights stored as a bit mask of bits. A hash table or an array maps each object to its list. The list is an array or a linked list; for this page it is a plain list that is scanned.
Invariant (A). For each object : (A1) no two entries of have the same subject, and (A2) no entry has an empty set of rights.
Abstraction. The state stands for the matrix with if , and if has no entry for . By (A1) this is a well-defined function. By (A2) the entries of are exactly the nonempty cells of column , so the lists use space linear in the number of nonempty cells, plus one header for each object.
Operations
CHECK(acl, s, o, r)- 1
for each entry (s', R') in acl[o] do - 2
if s' = s then return r ∈ R' - 3
return false ▷ no entry: the cell is empty GRANT(acl, s, o, r)- 4
for each entry (s', R') in acl[o] do - 5
if s' = s then R' ← R' ∪ {r}; return - 6
append (s, {r}) to acl[o] ▷ only when s has no entry yet REVOKE(acl, s, o, r)- 7
for each entry (s', R') in acl[o] do - 8
if s' = s then - 9
R' ← R' \ {r} - 10
if R' = ∅ then remove the entry from acl[o] - 11
return REVOKE-SUBJECT(acl, s)- 12
for each object o do - 13
remove the entry of s from acl[o], if there is one
Check. Lines L1 and L2 look for the entry of in the list of . By (A1) there is at most one, so the first match is the only match. If there is none, the cell is empty and line L3 denies. An ACL denies by default: a subject that no list names gets nothing. The cost is the position of the entry in the list, at most steps.
Grant. Lines L4 and L5 add to the existing entry of . Line L6 appends a new entry only when there is none, which keeps (A1). The new entry holds , which is not empty, so (A2) holds. Cost: at most steps, plus for the append.
Revoke. Lines L7 to L9 remove from the entry of . Line L10 removes an entry that has become empty, which keeps (A2). If there is no entry, nothing changes. Cost: at most steps; removing from the middle of an array list costs another moves, and in a linked list.
Revoke a subject. Lines L12 and L13 visit every list. This is the cost of the column view: the rights of one subject are spread over all objects, so the operation takes time linear in , even when has rights on only a few objects.
Create and delete an object. CREATE-OBJECT adds an empty list. DELETE-OBJECT removes the list with all its entries. Both take time in the map, plus the time to free the entries.
Example
Take the matrix of the access control matrix page, with subjects alice, bob and carol, objects f1, f2 and the printer p, and rights own, r and w. Its three columns are the three lists:
| object | its list |
|---|---|
| f1 | (alice, {own, r, w}), (bob, {r}) |
| f2 | (alice, {r}), (bob, {own, r, w}), (carol, {r}) |
| p | (bob, {w}), (carol, {w}) |
Now build the list of f2 from an empty state by a sequence of operations, and then change it.
| operation | the list of f2 after it | note |
|---|---|---|
| GRANT(bob, f2, own) | (bob, {own}) | line L6, new entry |
| GRANT(bob, f2, r) | (bob, {own, r}) | line L5 |
| GRANT(bob, f2, w) | (bob, {own, r, w}) | line L5 |
| GRANT(alice, f2, r) | (bob, {own, r, w}), (alice, {r}) | line L6 |
| GRANT(carol, f2, r) | (bob, {own, r, w}), (alice, {r}), (carol, {r}) | line L6 |
| CHECK(carol, f2, w) | unchanged | line L2 finds carol and returns false |
| REVOKE(alice, f2, r) | (bob, {own, r, w}), (carol, {r}) | line L10 removes the empty entry |
| GRANT(carol, p, w) | unchanged; the list of p is (carol, {w}) | |
| REVOKE-SUBJECT(carol) | (bob, {own, r, w}) | lines L12 and L13 also empty the list of p |
The last step visits both lists, f2 and p, although each holds only one entry of carol. In a system with a million files, the same step visits a million lists.
Correctness
Each operation keeps invariant (A), and each one changes the matrix that the state stands for exactly as the abstract type says. CHECK reads the cell because (A1) makes the entry of unique; GRANT adds to that cell and never makes a second entry; REVOKE and REVOKE-SUBJECT remove rights and drop entries that become empty, so (A2) holds and no empty cell is stored. It follows that the set of lists and the matrix determine each other: the lists of a matrix are its columns without the empty cells, and the matrix of the lists is given by the abstraction. The full proof is in the correctness proof.
Proof: The access control lists store exactly the access matrixfull
Write for the state: a map from each object to a finite list of entries with a subject and . Objects with no list have an empty list. Invariant (A) says: (A1) no two entries of one list have the same subject, and (A2) no entry has .
Abstraction. For a state that holds (A1), define the matrix by if is an entry of , and if no entry of has subject . By (A1) there is at most one such entry, so is a function.
Lemma 1 (lists and matrices are in bijection). Let be the set of states that hold (A), and the set of matrices . Then is a bijection, up to the order of the entries of each list. Its inverse maps a matrix to the state whose list for holds the pairs with .
Proof. Call the second map . For a matrix , the list has one entry for each subject with a nonempty cell, so it holds (A1) and (A2), and for nonempty cells by definition and for the others, because those subjects have no entry. So . For a state that holds (A), each entry of has by (A2), so it is the cell and it appears in . Conversely each entry of comes from a nonempty cell, which comes from an entry of . So the two lists hold the same entries, and by (A1) each entry once.
Lemma 1 is the reason for (A2): without it, a list could hold and the state with this entry and the state without it would give the same matrix.
Lemma 2 (CHECK). If holds (A1), CHECK returns true exactly when .
Proof. The loop of lines L1 and L2 visits the entries of in order. If some entry has subject , it is the only one by (A1), so line L2 returns for . If none has subject , the loop ends and line L3 returns false, and does not contain .
Lemma 3 (GRANT). If holds (A), then after GRANT the state holds (A), and its matrix is with added to cell and no other cell changed.
Proof. If has an entry , line L5 replaces it with and returns. The list keeps the same subjects, so (A1) holds, and is not empty, so (A2) holds. Only cell changes, from to . If there is no such entry, the loop ends without a return and line L6 appends . No other entry of the list has subject , so (A1) holds, and , so (A2) holds. Cell changes from to . In both cases the lists of other objects are not touched.
Lemma 4 (REVOKE). If holds (A), then after REVOKE the state holds (A), and its matrix is with removed from cell and no other cell changed.
Proof. If has an entry , line L9 replaces with . If , line L10 removes the entry, and the cell becomes ; otherwise the entry stays, with . Removing an entry or changing its set does not add a subject, so (A1) holds, and in both cases no empty set is stored, so (A2) holds. If there is no entry for , the loop of lines L7 and L8 ends with no change, and the cell was .
Lemma 5 (REVOKE-SUBJECT). If holds (A), then after REVOKE-SUBJECT the state holds (A), and its matrix is with every cell of row set to and every other cell unchanged.
Proof. The loop of lines L12 and L13 visits each object once. By (A1) the list has at most one entry for , and line L13 removes it, which sets cell to . Entries of other subjects are not changed. Removing entries keeps (A1) and (A2).
Lemma 6 (objects). CREATE-OBJECT adds an empty list, which holds (A) and gives the column of all empty. DELETE-OBJECT removes the list of , so the column of becomes all empty in , and the other lists are not changed.
Proof. Immediate from the definitions of the two operations and of .
Theorem. Start from the empty state, which holds (A) and has the all-empty matrix. After any finite sequence of operations, the state holds (A), its matrix is the matrix that the same sequence of abstract operations gives, and each CHECK in the sequence returns the abstract answer .
Proof. By induction on the length of the sequence, with Lemmas 3 to 6 for the step of each changing operation and Lemma 2 for each CHECK, which changes nothing.
Termination and cost. Each loop of lines L1, L4 and L7 visits each entry of one list at most once and returns at the first match, so it runs at most rounds by (A1). The loop of line L12 visits each object once, and line L13 scans one list, so REVOKE-SUBJECT does steps in total, where is, by Lemma 1, the number of nonempty cells.
Complexity
The model is the word RAM, with a set of rights as one word of bits, so a union, a difference and a membership test take time. The map from objects to lists is a hash table, with expected time for a lookup.
| operation | time with a scanned list | time with a hash table per object |
|---|---|---|
| CHECK | worst | expected |
| GRANT | worst | expected |
| REVOKE | worst | expected |
| ENTRIES (one column) | the same | |
| REVOKE-SUBJECT | expected | |
| rights of one subject (one row) | expected | |
| space | entries | the same, times a constant |
A full matrix needs bits whatever the policy. The lists need space for the nonempty cells only, which is the reason for the column view when most subjects have no rights on most objects. Most real lists are short, so a scan is fast in practice; a long list, such as the list of a file shared with a whole company, is the case for a hash table, or for groups (see Variants).
Variants
- Groups and abbreviations. An entry names a group, and a subject gets the rights of each group it is a member of. The Unix permission bits are the shortest form: three entries, for the owner, the owning group and all others, with three bits (r, w, x) each. Bishop calls these abbreviations of ACLs. A full ACL can then be needed in addition, as in the POSIX draft ACLs of Linux, which add named users and groups and a mask entry.
- Negative entries and order. Some systems add deny entries. The decision then depends on a rule for conflicts: "deny overrides", or "the first matching entry decides" as in Windows and NFSv4 ACLs, where tools put the deny entries first. The structure is then an ordered list, and the scan of line L1 is a first-match search.
- Inheritance. A directory carries a default ACL that new files in it copy. Multics and most current file systems have a form of this.
- Propagated ACLs. The ACL is attached to the data and follows it into copies, so that the creator keeps control. Bishop describes them as PACLs; the idea is close to the decentralized label model.
- Relation tuples at scale. Zanzibar stores each entry as a tuple (object, relation, user), where the user can be a set given by another tuple. A check then follows these links, which makes the ACL a form of relationship-based access control.
- Roles. If the entries name roles instead of users, the ACL is the role to permission part of role-based access control.
When to use it
Use ACLs when objects are long-lived and named, when the owner of an object must see and change who can use it, and when the main audit question is "who can read this file?". This is the case in file systems and in most services with a sharing dialog. ACLs need the system to know who the subject is at each check, so they depend on authentication, and they give a program the rights of the user who runs it, which makes the confused deputy problem possible (see capability list). Use capability lists instead when rights must be passed between programs at run time, or when each program must hold only the rights it needs, as the principle of least privilege asks.
Pitfalls
- A second entry for the same subject. If GRANT appends at line L6 without the scan of lines L4 and L5, a subject can get two entries. Then CHECK reads the first one only, and REVOKE at line L10 removes one entry and leaves the other, so a revoked right stays. Always look for the entry first, as lines L4 and L5 do.
- Revocation that waits for the next open. Most file systems check the ACL when a file is opened, not on each read. After REVOKE, a process that opened the file earlier keeps its access through the open handle until it closes it. If revocation must be immediate, the reference monitor must check at each use, or the system must close the handles.
- A removed user whose name comes back. If REVOKE-SUBJECT is not run when a user is deleted, and a new user later gets the same identifier, the new user gets all the old entries. Run lines L12 and L13 at deletion, or never reuse identifiers.
- An entry in the wrong order. In a first-match list, a deny entry placed after an allow entry for the same subject is never reached. Keep a canonical order, or use "deny overrides" as the rule.
- Empty entries. If line L10 is left out, the list keeps entries with no rights. CHECK is still right, but ENTRIES lists subjects that have no access, and an audit of "who can use this object?" is wrong.
Implementations
The Python class follows the main block with one scanned list for each object. It adds CREATE-OBJECT, DELETE-OBJECT, the conversions to and from a matrix, and a check of invariant (A). The tests compare every operation with a plain dictionary of matrix cells on random sequences, and check the column view against the matrix on every matrix over two subjects, two objects and two rights.
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/access-control-list/. The authors are listed in prov/443DQ0.jsonl.
"""Access control lists: the access matrix stored by column (Lampson 1971).
Each object keeps a list of entries (subject, rights). The list holds at
most one entry for each subject, and no entry has an empty set of rights.
"""
from collections.abc import Hashable, Iterable, Mapping
Subject = Hashable
Obj = Hashable
Right = Hashable
Entry = tuple[Subject, frozenset[Right]]
class AccessControlList:
"""The access lists of all objects of one protection state.
check, grant and revoke scan the list of one object, so each takes
O(L) time, where L is the length of that list (L is at most the
number of subjects). revoke_subject scans every list, so it takes time
linear in the total number of entries. The space is linear in the
number of nonempty cells of the access matrix, plus one list header
for each object.
"""
def __init__(self) -> None:
self._acl: dict[Obj, list[Entry]] = {}
# The operations of the main pseudocode block.
def check(self, s: Subject, o: Obj, r: Right) -> bool:
"""Return True when the list of object o gives right r to subject s."""
for subject, rights in self._acl.get(o, []): # @line L1
if subject == s: # @line L2
return r in rights
return False # @line L3
def grant(self, s: Subject, o: Obj, r: Right) -> None:
"""Add right r for subject s to the list of object o.
The object is created with an empty list when it is new.
"""
entries = self._acl.setdefault(o, [])
for k, (subject, rights) in enumerate(entries): # @line L4
if subject == s:
entries[k] = (subject, rights | {r}) # @line L5
return
entries.append((s, frozenset([r]))) # @line L6
def revoke(self, s: Subject, o: Obj, r: Right) -> None:
"""Remove right r of subject s from the list of object o, if it is there."""
entries = self._acl.get(o, [])
for k, (subject, rights) in enumerate(entries): # @line L7
if subject == s: # @line L8
rest = rights - {r} # @line L9
if rest:
entries[k] = (subject, rest)
else:
del entries[k] # @line L10
return # @line L11
def revoke_subject(self, s: Subject) -> None:
"""Remove every entry of subject s from every list."""
for o in self._acl: # @line L12
self._acl[o] = [(subject, rights) for subject, rights in self._acl[o] if subject != s] # @line L13
# Other operations.
def create_object(self, o: Obj) -> None:
"""Make object o known with an empty list. Nothing happens if it exists."""
self._acl.setdefault(o, [])
def delete_object(self, o: Obj) -> None:
"""Remove object o and its list."""
self._acl.pop(o, None)
def rights(self, s: Subject, o: Obj) -> frozenset[Right]:
"""Return the cell A[s, o] of the access matrix."""
for subject, rights in self._acl.get(o, []):
if subject == s:
return rights
return frozenset()
def entries(self, o: Obj) -> list[Entry]:
"""Return a copy of the list of object o (one column of the matrix)."""
return list(self._acl.get(o, []))
def objects(self) -> list[Obj]:
"""Return the objects in the order in which they were created."""
return list(self._acl)
def to_matrix(self) -> dict[tuple[Subject, Obj], frozenset[Right]]:
"""Return the nonempty cells of the access matrix as a dict."""
return {(s, o): rights for o, entries in self._acl.items() for s, rights in entries}
@classmethod
def from_matrix(
cls, matrix: Mapping[tuple[Subject, Obj], Iterable[Right]], objects: Iterable[Obj] = ()
) -> "AccessControlList":
"""Build the lists from the cells of a matrix. Empty cells give no entry."""
acl = cls()
for o in objects:
acl.create_object(o)
for (s, o), rights in matrix.items():
acl.create_object(o)
frozen = frozenset(rights)
if frozen:
acl._acl[o].append((s, frozen))
return acl
def check_invariant(self) -> None:
"""Raise AssertionError unless each list has distinct subjects and no empty entry."""
for entries in self._acl.values():
subjects = [subject for subject, _ in entries]
assert len(subjects) == len(set(subjects)), "two entries for one subject"
assert all(rights for _, rights in entries), "an entry with no rights"
test_access_control_list.py 128 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/access-control-list/. The authors are listed in prov/443DQ0.jsonl.
import itertools
import random
from access_control_list import AccessControlList
SUBJECTS = ["alice", "bob", "carol"]
OBJECTS = ["f1", "f2", "p"]
RIGHTS = ["own", "r", "w"]
# The access matrix of the page example.
MATRIX = {
("alice", "f1"): {"own", "r", "w"},
("alice", "f2"): {"r"},
("bob", "f1"): {"r"},
("bob", "f2"): {"own", "r", "w"},
("bob", "p"): {"w"},
("carol", "f2"): {"r"},
("carol", "p"): {"w"},
}
def test_page_example_columns() -> None:
acl = AccessControlList.from_matrix(MATRIX, OBJECTS)
acl.check_invariant()
assert acl.entries("f1") == [("alice", frozenset({"own", "r", "w"})), ("bob", frozenset({"r"}))]
assert [s for s, _ in acl.entries("f2")] == ["alice", "bob", "carol"]
assert acl.entries("p") == [("bob", frozenset({"w"})), ("carol", frozenset({"w"}))]
assert acl.check("bob", "f2", "w")
assert not acl.check("carol", "f2", "w")
assert not acl.check("alice", "p", "w")
def test_page_example_sequence() -> None:
acl = AccessControlList()
acl.grant("bob", "f2", "own")
acl.grant("bob", "f2", "r")
acl.grant("bob", "f2", "w")
acl.grant("alice", "f2", "r")
acl.grant("carol", "f2", "r")
assert acl.entries("f2") == [
("bob", frozenset({"own", "r", "w"})),
("alice", frozenset({"r"})),
("carol", frozenset({"r"})),
]
assert not acl.check("carol", "f2", "w")
acl.revoke("alice", "f2", "r")
assert acl.entries("f2") == [("bob", frozenset({"own", "r", "w"})), ("carol", frozenset({"r"}))]
acl.grant("carol", "p", "w")
acl.revoke_subject("carol")
assert acl.entries("f2") == [("bob", frozenset({"own", "r", "w"}))]
assert acl.entries("p") == []
assert acl.objects() == ["f2", "p"]
acl.check_invariant()
def test_edge_cases() -> None:
acl = AccessControlList()
assert not acl.check("alice", "f1", "r")
acl.revoke("alice", "f1", "r")
acl.revoke_subject("alice")
assert acl.to_matrix() == {}
acl.create_object("f1")
assert acl.entries("f1") == []
acl.grant("alice", "f1", "r")
acl.grant("alice", "f1", "r")
assert acl.entries("f1") == [("alice", frozenset({"r"}))]
acl.revoke("alice", "f1", "w")
assert acl.rights("alice", "f1") == frozenset({"r"})
acl.revoke("alice", "f1", "r")
assert acl.entries("f1") == []
acl.delete_object("f1")
assert acl.objects() == []
acl.check_invariant()
def test_round_trip_all_small_matrices() -> None:
# Every matrix over 2 subjects, 2 objects and 2 rights: 4 cells, 4 values each.
cells = list(itertools.product(SUBJECTS[:2], OBJECTS[:2]))
values = [frozenset(c) for k in range(3) for c in itertools.combinations(RIGHTS[:2], k)]
for choice in itertools.product(values, repeat=len(cells)):
matrix = dict(zip(cells, choice))
acl = AccessControlList.from_matrix(matrix, OBJECTS[:2])
acl.check_invariant()
assert acl.to_matrix() == {c: v for c, v in matrix.items() if v}
for (s, o), v in matrix.items():
for r in RIGHTS[:2]:
assert acl.check(s, o, r) == (r in v)
def test_random_operations_against_matrix() -> None:
rng = random.Random(20251121)
for _ in range(600):
acl = AccessControlList()
model: dict[tuple[str, str], set[str]] = {}
live: set[str] = set()
for _ in range(rng.randint(0, 40)):
op = rng.random()
s, o, r = rng.choice(SUBJECTS), rng.choice(OBJECTS), rng.choice(RIGHTS)
if op < 0.4:
acl.grant(s, o, r)
model.setdefault((s, o), set()).add(r)
live.add(o)
elif op < 0.7:
acl.revoke(s, o, r)
model.get((s, o), set()).discard(r)
elif op < 0.8:
acl.revoke_subject(s)
for key in list(model):
if key[0] == s:
model[key] = set()
elif op < 0.85:
acl.delete_object(o)
live.discard(o)
for key in list(model):
if key[1] == o:
model[key] = set()
else:
assert acl.check(s, o, r) == (r in model.get((s, o), set()))
acl.check_invariant()
expected = {k: frozenset(v) for k, v in model.items() if v}
assert acl.to_matrix() == expected
assert set(acl.objects()) == live
for s, o, r in itertools.product(SUBJECTS, OBJECTS, RIGHTS):
assert acl.check(s, o, r) == (r in model.get((s, o), set()))
assert acl.rights(s, o) == frozenset(model.get((s, o), set()))
History
Lampson's 1971 paper on protection described the access matrix and named its two storage forms, access lists for the columns and capability lists for the rows. Multics, designed from 1965, put an access control list on every segment, and Saltzer (1974) described the design and its weaknesses. Saltzer and Schroeder (1975) compared the list-oriented and the ticket-oriented forms. Unix (1970s) kept only the three abbreviated entries for owner, group and others. Large services now keep ACLs as relation tuples, as in Zanzibar (2019).
References
- Butler W. Lampson, Protection, Proceedings of the 5th Princeton Conference on Information Sciences and Systems, 1971, reprinted in ACM SIGOPS Operating Systems Review 8(1), 1974, pages 18 to 24 of the reprint (the access matrix, and the access list of an object as its column)
- Jerome H. Saltzer, Protection and the control of information sharing in Multics, Communications of the ACM 17(7), 1974, pages 388 to 402 (the access control lists of Multics segments and directories, and the known weaknesses of the design)
- Jerome H. Saltzer and Michael D. Schroeder, The protection of information in computer systems, Proceedings of the IEEE 63(9), 1975, pages 1278 to 1308, Section II (the list-oriented and ticket-oriented implementations, access control lists and their revocation)
- Matt Bishop, Computer Security: Art and Science, second edition, Addison-Wesley, 2018, ISBN 9780321712332, Chapter 16, Section 16.1 (access control lists, their abbreviations, creation and maintenance, and revocation)
- Ruoming Pang and others, Zanzibar, Google's consistent, global authorization system, USENIX ATC 2019, pages 33 to 46 (access control lists stored as relation tuples, and checks at scale)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 443DQ0 Edit this page History Report an error Markdown