Skip to content

policy: deny rules, and deny wins globally - #55

Merged
blakebauman merged 1 commit into
mainfrom
policy/deny-rules
Aug 13, 2026
Merged

blakebauman merged 1 commit into
mainfrom
policy/deny-rules

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Phase 1 of docs/design-policy-depth.md.

The engine was allow-only, so "everything on billing except refund_*" had to be written as an enumeration of every allowed name — a list that fails open on change, because a tool added upstream is a tool nobody remembered to exclude.

deny[] is shaped exactly like allow[] and matches the same way:

{ "id": "no-refunds", "subjects": { "groups": ["support"] },
  "deny": [ { "server": "billing", "names": ["refund_*", "credit_*"] } ] }

Deny wins globally, not by document order

First-match precedence was the smaller change and the wrong one: it makes safety depend on where a rule sits, so appending a broad allow at the bottom silently widens access. A rule whose correctness depends on where it was pasted will eventually be pasted in the wrong place — the same failure tenancy refused when it declined "first matching tenant wins". Deny-wins is also what operators arrive already knowing from IAM and firewalls.

TestDenyWinsRegardlessOfOrder evaluates the same two rules in both orders and asserts the same answer, which is what "globally" has to mean to be worth anything.

The cost is confined to documents that opt in

Deny-wins means evaluation can no longer stop at the first matching allow. The engine computes at construction whether any rule carries a deny, and when none does, evaluation is the first-match short-circuit it has always been:

ns/op allocs
deny-free document, before this change 72.7 0
deny-free document, after 73.8 0
deny rule matching the caller 92.7 0

Measured against a stashed baseline, not asserted. That matters because policy is evaluated once per named invocation and once per item of every list it filters.

Two properties worth stating

Deny is not a second mechanism. It participates in the same decision, so a carved-out name is invisible in lists and uncallable, together — the enforcement pair stays one pair (TestDenyRuleKeepsTheEnforcementPair drives both halves through a real gateway).

Deny is scoped by its rule's subjects, like any other rule, rather than acting as a global kill switch. And it names itself in the audit event's ruleId: an explicit refusal owes an operator its rule in a way the default decision cannot.

Verification

make check (race) green, make conformance 40/40, policy benchmarks above. The schema needed anyOf to express "allow or deny, at least one" now that allow is no longer required.

Phases 2–4 (argument constraints, destructive gating, docs) follow separately, as the design record intends.

🤖 Generated with Claude Code

The engine was allow-only, so "everything on billing except refund_*" had to
be written as an enumeration of every allowed name — a list that fails open on
change, because a tool added upstream is a tool nobody remembered to exclude.

deny[] is shaped exactly like allow[] and matches the same way, and any match
refuses regardless of rule order. First-match precedence was the smaller
change and is the wrong one: it makes safety depend on document order, so
appending a broad allow at the bottom silently widens access, and a rule whose
correctness depends on where it was pasted will eventually be pasted in the
wrong place. Deny-wins is also what operators already know from IAM and
firewalls, so nobody has to learn fold's variant.

The cost is that evaluation can no longer stop at the first matching allow.
That cost is confined to the documents that opt into it: the engine computes
at construction whether any rule carries a deny, and when none does the
evaluation is the same first-match short-circuit as before. Measured — 73.8 ns
for a deny-free document against 72.7 ns before this change, zero allocations
either way, and 92.7 ns when a deny rule matches the caller.

Deny is not a second enforcement mechanism. It participates in the same
decision, so a carved-out name is invisible in lists and uncallable together,
and the pair stays one pair. It is scoped by its rule's subjects like any
other rule rather than acting as a global kill switch, and it names itself in
the audit event's ruleId — an explicit refusal owes an operator its rule in a
way the default decision does not.

Phase 1 of docs/design-policy-depth.md. The schema needed anyOf to say "allow
or deny, at least one", since allow stopped being required.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit e895d25 into main Aug 13, 2026
7 checks passed
@blakebauman
blakebauman deleted the policy/deny-rules branch August 13, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant