Algorithm Search⌘K

Modelintro

Role-based access control

Also called RBAC, NIST RBAC model.

Assigns permissions to roles and roles to users, with role hierarchies and constraints, so that access follows job functions.

Role-based access control (RBAC) puts a layer of roles between users and permissions: an administrator assigns permissions to roles, such as "teller" or "auditor", and assigns users to roles, and a user gets the permissions of its roles. A senior role in a hierarchy inherits the permissions of its juniors, and constraints such as separation of duty forbid some combinations of roles. Sandhu, Coyne, Feinstein and Youman (1996) gave the family of models RBAC0 to RBAC3, and Ferraiolo and others (2001) gave the NIST model, which became the standard ANSI INCITS 359-2004. Composing the user assignment, the hierarchy and the permission assignment gives an access control matrix of users and permissions. RBAC stores that matrix in a factored form that follows the structure of an organization: a new employee needs one role, not a hundred cells.

The machine

State. An RBAC state has:

  • sets UU of users, Roles\mathit{Roles} of roles, and PP of permissions, where a permission is a pair of an operation and an object, for example (write, account);
  • the user assignment UA⊆U×RolesUA \subseteq U \times \mathit{Roles} and the permission assignment PA⊆P×RolesPA \subseteq P \times \mathit{Roles};
  • a role hierarchy RH⊆Roles×RolesRH \subseteq \mathit{Roles} \times \mathit{Roles}, a partial order written x≥yx \ge y ("xx is senior to yy"), stored by its immediate edges as a directed acyclic graph;
  • constraints: static separation of duty pairs (rs,n)(rs, n) with rs⊆Rolesrs \subseteq \mathit{Roles} and 2≤n≤∣rs∣2 \le n \le |rs|, and dynamic pairs of the same form;
  • sessions: each session belongs to one user and has a set of active roles.

A user uu is authorized for role yy when (u,x)∈UA(u, x) \in UA for some x≥yx \ge y. A session may activate only roles its user is authorized for. A static pair (rs,n)(rs, n) holds when no user is authorized for nn or more roles of rsrs; a dynamic pair holds when no session has nn or more roles of rsrs active.

The family. RBAC0 has users, roles, permissions, UAUA, PAPA and sessions. RBAC1 adds the hierarchy, RBAC2 adds constraints, and RBAC3 has both. The NIST model has the same parts under the names core RBAC, hierarchical RBAC, static separation of duty (SSD) and dynamic separation of duty (DSD).

Decision. A request of a session for permission pp is allowed when some active role, or a role junior to an active role, has pp:

  1. CHECK-ACCESS(sess, p)
  2. 1seen ← ∅; stack ← the active roles of sess
  3. 2while stack is not empty do
  4. 3x ← pop stack
  5. 4if x ∈ seen then continue
  6. 5add x to seen
  7. 6if (p, x) ∈ PA then return true
  8. 7push the juniors of x
  9. 8return false
  10. ADD-ACTIVE-ROLE(sess, x)
  11. 9if the user of sess is not authorized for x then return false
  12. 10if (the active roles of sess) ∪ {x} breaks a dynamic pair then return false
  13. 11add x to the active roles of sess; return true

Lines L1 to L8 are a search of the hierarchy below the active roles, as in graph reachability. Lines L9 to L11 are the only way to add an active role, so every session keeps its dynamic constraints.

Transitions. Administrative operations add and remove users, roles, permissions, edges of RHRH and pairs of UAUA and PAPA. An operation that would break a static pair is refused: adding (u,x)(u, x) to UAUA, and also adding an edge to RHRH, because a new edge can make a user authorized for more roles. Who may run these operations is a policy of its own; in the basic model only a security administrator may.

Example. A bank has the roles employee, teller, auditor, manager and customer, with teller ≥ employee, auditor ≥ employee and manager ≥ teller. The permissions are (read, handbook) for employee, (write, account) for teller, (read, log) for auditor, (approve, loan) for manager and (read, statement) for customer. There is a static pair ({teller, auditor}, 2), so nobody both handles accounts and audits them, and a dynamic pair ({teller, customer}, 2), so a teller who is also a customer of the bank does not act as both at once. Alice is a manager, bob is a teller and a customer, and carol is an auditor. The flattened relation is:

user authorized roles permissions
alice manager, teller, employee (approve, loan), (write, account), (read, handbook)
bob teller, customer, employee (write, account), (read, statement), (read, handbook)
carol auditor, employee (read, log), (read, handbook)

Assigning carol to teller is refused by the static pair. So is assigning alice to auditor, because alice is already authorized for teller through manager; and so is the edge auditor ≥ teller, because it would make carol a teller. In a session, bob can activate teller, but then not customer. Alice can open a session with only employee active; then CHECK-ACCESS for (approve, loan) is false until she activates manager. Activating only the roles a task needs is the principle of least privilege inside the model.

What it counts

The access decision. The search of lines L1 to L8 visits each role below the active roles at most once, so it takes O(a+e)O(a + e) time, where aa is the number of those roles and ee the number of hierarchy edges among them, with PAPA in a hash table. A system can instead store the transitive closure of RHRH, or the flattened relation itself, and answer in O(1)O(1) expected time, at the price of recomputing it after each administrative change.

The flattened relation. The users' permissions are the relation UA∘RH∗∘PAUA \circ RH^* \circ PA, where RH∗RH^* is the reflexive and transitive closure of the hierarchy: uu has pp when there are roles x≥yx \ge y with (u,x)∈UA(u, x) \in UA and (p,y)∈PA(p, y) \in PA. This is the access matrix with users as rows and permissions as columns. Its size can be ∣U∣⋅∣P∣|U| \cdot |P|, while the factored form has size ∣UA∣+∣PA∣+∣RH∣|UA| + |PA| + |RH|; the gain of RBAC is this difference.

Administration and analysis. The cost of checking constraints and of asking what a sequence of administrative changes can reach is the subject of the known results below.

Relation to other models

  • Access matrix. RBAC is a factored matrix. Each role is a set of permissions, and each user's row is the union of the sets of its roles. Role mining goes the other way: it looks for a small set of roles that factors a given user to permission matrix.
  • DAC and MAC. In RBAC an administrator, not the owner, decides, so it is not discretionary. Osborn, Sandhu and Munawer (2000) showed that RBAC can be configured to enforce lattice-based mandatory policies and discretionary policies, so RBAC is at least as expressive as both in this sense.
  • Separation of duty. The static and dynamic pairs are the RBAC form of separation of duty. That page also covers forms that RBAC pairs cannot state, such as constraints on the steps of one transaction.
  • ABAC. Attribute-based access control treats the role as one attribute of a user among many, and adds attributes of objects and of the environment. RBAC is the case where the rules test only the user's roles.

Known results in the model

  • Decision. CHECK-ACCESS is reachability in the hierarchy below the active roles, O(a+e)O(a + e) time, or O(1)O(1) expected with a stored closure.
  • Flattening is exact. A session with every authorized role active has exactly the permissions of the flattened relation UA∘RH∗∘PAUA \circ RH^* \circ PA. The Python code on this page checks this on 600 random states with up to 4 users, 5 roles and 12 permissions over 4 objects and 3 rights, against a closure computed by Warshall's method; it also checks that every refused assignment, edge and constraint is one that the brute force oracle refuses.
  • Separation of duty. Li, Tripunitara and Bizri (2007) showed that checking whether an RBAC state satisfies a static separation of duty policy, stated over the permissions a task needs, is coNP-complete. Checking a state against constraints on mutually exclusive roles, as in the static pairs above, is efficient, but deciding whether a set of such constraints is enough to enforce a given policy is again coNP-complete. See separation of duty and co-NP.
  • Security analysis. Li and Tripunitara (2006) studied questions such as "can user uu ever get permission pp?" under administrative changes, and found that the answer depends on which changes the model allows; for some forms the questions are efficiently decidable and for others they are hard.
  • Expressiveness. RBAC can simulate lattice-based MAC and DAC (Osborn, Sandhu and Munawer 2000).
Proof: The access check of RBAC computes the flattened relation, and the constraints stay truefull

Write JJ for the set of immediate hierarchy edges: (x,y)∈J(x, y) \in J when yy is a junior that was added to xx directly. The order x≥yx \ge y is the reflexive and transitive closure J∗J^*: there is a path of edges of JJ from xx to yy, possibly of length 0. For a set XX of roles write below(X)={y:x≥y for some x∈X}\mathrm{below}(X) = \{y : x \ge y \text{ for some } x \in X\}. A user uu is authorized for auth(u)=below({x:(u,x)∈UA})\mathrm{auth}(u) = \mathrm{below}(\{x : (u, x) \in UA\}).

The invariant (R) of a state is:

  • (R1) JJ has no cycle, so ≥\ge is a partial order.
  • (R2) For each user uu and each static pair (rs,n)(rs, n): ∣auth(u)∩rs∣<n|\mathrm{auth}(u) \cap rs| < n.
  • (R3) For each session with user uu and active roles XX: X⊆auth(u)X \subseteq \mathrm{auth}(u), and ∣X∩rs∣<n|X \cap rs| < n for each dynamic pair (rs,n)(rs, n).

Lemma 1 (CHECK-ACCESS). CHECK-ACCESS(sess,p)(\mathit{sess}, p) returns true exactly when there is a role y∈below(X)y \in \mathrm{below}(X) with (p,y)∈PA(p, y) \in PA, where XX is the set of active roles of the session. It ends after at most ∣below(X)∣|\mathrm{below}(X)| rounds that pass line L5.

Proof. Every role pushed is in below(X)\mathrm{below}(X): line L1 pushes the roles of XX, and line L7 pushes juniors of a popped role, and below(X)\mathrm{below}(X) is closed under taking juniors. Line L5 adds each role to seen once, and line L4 skips a role that is already in seen, so lines L6 and L7 run at most once for each role of below(X)\mathrm{below}(X). The pushes are at most the number of edges out of these roles plus ∣X∣|X|, so the loop ends.

If the loop returns true at line L6, the popped role xx is in below(X)\mathrm{below}(X) and has pp. Conversely, suppose some y∈below(X)y \in \mathrm{below}(X) has (p,y)∈PA(p, y) \in PA, and assume the loop returns false. Take a path x0∈X,x1,…,xk=yx_0 \in X, x_1, \ldots, x_k = y of edges of JJ. Then x0x_0 is pushed at line L1, and if xix_i is popped and added to seen, line L6 does not return for it (the loop returns false at the end), and line L7 pushes xi+1x_{i+1}. A pushed role is popped before the stack is empty, and either it is added to seen then, or it was added earlier. By induction every xix_i is added to seen, including yy, and at that time line L6 returns true, which is a contradiction. □\square

Lemma 2 (ADD-ACTIVE-ROLE keeps (R3)). Line L9 refuses a role that is not in auth(u)\mathrm{auth}(u), and line L10 refuses a role that would break a dynamic pair. Line L11 adds the role only when both tests pass, so after it X∪{x}⊆auth(u)X \cup \{x\} \subseteq \mathrm{auth}(u) and every dynamic pair holds. Dropping an active role makes XX smaller, which keeps (R3). □\square

Lemma 3 (administrative changes keep (R)).

  • ADD-INHERITANCE(x,y)(x, y) refuses the edge when x∈below({y})x \in \mathrm{below}(\{y\}), which is exactly the case where the edge would close a cycle, so (R1) holds. It then adds the edge, computes auth(u)\mathrm{auth}(u) for every user, and removes the edge again if a static pair fails, so (R2) holds after it. A new edge only makes auth\mathrm{auth} larger, so the active roles of a session stay authorized and (R3) holds.
  • ASSIGN-USER(u,x)(u, x) computes the new auth(u)\mathrm{auth}(u) and refuses if a static pair fails. Other users are not changed, so (R2) holds; auth(u)\mathrm{auth}(u) grows, so (R3) holds.
  • DEASSIGN-USER(u,x)(u, x) makes auth(u)\mathrm{auth}(u) smaller, which keeps (R2), and then intersects the active roles of each session of uu with the new auth(u)\mathrm{auth}(u), which keeps (R3).
  • ADD-SSD and ADD-DSD refuse a pair that some user or some session already breaks, and a pair with n<2n < 2 or n>∣rs∣n > |rs|.
  • Changes of PAPA do not appear in (R). □\square

Theorem. In every state reached from the empty state, (R) holds. For a session of uu with active roles XX, CHECK-ACCESS(sess,p)(\mathit{sess}, p) is true exactly when p∈⋃y∈below(X)PA−1(y)p \in \bigcup_{y \in \mathrm{below}(X)} PA^{-1}(y). If X=auth(u)X = \mathrm{auth}(u), this set is the row of uu in the flattened relation UA∘RH∗∘PAUA \circ RH^* \circ PA: the permissions pp with (u,x)∈UA(u, x) \in UA, x≥yx \ge y and (p,y)∈PA(p, y) \in PA for some roles xx and yy.

Proof. The empty state holds (R). By Lemmas 2 and 3 each operation keeps it. The first claim about CHECK-ACCESS is Lemma 1. For X=auth(u)X = \mathrm{auth}(u) we have below(X)=auth(u)\mathrm{below}(X) = \mathrm{auth}(u), because auth(u)\mathrm{auth}(u) is already closed under taking juniors, and y∈auth(u)y \in \mathrm{auth}(u) means x≥yx \ge y for some xx with (u,x)∈UA(u, x) \in UA, which is the definition of the composed relation. Such an XX can be activated role by role only if no dynamic pair forbids it; the tests of this page activate every authorized role in states with no dynamic pairs. ■\blacksquare

Code

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.

role_based_access_control.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/role-based-access-control/. The authors are listed in prov/VWXVF2.jsonl.

"""Role-based access control with a role hierarchy and separation of duty.

The state follows the NIST model (Ferraiolo et al. 2001): users, roles,
permissions, the user assignment UA, the permission assignment PA, a role
hierarchy RH given by its immediate senior-to-junior edges, static and
dynamic separation of duty constraints, and sessions with active roles.

A senior role inherits every permission of its juniors. A user is
authorized for the roles assigned to it and all their juniors. A session
may activate only authorized roles. A static constraint (rs, n) says that
no user is authorized for n or more roles of rs; a dynamic constraint
(rs, n) says the same for the active roles of one session.
"""

from collections.abc import Hashable, Iterable

User = Hashable
Role = Hashable
Perm = Hashable
Session = Hashable


class RBAC:
    """One RBAC state.

    check_access takes O(a + e) time in the worst case, where a is the number
    of roles below the active roles and e the number of hierarchy edges among
    them; permission tests are hash lookups. The changes that can break a
    static constraint recompute the authorized roles of the users concerned.
    """

    def __init__(self) -> None:
        self._roles: set[Role] = set()
        self._ua: dict[User, set[Role]] = {}
        self._pa: dict[Role, set[Perm]] = {}
        self._juniors: dict[Role, set[Role]] = {}
        self._ssd: list[tuple[frozenset[Role], int]] = []
        self._dsd: list[tuple[frozenset[Role], int]] = []
        self._sessions: dict[Session, tuple[User, set[Role]]] = {}

    # Roles, assignments and the hierarchy.

    def add_role(self, role: Role) -> None:
        self._roles.add(role)
        self._pa.setdefault(role, set())
        self._juniors.setdefault(role, set())

    def below(self, roles: Iterable[Role]) -> set[Role]:
        """Return the given roles and every role junior to one of them."""
        seen: set[Role] = set()
        stack = list(roles)
        while stack:
            x = stack.pop()
            if x not in seen:
                seen.add(x)
                stack.extend(self._juniors.get(x, ()))
        return seen

    def authorized_roles(self, u: User) -> set[Role]:
        return self.below(self._ua.get(u, ()))

    def _ssd_ok(self, roles: set[Role]) -> bool:
        return all(len(roles & rs) < n for rs, n in self._ssd)

    def _dsd_ok(self, roles: set[Role]) -> bool:
        return all(len(roles & rs) < n for rs, n in self._dsd)

    def add_inheritance(self, senior: Role, junior: Role) -> bool:
        """Make senior inherit junior. Refuse a cycle or a broken static constraint."""
        if senior not in self._roles or junior not in self._roles:
            return False
        if senior in self.below([junior]):
            return False
        self._juniors[senior].add(junior)
        if all(self._ssd_ok(self.authorized_roles(u)) for u in self._ua):
            return True
        self._juniors[senior].discard(junior)
        return False

    def assign_user(self, u: User, role: Role) -> bool:
        """Add (u, role) to UA unless a static constraint forbids it."""
        if role not in self._roles:
            return False
        if not self._ssd_ok(self.below(self._ua.get(u, set()) | {role})):
            return False
        self._ua.setdefault(u, set()).add(role)
        return True

    def deassign_user(self, u: User, role: Role) -> None:
        """Remove (u, role) from UA and drop roles the user is no longer authorized for."""
        self._ua.get(u, set()).discard(role)
        allowed = self.authorized_roles(u)
        for owner, active in self._sessions.values():
            if owner == u:
                active &= allowed

    def grant_permission(self, p: Perm, role: Role) -> None:
        self._pa[role].add(p)

    def revoke_permission(self, p: Perm, role: Role) -> None:
        self._pa[role].discard(p)

    def add_ssd(self, roles: Iterable[Role], n: int) -> bool:
        """Add a static constraint unless some user already breaks it."""
        rs = frozenset(roles)
        if n < 2 or n > len(rs):
            return False
        if any(len(self.authorized_roles(u) & rs) >= n for u in self._ua):
            return False
        self._ssd.append((rs, n))
        return True

    def add_dsd(self, roles: Iterable[Role], n: int) -> bool:
        """Add a dynamic constraint unless some session already breaks it."""
        rs = frozenset(roles)
        if n < 2 or n > len(rs):
            return False
        if any(len(active & rs) >= n for _, active in self._sessions.values()):
            return False
        self._dsd.append((rs, n))
        return True

    # Sessions.

    def create_session(self, u: User, sid: Session) -> None:
        self._sessions[sid] = (u, set())

    def add_active_role(self, sid: Session, role: Role) -> bool:
        """Activate role in the session, if the user may and no dynamic constraint forbids it."""
        u, active = self._sessions[sid]
        if role not in self.authorized_roles(u):  # @line L9
            return False
        if not self._dsd_ok(active | {role}):  # @line L10
            return False
        active.add(role)  # @line L11
        return True

    def drop_active_role(self, sid: Session, role: Role) -> None:
        self._sessions[sid][1].discard(role)

    def active_roles(self, sid: Session) -> set[Role]:
        return set(self._sessions[sid][1])

    def check_access(self, sid: Session, p: Perm) -> bool:
        """Return True when an active role of the session, or a junior of one, has p."""
        seen: set[Role] = set()  # @line L1
        stack = list(self._sessions[sid][1])
        while stack:  # @line L2
            x = stack.pop()  # @line L3
            if x in seen:  # @line L4
                continue
            seen.add(x)  # @line L5
            if p in self._pa.get(x, ()):  # @line L6
                return True
            stack.extend(self._juniors.get(x, ()))  # @line L7
        return False  # @line L8

    # Views.

    def user_permissions(self, u: User) -> set[Perm]:
        """Return the flattened relation for u: the permissions of all authorized roles."""
        out: set[Perm] = set()
        for x in self.authorized_roles(u):
            out |= self._pa.get(x, set())
        return out

    def check_invariant(self) -> None:
        """Raise AssertionError unless the hierarchy is acyclic and every constraint holds."""
        for x in self._roles:
            for y in self._juniors[x]:
                assert x not in self.below([y]), "a cycle in the role hierarchy"
        for u in self._ua:
            assert self._ssd_ok(self.authorized_roles(u)), "a static constraint is broken"
        for u, active in self._sessions.values():
            assert active <= self.authorized_roles(u), "an active role the user may not have"
            assert self._dsd_ok(active), "a dynamic constraint is broken"
test_role_based_access_control.py 168 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/role-based-access-control/. The authors are listed in prov/VWXVF2.jsonl.

import itertools
import random

from role_based_access_control import RBAC

READ_HANDBOOK = ("read", "handbook")
WRITE_ACCOUNT = ("write", "account")
READ_LOG = ("read", "log")
APPROVE_LOAN = ("approve", "loan")
READ_STATEMENT = ("read", "statement")


def build_bank() -> RBAC:
    """The example of the page."""
    b = RBAC()
    for x in ["employee", "teller", "auditor", "manager", "customer"]:
        b.add_role(x)
    assert b.add_inheritance("teller", "employee")
    assert b.add_inheritance("auditor", "employee")
    assert b.add_inheritance("manager", "teller")
    b.grant_permission(READ_HANDBOOK, "employee")
    b.grant_permission(WRITE_ACCOUNT, "teller")
    b.grant_permission(READ_LOG, "auditor")
    b.grant_permission(APPROVE_LOAN, "manager")
    b.grant_permission(READ_STATEMENT, "customer")
    assert b.add_ssd({"teller", "auditor"}, 2)
    assert b.add_dsd({"teller", "customer"}, 2)
    assert b.assign_user("alice", "manager")
    assert b.assign_user("bob", "teller")
    assert b.assign_user("bob", "customer")
    assert b.assign_user("carol", "auditor")
    return b


def test_page_example() -> None:
    b = build_bank()
    b.check_invariant()
    assert b.authorized_roles("alice") == {"manager", "teller", "employee"}
    assert b.user_permissions("alice") == {APPROVE_LOAN, WRITE_ACCOUNT, READ_HANDBOOK}
    assert b.user_permissions("carol") == {READ_LOG, READ_HANDBOOK}
    # Static separation of duty.
    assert not b.assign_user("carol", "teller")
    assert not b.assign_user("alice", "auditor")  # alice is a teller through manager
    assert not b.add_inheritance("auditor", "teller")  # would make carol a teller
    # Sessions and dynamic separation of duty.
    b.create_session("bob", 1)
    assert b.add_active_role(1, "teller")
    assert not b.add_active_role(1, "customer")
    assert not b.add_active_role(1, "manager")  # not authorized
    assert b.check_access(1, WRITE_ACCOUNT)
    assert b.check_access(1, READ_HANDBOOK)  # inherited from employee
    assert not b.check_access(1, READ_STATEMENT)
    b.drop_active_role(1, "teller")
    assert b.add_active_role(1, "customer")
    assert b.check_access(1, READ_STATEMENT)
    assert not b.check_access(1, WRITE_ACCOUNT)
    b.create_session("alice", 2)
    assert b.add_active_role(2, "employee")
    assert not b.check_access(2, APPROVE_LOAN)  # least privilege: only employee is active
    assert b.add_active_role(2, "manager")
    assert b.check_access(2, APPROVE_LOAN)
    b.check_invariant()


def test_edge_cases() -> None:
    b = RBAC()
    b.add_role("a")
    b.add_role("b")
    assert not b.add_inheritance("a", "a")
    assert b.add_inheritance("a", "b")
    assert not b.add_inheritance("b", "a")
    assert not b.assign_user("u", "missing")
    assert not b.add_ssd({"a"}, 2)
    assert not b.add_ssd({"a", "b"}, 3)
    assert b.assign_user("u", "a")
    assert not b.add_ssd({"a", "b"}, 2)  # u is authorized for a and b
    b.create_session("u", "s")
    assert b.add_active_role("s", "a")
    assert b.add_active_role("s", "b")
    assert not b.add_dsd({"a", "b"}, 2)
    b.deassign_user("u", "a")
    assert b.active_roles("s") == set()
    assert not b.check_access("s", "p")
    b.check_invariant()


def closure_oracle(n: int, edges: set[tuple[int, int]]) -> list[list[bool]]:
    """The reflexive and transitive closure of the hierarchy, by Warshall's method."""
    ge = [[i == j or (i, j) in edges for j in range(n)] for i in range(n)]
    for k in range(n):
        for i in range(n):
            if ge[i][k]:
                for j in range(n):
                    if ge[k][j]:
                        ge[i][j] = True
    return ge


def test_random_states_against_flattened_relation() -> None:
    rng = random.Random(1996)
    objects = ["o1", "o2", "o3", "o4"]
    rights = ["r", "w", "x"]
    perms = list(itertools.product(rights, objects))
    users = ["u1", "u2", "u3", "u4"]
    for trial in range(600):
        n = rng.randint(1, 5)
        b = RBAC()
        for x in range(n):
            b.add_role(x)
        edges: set[tuple[int, int]] = set()
        ua: set[tuple[str, int]] = set()
        pa: set[tuple[tuple[str, str], int]] = set()
        ssd: list[tuple[frozenset[int], int]] = []
        for _ in range(rng.randint(0, 25)):
            op = rng.random()
            if op < 0.3:
                i, j = rng.randrange(n), rng.randrange(n)
                ge = closure_oracle(n, edges)
                trial_ge = closure_oracle(n, edges | {(i, j)})
                ok = not ge[j][i] and all(
                    len({x for x in range(n) if any(trial_ge[y][x] for u2, y in ua if u2 == u)} & rs) < k
                    for u in users
                    for rs, k in ssd
                )
                assert b.add_inheritance(i, j) == ok
                if ok:
                    edges.add((i, j))
            elif op < 0.55:
                u, x = rng.choice(users), rng.randrange(n)
                ge = closure_oracle(n, edges)
                auth = {z for z in range(n) if any(ge[y][z] for u2, y in ua | {(u, x)} if u2 == u)}
                ok = all(len(auth & rs) < k for rs, k in ssd)
                assert b.assign_user(u, x) == ok
                if ok:
                    ua.add((u, x))
            elif op < 0.65:
                u, x = rng.choice(users), rng.randrange(n)
                b.deassign_user(u, x)
                ua.discard((u, x))
            elif op < 0.9:
                p, x = rng.choice(perms), rng.randrange(n)
                b.grant_permission(p, x)
                pa.add((p, x))
            else:
                rs = frozenset(rng.sample(range(n), rng.randint(1, n)))
                k = rng.randint(1, 3)
                ge = closure_oracle(n, edges)
                ok = 2 <= k <= len(rs) and all(
                    len({z for z in range(n) if any(ge[y][z] for u2, y in ua if u2 == u)} & rs) < k for u in users
                )
                assert b.add_ssd(rs, k) == ok
                if ok:
                    ssd.append((rs, k))
            b.check_invariant()
        # The flattened relation UA o RH* o PA, against sessions with every authorized role.
        ge = closure_oracle(n, edges)
        for u in users:
            flat = {p for (p, x) in pa if any(ge[y][x] for u2, y in ua if u2 == u)}
            assert b.user_permissions(u) == flat
            sid = (trial, u)
            b.create_session(u, sid)
            for x in b.authorized_roles(u):
                assert b.add_active_role(sid, x)
            for p in perms:
                assert b.check_access(sid, p) == (p in flat)

References

  1. Ravi S. Sandhu, Edward J. Coyne, Hal L. Feinstein and Charles E. Youman, Role-based access control models, IEEE Computer 29(2), 1996, pages 38 to 47 (the family RBAC0 to RBAC3, role hierarchies, constraints and sessions)
  2. David F. Ferraiolo, Ravi Sandhu, Serban Gavrila, D. Richard Kuhn and Ramaswamy Chandramouli, Proposed NIST standard for role-based access control, ACM Transactions on Information and System Security 4(3), 2001, pages 224 to 274 (core RBAC, hierarchical RBAC, static and dynamic separation of duty, and the functional specification)
  3. American National Standards Institute, Information technology, role based access control, ANSI INCITS 359-2004, 2004, the reference model with its four components and the functional specification
  4. Sylvia Osborn, Ravi Sandhu and Qamar Munawer, Configuring role-based access control to enforce mandatory and discretionary access control policies, ACM Transactions on Information and System Security 3(2), 2000, pages 85 to 106 (RBAC configurations that enforce lattice-based mandatory policies and discretionary policies)
  5. Ninghui Li, Mahesh V. Tripunitara and Ziad Bizri, On mutually exclusive roles and separation-of-duty, ACM Transactions on Information and System Security 10(2), 2007, the complexity of checking separation of duty policies and constraints on mutually exclusive roles
  6. Ninghui Li and Mahesh V. Tripunitara, Security analysis in role-based access control, ACM Transactions on Information and System Security 9(4), 2006, pages 391 to 420 (security analysis questions about reachable RBAC states under administrative changes)
  7. Matt Bishop, Computer Security: Art and Science, second edition, Addison-Wesley, 2018, ISBN 9780321712332, Chapter 8, Section 8.4 (role-based access control)

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 proofH2 full proof
  • correctness: no review record reviews/VWXVF2/proof-correctness.yaml
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/VWXVF2/text.yaml