Expand description
Glob matching, subject extraction, and precedence for a compiled
PermissionMap (#7948).
Why: a permission map is written as an unordered YAML table, so “which rule
applies” cannot be “the first one that matches” — an operator writing
bash: { "git status*": allow, "*": ask } expects the narrow rule to win
regardless of key order. This module owns the total order that makes that
mechanical.
What: PermissionMap::evaluate (one subject), PermissionMap::evaluate_call
(every subject of one call), and subjects_for. Precedence, highest first:
- an argument-level rule beats a tool-level rule;
- at the same level, the longest LITERAL PREFIX wins;
- at equal specificity,
deny>ask>allow.
A call that matches no rule returns None, which every caller reads as
allow — the pre-#7948 behaviour.
A bash rule matches the command TEXT, never the program that ends up
running: sh -c 'rm x', /bin/rm x, and true; rm x all miss a rm *
deny. Treat a bash rule as a guard against an accident, not against an
adversary — an agent that wants to get around it can.
Test: permissions::tests::matcher_tests — the whole module.
Structs§
- Rule
Match - The rule that decided one call, and what it decided.
Functions§
- normalise_
path_ subject - Lexically normalise a path subject: drop
.segments and empty segments from repeated/, foldname/.., and strip a trailing/. - subjects_
for - The argument(s) a tool call is discriminated by.
- subjects_
for_ in_ root subjects_forwith the run’s working root supplied.