Part 3 of 13 · 2 min read
No matching grant means no, and that default has to hold before anything else is checked
A system that has to be told "no" for every dangerous combination will eventually miss one; a system that starts from "no" only has to be told the specific "yes" cases.
Think of a locked door that opens only for keys cut to match it, versus an unlocked door with a sign asking people not to enter certain rooms. The first fails safe when no one thought to make a key for a particular room. The second fails open the moment someone ignores the sign.
deny by default means no matching grant results in a denial, not an allowance, and a capability is a concrete ability. Read this record, refund up to this amount, run this command -- so checking authorisation means walking the list of capabilities actually granted and only succeeding if one of them matches the resource, the action. Every numeric limit attached to it.
A worked example. A grant for orders/* with action refund and max_amount=50 authorises a refund request of exactly 50 but denies one of 50.01 -- there's no rounding or grace margin, the check is a strict less-than-or-equal. A grant with expires_at=10 authorises a read at time 9.9 but denies the identical read at time 10 -- the boundary is exclusive, and once the grant has expired there's no fallback path to approval or warning, the call is simply refused like any other unmatched request.
The key lines. From code/mini-privilege/privilege.py:
# from code/mini-privilege/privilege.py
def authorize(grants, resource, action, amount=0.0, now=0.0, used=None):
"""Deny by default. `used` maps grant index to uses so far (mutated on success)."""
used = used if used is not None else {}
for i, g in enumerate(grants):
if action not in g.actions or not fnmatch.fnmatchcase(resource, g.resource):
continue
if g.expires_at is not None and now >= g.expires_at:
continue
Read it as: the function has no final return True outside the loop. It only returns True from inside the loop, the moment one specific grant fully matches. If the loop finishes without a match, execution falls through to the explicit return False at the end. That is deny-by-default as actual control flow: there's no code path that silently allows something nobody explicitly granted.
Blast radius, capability
Blast radius is the damage one compromised component can do. A capability is a concrete ability (read this record, refund up to this amount, run this command).
Example: "refund up to 50 on order 1, expiring at t=100" is a capability stated with every one of its limits visible -- which is exactly what lets the worst-case-damage calculation in Part 1 compute a number instead of a guess: the capability's own limits bound what any attacker, however successful, could extract through it.