Repository navigation
memory.owner_report for a wildcard or delegated token covers only what the token can read - #232
Merged
Merged
Conversation
…aces it cannot read A flat token with a `*` claim got an owner report with no namespace predicate, so it counted rows, readers and usage in restricted namespaces and collections the gate refuses it (a `*` never counts toward those). The wildcard path now applies the same exclusion an org admin's rollup does: `auth.context.every_readable_namespace`, factored out of `resolve_org_scope`. The report takes a predicate (`NamespaceScope`) instead of a namespace list with a `*` sentinel. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A delegated token reaches only the namespaces where its creator holds a live grant, so it takes the member path rather than the every-namespace one. The report resolves its scope once: in the reads statement, `namespace` is `e.namespace` by the SELECT alias, so a single predicate covers both the ledger and the memory subquery. The wildcard test now asserts the collection clause, and a new test covers a delegated token. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
With classification unreadable, a wildcard token's report is empty, runs no statement and marks the request the server's. The delegated-token test is named for what it checks (the member path), and the resolve_org_scope docstring says what an admin's filter holds. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
fix/owner-report-wildcard-restricted
branch
from
November 3, 2026 22:23
1ffb320 to
a7b950f
Compare
A flat token whose claim names `x` next to `*`, and whose grant on `x` was revoked, is capped at nothing there (`authz.claim_cap`), so the gate refuses `x`. The scope that an org admin's rollup and a wildcard owner report use now adds those named claims to `ns_hidden`, asked through `CachedGate`. The projection-failure tests route the grant read this adds, and stub `may_be_restricted` the gate now consults. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The empty predicate of an inaccessible OrgScopeFilter would read every namespace, so owner_report answers empty for it instead of trusting its caller to check; the handler's two early returns go. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ate admits Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
memory.owner_reportcalled with a flat*token no longer counts rows, readers or usage from restricted namespaces or collections that the token cannot read. A delegated*token's report is now limited to the namespaces where its creator holds a live grant. Before, it covered every namespace of the org.Why
Failing case: a flat VIEWER token with
namespaces=["*"]callsmemory.owner_reportwith nonamespace. The handler set the scope to["*"], so all three statements ran with no namespace predicate. The answer then included the owner's row counts, the readers (actor, agent) and the usage totals from a restricted namespace. That token cannot read there, becauseauthz.names_namespacenever counts a wildcard toward a restricted namespace. The same gap also covered collections the token cannot read.Pattern: the scoped-token branch filters through the gate (
rollup_member_namespaces). The wildcard branch skipped that step. An org admin's rollup (resolve_org_scope) already excludes these namespaces by name (ns_hidden) and leaves out unreadable collections.Fix: the exclusion step from
resolve_org_scope's admin branch is nowauth.context.every_namespace_scope, and the owner report's wildcard and auth-off path calls it. When classification cannot be read, the report comes back empty, as an org admin's rollup does. The helper also leaves out the namespaces the token's claim names but the gate refuses. A typical case is a claim capped at a revoked grant (authz.claim_cap), which applies even next to*and even for an org admin. Org-admin rollups throughresolve_org_scopeget the same exclusion. A delegated token with a*claim reaches only where its creator holds a live grant (authz._check_delegated), so it now takes the member path (rollup_member_namespaces), not the every-namespace one.owner_reportnow takes one predicate (anOrgScopeFilter, built withnamespace_scope(...)for a list) in place of a namespace list with a*sentinel, and the sentinel path is gone. In the reads statementnamespaceise.namespacethrough the SELECT alias, so the same predicate covers both the ledger and the memory subquery.Scope and risk
Touches
server/auth/context.py. There,resolve_org_scope's admin branch now also leaves out a named claim that the gate refuses, at the cost of one cached grant-map read per rollup. Also touchesserver/memory/app/exposure.pyandserver/memory/app/owner_report.py. Scoped tokens and calls that name anamespaceread the same rows as before. A wildcard token now sees less: nothing from a restricted namespace it holds no grant for, and nothing from a collection it cannot read. A delegated*token now sees only what its creator's live grants reach.Compatibility, rollout and rollback
Tests
test_a_wildcard_token_leaves_out_the_restricted_namespaces_it_cannot_readmarksns-rrestricted, calls the handler with a wildcard VIEWER token and asserts that all three statements carryNOT IN {ns_hidden}bound to["ns-r"]. It failed before the fix, because the SQL had no namespace predicate.test_a_delegated_wildcard_token_takes_the_member_pathasserts that a delegated*token's report is bounded bynssto its member namespaces. On main the report had nonsspredicate.test_a_wildcard_token_gets_nothing_when_classification_is_unreadableasserts that the report is empty, runs no statement and marks the request answered-unverified.test_with_auth_off_the_report_reads_every_namespacetakes the place of the old sentinel test.clickhouse local(26.9) and returned only the unhidden namespace.test_a_wildcard_scope_excludes_a_named_claim_capped_at_a_revoked_grantuses a claim of*,xandshop, with a revoked grant onx, and assertsns_hidden == [restricted, "x"].pytest tests/unit/test_owner_report.py tests/unit/test_request_sli.py tests/unit/test_context_restricted_resolution.py tests/unit/test_package_contracts.pypassed.make format lint typecheckpassed.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. Checked: the gate rule for wildcard claims, that
resolve_org_scopekeeps its output, and that the new test failed before the fix.I can explain every line of this diff and how it interacts with the rest of Loom.
🤖 Generated with Claude Code