Skip to main content

Module matcher

Module matcher 

Source
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:

  1. an argument-level rule beats a tool-level rule;
  2. at the same level, the longest LITERAL PREFIX wins;
  3. 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§

RuleMatch
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 /, fold name/.., and strip a trailing /.
subjects_for
The argument(s) a tool call is discriminated by.
subjects_for_in_root
subjects_for with the run’s working root supplied.