Repository navigation
A policy can finally say "requires the write scope" - #87
Merged
Merged
Conversation
fold could not express the most ordinary enterprise authorization
predicate there is. Scopes arrive in the `scope` claim as a
space-delimited string (RFC 6749), and the claims matcher compares whole
values — so `claims: {"scope": "write"}` does not match a token carrying
`read write admin`, and no amount of writing it differently helped.
`subjects.scopes` reads `scope`, or `scp` when that yields nothing, as
either a space-delimited string or an array, so a rule is written once
against the concept rather than against an issuer's spelling. The two
are never merged: an issuer sending both is sending the same set twice,
and merging would silently union two claims that disagreed.
Scopes match conjunctively — every one named must be held. That is
deliberately unlike subs and groups, which are alternatives: those
answer "who is this", where one identity is enough, while a scope
answers "what were they granted", where a list is a set of
requirements rather than a choice. So scopes gate like claims do,
combining with an identity or standing alone. Because PolicySubjects is
shared, tenants get the same selector from the same definition.
A denial now says what would fix it. Where scopes were the only obstacle
the -32042 error names them, in the message and in data.missingScopes,
and the audit event carries them, so an agent re-authorizes for what it
lacks instead of retrying blind. Two disclosure rules bound that, and
they matter more than the convenience. Only scopes the caller lacks
appear, because re-authorizing accumulates permissions rather than
replacing them and asking for the pair risks losing what they had. And a
rule contributes only when scopes were the sole obstacle and it targets
that exact invocation — naming a requirement that guards something the
caller could not reach anyway would disclose that it exists. It is the
discipline args already follows, which reports which path failed and
never the value the rule wanted.
Documents naming no scopes evaluate exactly as before: the accounting is
gated on a flag computed at construction, and the list path never
computes a shortfall at all, since it is confined to the call mode.
On the tenant index, one correction worth recording. Scope-bearing
selectors are excluded from the claim and group indexes, but that is
consistency and defence in depth rather than a bug fix: considerTenants
re-matches every candidate an index produces, so a mis-filed selector
narrows oddly and never admits wrongly. It is kept because dropping that
re-match as redundant is exactly the optimization someone will reach for
one day. The predicate that is load-bearing today is the exclusion of
subs from indexableGroups, because subs and groups are alternatives and
a principal can satisfy such a selector while holding no group at all.
Single-scope selectors get their own index; multi-scope ones cannot,
since a conjunction is not answerable by a held-scope lookup.
No behavioural test can catch a mis-filing, precisely because behaviour
is correct either way, so the partitioning is asserted directly.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Aug 25, 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 the audit follow-up. Independent of #84.
The gap
fold could not express the most ordinary enterprise authorization predicate there is. Scopes arrive in the
scopeclaim as a space-delimited string (RFC 6749 §3.3), andclaimsMatchcompares whole values — soclaims: {"scope": "write"}does not match a token carryingread write admin. There was no way to write it that worked.subjects.scopesreadsscope, orscpwhen that yields nothing, as either a space-delimited string or an array — so a rule is written once against the concept rather than against an issuer's spelling. The two are never merged: an issuer sending both is sending the same set twice, and merging would silently union two claims that disagreed.Because
PolicySubjectsis shared,tenantsselectors get the same field from the same definition.The semantic choice worth reviewing
Scopes match conjunctively — every scope named must be held — unlike
subsandgroups, which are alternatives.The reasoning:
subsandgroupsanswer who is this, and one identity is enough. A scope answers what were they granted, where a list reads as a set of requirements rather than a choice. So scopes gate likeclaimsdo — combine with an identity, or stand alone as the whole subject.Denials that say what would fix them
Where scopes were the only obstacle,
-32042names them in the message and indata.missingScopes, and the audit event carries them. An agent re-authorizes for exactly what it lacks instead of retrying blind.Two disclosure rules bound this, and they matter more than the convenience:
readwho needsread writeis told to obtainwritealone — asking for the pair risks an IdP issuing a token that drops what they had.argsalready follows — it reports which path failed, never the value the rule wanted.Both are mutation-tested: removing the targeting guard, or returning the full requirement instead of the shortfall, each fails a specific test.
Cost to documents that don't use it
Nothing. The accounting is gated on a
hasScopesflag computed at construction, and the shortfall is only computed underargEnforce— exclusive toDecideCall— so list filtering never touches it. Latency gate unmoved at 0.179 ms.A correction on the tenant index
My first version of this change claimed the index predicates were a live admission bug — that
{groups:["eng"], scopes:["admin"]}filed underbyGroupwould match on the group alone. That was wrong, and the design record now says so.considerTenantsre-matches every candidate an index produces, so the index only narrows and the matcher stays the authority.The exclusions are kept as consistency and defence in depth — dropping that re-match as redundant is exactly the optimization someone reaches for one day. The predicate that is load-bearing today is the exclusion of
subsfromindexableGroups:subsandgroupsare alternatives, so a principal can satisfy such a selector by subject while holding no group at all, and a group lookup would never surface it. Conjunctive dimensions can't produce that failure; disjunctive ones can.Single-scope selectors get their own index. Multi-scope ones cannot — a conjunction is not answerable by a held-scope lookup — so they scan, deliberately.
No behavioural test can catch a mis-filing, precisely because behaviour is correct either way.
TestScopeBearingSelectorsAreNotIndexedByAnotherDimensionasserts the partitioning itself and is the only thing that fails when a predicate loses a condition; its comment says so, so nobody deletes it as redundant. The cross-product test was also extended with scopes — it passes either way, which is the finding rather than a gap.Verification
go test -race ./...— all greendatafield on-32042is tolerated on the wireIntegration tests use real SDK peers throughout; the visibility test connects a second client directly to the upstream to prove the tool's absence is the gateway's doing.
Known gaps
MissingScopesis asserted ontools/callbut notprompts/getorresources/read(same code path inauthorize), and there's no benchmark asserting that scope-free documents pay nothing — it's argued structurally rather than measured.🤖 Generated with Claude Code