Skip to content

policy: constrain grants by argument - #56

Merged
blakebauman merged 1 commit into
mainfrom
policy/argument-constraints
Aug 13, 2026
Merged

blakebauman merged 1 commit into
mainfrom
policy/argument-constraints

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Phase 2 of docs/design-policy-depth.md, following #55.

A grant was per name, so "may call deploy" and "may call deploy against staging" were the same sentence. args is 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" and 1 are 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 deny carrying args is equally unevaluable at list time — but hiding there would apply the rule far more broadly than written, since "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 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. TestArgumentConstraintThroughTheGateway asserts 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:

ns/op allocs
no args anywhere, baseline before this PR 75.2 0
no args anywhere, after 76.8 0
document constraining arguments, one dotted path 94.3 0

The residual 1.6 ns is the wider Decision struct, which now carries the failed path. Six runs per side against a stashed baseline, not a single sample.

Verification

make check (race) green, make conformance 40/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

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]>
@blakebauman
blakebauman merged commit b5ece8e into main Aug 13, 2026
7 checks passed
@blakebauman
blakebauman deleted the policy/argument-constraints branch August 13, 2026 16:50
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