Repository navigation
policy: deny rules, and deny wins globally - #55
Merged
Merged
Conversation
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]>
This was referenced Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of
docs/design-policy-depth.md.The engine was allow-only, so "everything on
billingexceptrefund_*" 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 likeallow[]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.
TestDenyWinsRegardlessOfOrderevaluates 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:
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 (
TestDenyRuleKeepsTheEnforcementPairdrives 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 conformance40/40, policy benchmarks above. The schema neededanyOfto express "allow or deny, at least one" now thatallowis no longer required.Phases 2–4 (argument constraints, destructive gating, docs) follow separately, as the design record intends.
🤖 Generated with Claude Code