SSO Phase 4d: Omit sso-enforced grants from non-sso users#2805
Draft
GregorShear wants to merge 5 commits intomasterfrom
Draft
SSO Phase 4d: Omit sso-enforced grants from non-sso users#2805GregorShear wants to merge 5 commits intomasterfrom
GregorShear wants to merge 5 commits intomasterfrom
Conversation
GregorShear
commented
Mar 24, 2026
Comment on lines
+499
to
+508
| WHERE NOT EXISTS ( | ||
| SELECT 1 FROM tenants t | ||
| WHERE g.object_role ^@ t.tenant | ||
| AND t.enforce_sso | ||
| AND NOT EXISTS ( | ||
| SELECT 1 FROM auth.identities ai | ||
| WHERE ai.user_id = g.user_id | ||
| AND ai.provider = 'sso:' || t.sso_provider_id::text | ||
| ) | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
explain analyze before adding this where clause:
Seq Scan on user_grants g (cost=0.00..16.00 rows=600 width=52) (actual time=0.024..0.026 rows=3 loops=1)
Planning Time: 0.152 ms
Execution Time: 0.089 ms
and after:
Nested Loop Anti Join (cost=0.00..969850.12 rows=598 width=52) (actual time=0.047..0.048 rows=3 loops=1)
Join Filter: (((g.object_role)::text ^@ (t.tenant)::text) AND (NOT (hashed SubPlan 2)))
-> Seq Scan on user_grants g (cost=0.00..16.00 rows=600 width=52) (actual time=0.030..0.030 rows=3 loops=1)
-> Materialize (cost=0.00..14.25 rows=170 width=48) (actual time=0.005..0.005 rows=0 loops=3)
-> Seq Scan on tenants t (cost=0.00..13.40 rows=170 width=48) (actual time=0.015..0.015 rows=0 loops=1)
Filter: enforce_sso
Rows Removed by Filter: 1
SubPlan 2
-> Seq Scan on identities ai (cost=0.00..13.80 rows=380 width=48) (never executed)
Planning Time: 1.175 ms
Execution Time: 0.135 ms
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.
When
enforce_sso = true, filter grants so that only users with an SSO identity matching the tenant'ssso_provider_idcan see grants for that tenant. This handles users whose email domain doesn't match the SSO domain — they aren't blocked at login (4c) but can't access enforcing tenants' resources. Must cover both auth channels:internal.user_roles()SQL function (used byauth_roles())snapshot.rs— must useauth.identities.provider_idcheck (NOT the blanketis_sso_userflag)Verify: