fix(query): respect wildcard ExcludedSubjects in LookupSubjects intersection#3136
Open
matte1782 wants to merge 2 commits into
Open
fix(query): respect wildcard ExcludedSubjects in LookupSubjects intersection#3136matte1782 wants to merge 2 commits into
matte1782 wants to merge 2 commits into
Conversation
…section The experimental query-plan engine's intersectSubjectSets admitted a concrete subject matched by the other operand's wildcard without consulting that wildcard's ExcludedSubjects. A subject explicitly excluded from a wildcard (e.g. `viewer:* - banned`) was therefore re-admitted when the exclusion fed into an intersection such as `(viewer:* - banned) & reader`, so LookupSubjects enumerated a banned subject as authorized. Check is unaffected (it resolves the wildcard ban at the datastore leaf), so this manifested as a Check vs LookupSubjects consistency violation under `--experimental-query-plan ls`. intersectSubjectSets now applies the wildcard's exclusions when admitting concrete subjects, reusing combineExclusionCaveats so caveated exclusions are handled consistently with the exclusion iterator, and unions the two ExcludedSubjects sets in the wildcard-with-wildcard case ((* - E1) intersect (* - E2) = * - (E1 union E2)). Adds unit and end-to-end coverage in wildcard_intersection_test.go and a wildcardmainexclusionintersect.yaml consistency config (companion to wildcardintersectionexclusion.yaml, whose exclusion main set is concrete).
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
authzedbot
added a commit
to authzed/cla
that referenced
this pull request
May 25, 2026
Codecov Report❌ Patch coverage is
❌ Your project check has failed because the head coverage (74.50%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #3136 +/- ##
==========================================
- Coverage 75.97% 74.50% -1.46%
==========================================
Files 566 566
Lines 64236 64287 +51
==========================================
- Hits 48797 47891 -906
- Misses 11770 12782 +1012
+ Partials 3669 3614 -55 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Fixes #3135.
Problem
In the experimental query-plan engine,
intersectSubjectSets(pkg/query/intersection.go) admits a concrete subject matched by the other operand's wildcard without consulting that wildcard'sExcludedSubjects. So a subject explicitly excluded from a wildcard (viewer:* - banned) is re-admitted when the exclusion feeds an intersection ((viewer:* - banned) & reader), andLookupSubjectsenumerates a banned subject as authorized.Checkis unaffected (it resolves the wildcard ban at the leaf), so this is aCheckvsLookupSubjectsconsistency violation under--experimental-query-plan ls(default off).This is reachable through the real schema compiler, not just hand-built iterators. For the schema in #3135 the plan compiles to:
Before:
IterSubjects(viewable)=[alice, bob, charlie]. After:[alice, charlie].Fix
intersectSubjectSetsnow:ExcludedSubjectsand, when admitting a concrete subject matched by that wildcard, applies the exclusion viacombineExclusionCaveats— dropping the subject for an absolute exclusion, or conditioning it on the negated exclusion caveat. ReusingcombineExclusionCaveatskeeps caveated exclusions consistent with howExclusionIteratoralready treats them.ExcludedSubjectsin the wildcard ∩ wildcard case, since(* - E1) ∩ (* - E2) = * - (E1 ∪ E2)(OR-combining caveats when the same subject is excluded on both sides; an unconditional exclusion dominates).When neither wildcard carries exclusions the behavior is byte-for-byte unchanged.
Tests
pkg/query/wildcard_intersection_test.go: unit subtests inTestIntersectSubjectSetsfor excluded-concrete dropping (both wildcard sides), caveated exclusion conditioning, and exclusion union in wildcard ∩ wildcard; plus an end-to-end(viewer:* - banned) & readersubtest inTestIntersectionIterator_WildcardBehavior. Each new test fails onmainand passes with this change.internal/services/integrationtesting/testconfigs/wildcardmainexclusionintersect.yaml: companion consistency config. The existingwildcardintersectionexclusion.yamlonly covers an exclusion whose main set is concrete ((viewer & reader) - banned); this one exercises a wildcard main set ((viewer:* - banned) & reader). It passes the defaultTestConsistency(stable engine) suite.go test ./pkg/query/...andgo vet ./pkg/query/pass.