Algorithm Search⌘K

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
Properties
not concurrentnot externalnot persistent

An access control list (ACL) stores the access control matrix by column: each object keeps a list of entries (s,T)(s, T), one for each subject ss that has some right on it, with TT the set of rights of ss. To decide a request "may ss do rr to oo?", the system scans the list of oo for the entry of ss and tests r∈Tr \in T. 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 (S,O,A)(S, O, A) with subjects SS, objects OO and the matrix A:S×O→2RA : S \times O \to 2^R over a finite set RR of rights. It supports these operations:

  • CHECK(s,o,r)(s, o, r) returns true when r∈A[s,o]r \in A[s, o].
  • GRANT(s,o,r)(s, o, r) sets A[s,o]←A[s,o]∪{r}A[s, o] \leftarrow A[s, o] \cup \{r\}.
  • REVOKE(s,o,r)(s, o, r) sets A[s,o]←A[s,o]∖{r}A[s, o] \leftarrow A[s, o] \setminus \{r\}.
  • REVOKE-SUBJECT(s)(s) sets A[s,o]←∅A[s, o] \leftarrow \emptyset for every object oo.
  • ENTRIES(o)(o) returns column oo: the pairs (s,A[s,o])(s, A[s, o]) with A[s,o]≠∅A[s, o] \ne \emptyset.
  • CREATE-OBJECT(o)(o) and DELETE-OBJECT(o)(o) 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 oo the structure keeps a list acl[o]\mathit{acl}[o] of entries (s,T)(s, T), where ss is a subject and T⊆RT \subseteq R is a set of rights stored as a bit mask of rr 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 oo: (A1) no two entries of acl[o]\mathit{acl}[o] have the same subject, and (A2) no entry has an empty set of rights.

Abstraction. The state stands for the matrix MM with M[s,o]=TM[s, o] = T if (s,T)∈acl[o](s, T) \in \mathit{acl}[o], and M[s,o]=∅M[s, o] = \emptyset if acl[o]\mathit{acl}[o] has no entry for ss. By (A1) this is a well-defined function. By (A2) the entries of acl[o]\mathit{acl}[o] are exactly the nonempty cells of column oo, so the lists use space linear in the number nn of nonempty cells, plus one header for each object.

Operations

  1. CHECK(acl, s, o, r)
  2. 1for each entry (s', R') in acl[o] do
  3. 2if s' = s then return r ∈ R'
  4. 3return false ▷ no entry: the cell is empty
  5. GRANT(acl, s, o, r)
  6. 4for each entry (s', R') in acl[o] do
  7. 5if s' = s then R' ← R' ∪ {r}; return
  8. 6append (s, {r}) to acl[o] ▷ only when s has no entry yet
  9. REVOKE(acl, s, o, r)
  10. 7for each entry (s', R') in acl[o] do
  11. 8if s' = s then
  12. 9R' ← R' \ {r}
  13. 10if R' = ∅ then remove the entry from acl[o]
  14. 11return
  15. REVOKE-SUBJECT(acl, s)
  16. 12for each object o do
  17. 13remove the entry of s from acl[o], if there is one

Check. Lines L1 and L2 look for the entry of ss in the list of oo. 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 ss steps.

Grant. Lines L4 and L5 add rr to the existing entry of ss. Line L6 appends a new entry only when there is none, which keeps (A1). The new entry holds {r}\{r\}, which is not empty, so (A2) holds. Cost: at most ss steps, plus O(1)O(1) for the append.

Revoke. Lines L7 to L9 remove rr from the entry of ss. Line L10 removes an entry that has become empty, which keeps (A2). If there is no entry, nothing changes. Cost: at most ss steps; removing from the middle of an array list costs another O(s)O(s) moves, and O(1)O(1) 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 o+no + n, even when ss 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 O(1)O(1) 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 MM that the state stands for exactly as the abstract type says. CHECK reads the cell M[s,o]M[s, o] because (A1) makes the entry of ss unique; GRANT adds rr 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 acl\mathit{acl} for the state: a map from each object oo to a finite list acl[o]\mathit{acl}[o] of entries (s,T)(s, T) with ss a subject and T⊆RT \subseteq R. 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 T=∅T = \emptyset.

Abstraction. For a state that holds (A1), define the matrix M(acl)M(\mathit{acl}) by M(acl)[s,o]=TM(\mathit{acl})[s, o] = T if (s,T)(s, T) is an entry of acl[o]\mathit{acl}[o], and M(acl)[s,o]=∅M(\mathit{acl})[s, o] = \emptyset if no entry of acl[o]\mathit{acl}[o] has subject ss. By (A1) there is at most one such entry, so M(acl)M(\mathit{acl}) is a function.

Lemma 1 (lists and matrices are in bijection). Let L\mathcal{L} be the set of states that hold (A), and M\mathcal{M} the set of matrices S×O→2RS \times O \to 2^R. Then M:L→MM : \mathcal{L} \to \mathcal{M} is a bijection, up to the order of the entries of each list. Its inverse maps a matrix AA to the state whose list for oo holds the pairs (s,A[s,o])(s, A[s, o]) with A[s,o]≠∅A[s, o] \ne \emptyset.

Proof. Call the second map LL. For a matrix AA, the list L(A)[o]L(A)[o] has one entry for each subject ss with a nonempty cell, so it holds (A1) and (A2), and M(L(A))[s,o]=A[s,o]M(L(A))[s, o] = A[s, o] for nonempty cells by definition and ∅\emptyset for the others, because those subjects have no entry. So M(L(A))=AM(L(A)) = A. For a state acl\mathit{acl} that holds (A), each entry (s,T)(s, T) of acl[o]\mathit{acl}[o] has T≠∅T \ne \emptyset by (A2), so it is the cell M(acl)[s,o]M(\mathit{acl})[s, o] and it appears in L(M(acl))[o]L(M(\mathit{acl}))[o]. Conversely each entry of L(M(acl))[o]L(M(\mathit{acl}))[o] comes from a nonempty cell, which comes from an entry of acl[o]\mathit{acl}[o]. So the two lists hold the same entries, and by (A1) each entry once. □\square

Lemma 1 is the reason for (A2): without it, a list could hold (s,∅)(s, \emptyset) and the state with this entry and the state without it would give the same matrix.

Lemma 2 (CHECK). If acl\mathit{acl} holds (A1), CHECK(acl,s,o,r)(\mathit{acl}, s, o, r) returns true exactly when r∈M(acl)[s,o]r \in M(\mathit{acl})[s, o].

Proof. The loop of lines L1 and L2 visits the entries of acl[o]\mathit{acl}[o] in order. If some entry has subject ss, it is the only one by (A1), so line L2 returns r∈Tr \in T for T=M(acl)[s,o]T = M(\mathit{acl})[s, o]. If none has subject ss, the loop ends and line L3 returns false, and M(acl)[s,o]=∅M(\mathit{acl})[s, o] = \emptyset does not contain rr. □\square

Lemma 3 (GRANT). If acl\mathit{acl} holds (A), then after GRANT(acl,s,o,r)(\mathit{acl}, s, o, r) the state holds (A), and its matrix is M(acl)M(\mathit{acl}) with rr added to cell [s,o][s, o] and no other cell changed.

Proof. If acl[o]\mathit{acl}[o] has an entry (s,T)(s, T), line L5 replaces it with (s,T∪{r})(s, T \cup \{r\}) and returns. The list keeps the same subjects, so (A1) holds, and T∪{r}T \cup \{r\} is not empty, so (A2) holds. Only cell [s,o][s, o] changes, from TT to T∪{r}T \cup \{r\}. If there is no such entry, the loop ends without a return and line L6 appends (s,{r})(s, \{r\}). No other entry of the list has subject ss, so (A1) holds, and {r}≠∅\{r\} \ne \emptyset, so (A2) holds. Cell [s,o][s, o] changes from ∅\emptyset to {r}=∅∪{r}\{r\} = \emptyset \cup \{r\}. In both cases the lists of other objects are not touched. □\square

Lemma 4 (REVOKE). If acl\mathit{acl} holds (A), then after REVOKE(acl,s,o,r)(\mathit{acl}, s, o, r) the state holds (A), and its matrix is M(acl)M(\mathit{acl}) with rr removed from cell [s,o][s, o] and no other cell changed.

Proof. If acl[o]\mathit{acl}[o] has an entry (s,T)(s, T), line L9 replaces TT with T′=T∖{r}T' = T \setminus \{r\}. If T′=∅T' = \emptyset, line L10 removes the entry, and the cell becomes ∅=T′\emptyset = T'; otherwise the entry (s,T′)(s, T') stays, with T′≠∅T' \ne \emptyset. 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 ss, the loop of lines L7 and L8 ends with no change, and the cell was ∅=∅∖{r}\emptyset = \emptyset \setminus \{r\}. □\square

Lemma 5 (REVOKE-SUBJECT). If acl\mathit{acl} holds (A), then after REVOKE-SUBJECT(acl,s)(\mathit{acl}, s) the state holds (A), and its matrix is M(acl)M(\mathit{acl}) with every cell of row ss set to ∅\emptyset and every other cell unchanged.

Proof. The loop of lines L12 and L13 visits each object oo once. By (A1) the list acl[o]\mathit{acl}[o] has at most one entry for ss, and line L13 removes it, which sets cell [s,o][s, o] to ∅\emptyset. Entries of other subjects are not changed. Removing entries keeps (A1) and (A2). □\square

Lemma 6 (objects). CREATE-OBJECT(o)(o) adds an empty list, which holds (A) and gives the column of oo all empty. DELETE-OBJECT(o)(o) removes the list of oo, so the column of oo becomes all empty in MM, and the other lists are not changed.

Proof. Immediate from the definitions of the two operations and of MM. □\square

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 M(acl)M(\mathit{acl}) is the matrix that the same sequence of abstract operations gives, and each CHECK in the sequence returns the abstract answer r∈A[s,o]r \in A[s, o].

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. □\square

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 ∣acl[o]∣≤s|\mathit{acl}[o]| \le s rounds by (A1). The loop of line L12 visits each object once, and line L13 scans one list, so REVOKE-SUBJECT does O(o+n)O(o + n) steps in total, where n=∑o∣acl[o]∣n = \sum_o |\mathit{acl}[o]| is, by Lemma 1, the number of nonempty cells. ■\blacksquare

Complexity

The model is the word RAM, with a set of rights as one word of rr bits, so a union, a difference and a membership test take O(1)O(1) time. The map from objects to lists is a hash table, with O(1)O(1) expected time for a lookup.

operation time with a scanned list time with a hash table per object
CHECK O(s)O(s) worst O(1)O(1) expected
GRANT O(s)O(s) worst O(1)O(1) expected
REVOKE O(s)O(s) worst O(1)O(1) expected
ENTRIES (one column) O(length of the list)O(\text{length of the list}) the same
REVOKE-SUBJECT O(o+n)O(o + n) O(o)O(o) expected
rights of one subject (one row) O(o+n)O(o + n) O(o)O(o) expected
space Θ(n+o)\Theta(n + o) entries the same, times a constant

A full matrix needs s⋅o⋅rs \cdot o \cdot r 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.

access_control_list.pyI0RawGitHub
# 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

  1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/443DQ0/text.yaml