Skip to content

Phase 4c: Intercept non-SSO logins for enforced domains#2798

Open
GregorShear wants to merge 1 commit intomasterfrom
greg/sso-phase-4/c
Open

Phase 4c: Intercept non-SSO logins for enforced domains#2798
GregorShear wants to merge 1 commit intomasterfrom
greg/sso-phase-4/c

Conversation

@GregorShear
Copy link
Contributor

@GregorShear GregorShear commented Mar 20, 2026

  • Add enforce_sso boolean column to tenants.
  • GoTrue customize_access_token hook (check_sso_requirement) blocks social login for users with email covered by tenant's SSO domains
  • The hook checks auth.users.is_sso_user — SSO users always pass through (important for token refresh).
  • Blocked logins receive a 403 error with message: 'sso_required:<domain>' — the frontend parses the domain and calls supabase.auth.signInWithSSO({ domain }) to redirect the user to their IdP.

Users whose email domain does NOT match an enforcing tenant's SSO domain (e.g., contractors with @gmail.com) are not blocked by the hook. Their grants on enforcing tenants are handled by grant filtering in 4d instead.

Activated by enforce_sso = true. Tenants configure SSO first, then communicate the transition to their users. enforce_sso is flipped on a hard cutoff date.

Verify:

  • Social user with matching email domain on enforcing tenant → blocked with sso_required:<domain>
  • Social user with matching domain, enforce_sso = false → not blocked
  • Social user with non-matching domain (e.g. @gmail.com) → not blocked (grants handled by 4d)
  • SSO user (is_sso_user = true) with matching domain → not blocked (token refresh works)
  • Blocked user redirected via signInWithSSO({ domain }) → authenticates via IdP → grant migration trigger fires
  • Malformed hook input → exception caught, login not blocked, warning logged

@GregorShear GregorShear force-pushed the greg/sso-phase-4/b branch 3 times, most recently from 0adfd5f to 825b209 Compare March 20, 2026 17:03
@GregorShear GregorShear force-pushed the greg/sso-phase-4/b branch 6 times, most recently from 7cb615f to 6b4fe9d Compare March 23, 2026 21:29
@GregorShear GregorShear force-pushed the greg/sso-phase-4/c branch 4 times, most recently from 8a8f8f5 to 9479354 Compare March 24, 2026 00:35
@GregorShear GregorShear changed the title Phase 4c: Soft SSO login nudge (access token hook) Phase 4c: Login intercept Mar 24, 2026
@GregorShear GregorShear requested review from jshearer and psFried March 24, 2026 00:37
@GregorShear GregorShear marked this pull request as ready for review March 24, 2026 00:48
@GregorShear GregorShear force-pushed the greg/sso-phase-4/c branch 2 times, most recently from 2a41825 to 78c163b Compare March 24, 2026 16:17
exception when others then
-- Never block login due to a bug in this hook.
raise warning 'check_sso_requirement failed for user %: %', target_user_id, SQLERRM;
return event;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking for input here - should we block or pass users on exception? do we favor breaking login, or adding a security hole?

either way i'll need help setting up an alert for that warning.

@GregorShear GregorShear changed the title Phase 4c: Login intercept Phase 4c: Intercept non-SSO logins for enforced domains Mar 24, 2026
@GregorShear GregorShear force-pushed the greg/sso-phase-4/b branch 3 times, most recently from 8e55746 to 15109f7 Compare March 24, 2026 18:34
Base automatically changed from greg/sso-phase-4/b to master March 25, 2026 16:18
@GregorShear GregorShear force-pushed the greg/sso-phase-4/c branch 2 times, most recently from 73fbcc9 to 33c62d9 Compare March 25, 2026 18:29
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% claude generated script for setting up mocksaml in a dev environment. it works on my machine... :)

Copy link
Contributor Author

@GregorShear GregorShear Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will probably remove this skill in favor of the start-with-saml.sh script below

# Allow/disallow new user signups to your project.
enable_signup = true

[auth.hook.custom_access_token]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for dev environment - will have to configure this via the supabase dashboard in production

);
end if;

return event;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the exception handler so exceptions will bubble up to the caller - is this the right approach? is there any specific monitoring we need to set up or are all exceptions like readily visible? (where would i look for these anyway?)

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