Repository navigation
policy: constrain grants by argument - #56
Merged
Merged
Conversation
A grant was per name, so "may deploy" and "may deploy to staging" were the same sentence. args is a map of dotted JSON path to required value on an allow or deny clause, all of which must match, compared type-exactly the way subject claims already are — "1" and 1 are different, because a lenient comparison silently widens a grant. The asymmetry this creates is real and is now written down in the README rather than left to be discovered: there are no arguments at list time, so a constrained tool is visible and only conditionally callable. The invisibility pair's guarantee becomes "a caller never sees a tool they cannot call at all" rather than "never sees anything they might be refused", and an operator who needs the stronger property grants by name. The design record did not settle the mirror case, and implementation had to. A deny carrying args cannot be evaluated at list time either, and hiding there would apply the rule far more broadly than it was written — "no deploys to production" would remove deploy entirely. So an unevaluable deny does not hide; it refuses at call time. Allow and deny make opposite choices about the same missing information, each in the direction that matches what the rule says. Denials name the constraint path that failed and never the value the rule wanted: what the caller sent is already theirs, but what the rule expects is the operator's configuration, and a refusal is a poor place to disclose a policy document one field at a time. Arguments are parsed lazily and at most once per call, through a source the gateway only builds when the running policy constrains something — fold forwards arguments as raw JSON otherwise, which is part of why the proxy path is allocation-light. Keeping that promise took keeping the old matcher. Folding the arg-aware logic into it behind a mode flag cost ~4% on the per-item decide path, which is measurable because policy is evaluated once per item of every list it filters. So there are two matchers, and a document with no args anywhere runs the original: 76.8 ns against a 75.2 ns baseline, zero allocations, versus 94.3 ns for one that constrains arguments and walks a dotted path. Added p50 through the proxy is 181 µs against a 5 ms gate; conformance 40/40. Phase 2 of docs/design-policy-depth.md. 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 2 of
docs/design-policy-depth.md, following #55.A grant was per name, so "may call
deploy" and "may calldeployagainst staging" were the same sentence.argsis a map of dotted JSON path to required value on an allow or deny clause:{ "server": "deploy", "names": ["deploy"], "args": { "target.environment": "staging" } }Values compare type-exactly, like subject claims —
"1"and1are different, because a lenient comparison silently widens a grant. No wildcards, no array indexing: a matcher that starts narrow can widen later; one that starts expressive cannot be narrowed.The asymmetry, stated rather than discovered
There are no arguments at list time, so this cannot filter a list: a constrained tool is visible and only conditionally callable. The invisibility pair's guarantee becomes a caller never sees a tool they cannot call at all rather than never sees anything they might be refused. An operator who needs the stronger property grants by name. This is in the README's policy section, not just here.
The design record did not settle the mirror case, and implementation had to. A
denycarryingargsis equally unevaluable at list time — but hiding there would apply the rule far more broadly than written, since "no deploys to production" would removedeployentirely. So an unevaluable deny does not hide; it refuses at call time. Allow and deny make opposite choices about the same missing information, each in the direction that matches what the rule actually says.Denials name the constraint path that failed and never the value the rule wanted. What the caller sent is already theirs; what the rule expects is the operator's configuration, and a refusal is a poor place to disclose a policy document one field at a time.
TestArgumentConstraintThroughTheGatewayasserts both halves — the path appears, the expected value does not.Keeping the old path meant keeping the old matcher
Arguments are parsed lazily, at most once per call, through a source the gateway only builds when the running policy constrains something.
Folding the arg-aware logic into the existing matcher behind a mode flag cost ~4% on the per-item decide path — measurable, because policy is evaluated once per named invocation and once per item of every list it filters. So there are two matchers:
argsanywhere, baseline before this PRargsanywhere, afterThe residual 1.6 ns is the wider
Decisionstruct, which now carries the failed path. Six runs per side against a stashed baseline, not a single sample.Verification
make check(race) green,make conformance40/40, added p50 181 µs against a 5 ms gate, plus five new policy unit tests and one integration test through a real gateway.Phase 3 (destructive gating via
toolKind) and phase 4 (docs pass) remain.🤖 Generated with Claude Code