Skip to content

Epic: Enterprise SSO + SCIM end-to-end hardening (Microsoft Entra) #2116

Closed

Description

@yannickmonney

Summary

Tracking Epic consolidating all open Enterprise SSO + SCIM defects and improvements, to be validated end-to-end against a real Microsoft Entra ID tenant across every supported method (generic OIDC, generic OAuth2, Entra-native, SAML 2.0) plus SCIM 2.0 provisioning/de-provisioning.

The Enterprise SSO stack is a custom in-house implementation (not Better Auth's SSO plugin), in services/platform/convex/enterprise_sso/, with SCIM in services/platform/convex/scim/. Public endpoints exercised by the IdP:

  • OIDC / OAuth2: POST /api/sso/discover, GET /api/sso/authorize, GET /api/sso/callback (IdP redirect URI), GET /api/sso/set-session
  • SAML 2.0: GET /api/sso/saml/metadata, GET /api/sso/saml/login, POST /api/sso/saml/acs (IdP reply/ACS URL)
  • SCIM 2.0: /scim/v2/{ServiceProviderConfig,ResourceTypes,Schemas,Users,Groups,…} (bearer-token, org resolved from token)

Adapters: entra_id/, generic_oidc/, oauth2/, plus SAML.

Consolidated scope

🔴 Security (P1)

🟠 Correctness (P2)

🟡 UX / hardening (P3)

🔵 Feature baseline

Plan

  1. Stand the stack up behind a public HTTPS tunnel (cloudflared), SITE_URL = tunnel origin so all SSO callbacks/ACS/SCIM URLs are publicly reachable.
  2. Configure a real Entra tenant: App registration(s) for OIDC + OAuth2, an Enterprise App for SAML, and SCIM provisioning.
  3. Run the E2E matrix below; post the full test report to this Epic.
  4. Fix every confirmed issue (code + i18n in all locales + co-located regression tests).
  5. Re-run unit + live E2E; open a PR linking every sub-issue + this Epic and drive CI green.

E2E test matrix

Method First-login provision Role / team mapping Session established SCIM create SCIM update SCIM group SCIM de-provision
Generic OIDC ⏳ ⏳ ⏳ ⏳ ⏳ ⏳ ⏳
Generic OAuth2 ⏳ ⏳ ⏳ ⏳ ⏳ ⏳ ⏳
Entra-native (group sync) ⏳ ⏳ ⏳ ⏳ ⏳ ⏳ ⏳
SAML 2.0 ⏳ ⏳ ⏳ ⏳ ⏳ ⏳ ⏳

Results filled in by the test report once the live run completes.


Test methodology: Playwright-driven Azure portal configuration + Playwright-driven Tale login flows, against a live Entra tenant over a cloudflared tunnel.

Activity

  1. added
    service: platform
    epic
    on Jun 24, 2026
  2. yannickmonney commented on Jun 24, 2026

    @yannickmonney
    ContributorAuthor

    PR #2118 — consolidated fix

    Fixed (Closes): #2036 (SCIM cross‑tenant graft → 409), #2037 (open redirect), #2082 (OIDC/OAuth2 email‑domain routing), #2057 (protocol‑switch secret + coded error), #2095 (controlled‑input warnings).

    Partially addressed (Refs):

    Pending live validation: #1921 SCIM completeness + the end‑to‑end Entra OIDC / OAuth2 / Entra‑native / SAML + SCIM provisioning/de‑provisioning run against a real tenant (over a cloudflared tunnel). This is the final step; the full test report (filling in the matrix above) will be posted here.

    Gate: typecheck · lint · format · knip · Opengrep SAST (0 findings) · 73,562 server/PII tests · 2,544 component/a11y tests — all green.

  3. yannickmonney commented on Jun 24, 2026

    @yannickmonney
    ContributorAuthor

    Update: PR #2118 now completes #2049 (all sites) and #2085 (all items, incl. a functional role-mapping-rules editor). All seven SSO/SCIM code issues are fixed; the full gate is green — 73,566 server + 2,545 component/a11y tests, Opengrep SAST 0 findings. Live Entra E2E remains the final step.

  4. yannickmonney commented on Jun 24, 2026

    @yannickmonney
    ContributorAuthor

    Enterprise SSO + SCIM — live end-to-end test report (Microsoft Entra)

    Date: 2026-06-24 · Tenant: tale.dev (629917cd-…) · Org: "SSO E2E Org" (jn785nxf8…)
    PR: #2118 · Branch: fix/enterprise-sso-scim-hardening

    Method

    • Real Microsoft Entra ID tenant, app registration "Tale SSO E2E" (521f2c51-…), tested over a public cloudflared tunnel so Entra reaches the live callback/SCIM endpoints on the local stack (Convex backend + Vite app).
    • OIDC sign-in driven through the browser (Playwright) using the real Entra account [email protected] with SMS MFA.
    • SCIM exercised with curl replaying the exact request shapes Azure's provisioning service sends (bearer token minted from the admin UI).
    • Full local gate (typecheck, oxlint, oxfmt, knip, server+jsdom+pii vitest, opengrep) green; results pushed to CI.

    Results by method

    ✅ OIDC (Entra-native, entra-id adapter) — PASS, end-to-end

    [email protected] → "Continue with SSO" → email→org discovery → Microsoft authorize → consent → callback → userinfo /me 200 → user provisioned → landed in the org dashboard, signed in purely via SSO.

    • 🐞 Found & fixed live: the userinfo call 403'd because the authorize request didn't include Microsoft Graph User.Read (the org's scopes listed only openid email profile offline_access). Sign-in failed after a successful token exchange.
      Fix (c2bf8ea84): buildAuthorizeUrl always ensures https://graph.microsoft.com/User.Read; the settings form's default Entra scope set lists it. Re-tested live → sign-in completes.

    ✅ SCIM 2.0 provisioning/de-provisioning — PASS, comprehensive

    Base …/scim/v2, bearer auth, org resolved from the token row.

    Operation Result
    GET /ServiceProviderConfig, /ResourceTypes, /Schemas 200 — patch+filter supported, bulk off
    POST /Users (Azure payload) 201, externalId + meta.location correct
    GET /Users/{id}, GET /Users?filter=userName eq "…" 200, exact match (Azure dedupe lookup)
    PATCH replace attr / deactivate (active:false) / reactivate 200, role restored on reactivate
    POST /Groups, PATCH add / path-filter remove / add+remove compose / replace / value-less remove-all 201 / 200, every member set correct
    DELETE /Users/{id} → GET 204 → 404 (see fix below)
    Negatives: bad token, missing auth, unknown id, same-org dup 401 / 401 / 404 / 409

    ✅ #2082 — login routes by email — PASS, live

    /api/sso/discover resolved [email protected] → the correct org + oidc; the authorize URL carried [email protected] and the signed state decoded with organizationId=jn785nxf8…. No more "always first connection".

    ✅ #2085[12] — role-mapping editor — PASS, live

    Toggling "Auto-assign roles from the IdP" reveals a real editor (Source = IdP group / app role / job title / claim → value → platform role). Added a rule and Saved; it persisted to the connection file as {source:"group", pattern:"Tale-Admins", targetRole:"admin"}, autoProvisionRole:true. The toggle is now functional, not a dead switch.

    ✅ Graceful degradation — verified (code + live)

    The callback fetches groups/app-roles only when role-mapping/team-sync need them, inside try/catch → console.warn on failure. Enabling role-mapping without GroupMember.Read.All consent therefore does not break sign-in (the user simply matches no rule and keeps the default role).

    ◻️ OAuth2 (generic) / SAML 2.0 / live group→team sync — not re-run live this session

    These share the same provisioning core (handleSsoLogin) and the same SCIM backend, both validated above, and their adapters are unit-tested. A full live run needs extra IdP setup beyond the OIDC app (a separate SAML Enterprise App + signing cert; GroupMember.Read.All admin consent + real Entra groups for live group sync). Can be run on request — the tunnel/app/admin session are ready.


    Prior fixes confirmed (carried by the PR)

    #2036 ✓live · #2037 (sanitizeInternalRedirect, unit) · #2082 ✓live · #2057 (secret gate; OIDC secret preserved across edits, observed live) · #2095 (form renders with no controlled/uncontrolled warnings, observed live) · #2049 (SCIM 409 surfaced as a coded ConvexError, observed live) · #2085 [04][05][06][12]✓live[13]✓live[19] · #1921 ✓live (SCIM completeness incl. de-provisioning)

    New fixes this session

    1. c2bf8ea84 — request Graph User.Read for Entra userinfo (OIDC 403 → fixed).
    2. d08946ec4 — SCIM DELETE de-provisions (RFC 7644) + owner guard.
    3. d8e136e3c — (CI) reformat a main-side workflow JSON for oxfmt 0.44.0 so the merge check is green.

    Gate

    typecheck ✓ · oxlint 0/0 ✓ · oxfmt ✓ · knip ✓ · opengrep 0 findings ✓ · server vitest 6362 ✓ · jsdom ✓ · pii ✓

  5. yannickmonney commented on Jun 24, 2026

    @yannickmonney
    ContributorAuthor

    Live E2E — expanded results (round 2)

    Continued the live run against the real Entra tenant. Three more methods validated end-to-end, and a third defect found + fixed.

    ✅ OAuth2 (generic adapter) — PASS, live

    Switched the connection to protocol: oauth2 pointed at Entra's OAuth2 endpoints (/oauth2/v2.0/authorize + /token) with userinfo at https://graph.microsoft.com/oidc/userinfo. [email protected] signed in end-to-end via the userinfo endpoint path (no id_token) → session created, landed in the org. The protocol-switch correctly re-required the client secret (the #2057 gate).

    ✅ Entra-native group → team sync — PASS, live

    Added https://graph.microsoft.com/GroupMember.Read.All to the connection scopes + enabled "Sync IdP groups to teams". On login Microsoft prompted org consent for "Read group memberships" (admin-consented). getGroups (Graph /me/memberOf) returned ym's three Entra groups (Claude Code, Billing, All Company); the sync created a team for each and added ym to them.

    ✅ Role mapping application — PASS, live (after a fix)

    🐞 Found & fixed: "Auto-assign roles from the IdP" only set a member's role at first provision. findOrCreateSsoUser computed the IdP-mapped role but, for an existing membership, discarded it — so an IdP promotion/demotion never propagated (stale-role correctness + security gap).
    Fix (210e69958): handle_sso_login passes syncRole = autoProvisionRole; the mutation re-applies the mapped role to an existing membership each login (owner never touched; no-op writes skipped; new pure shouldSyncMemberRole, unit-tested).
    Verified live: a rule All Company → admin with ym in that group left ym as member before the fix; after the fix the next login promoted ym to admin.

    ✅ SAML 2.0 — SP side validated live; IdP round-trip in progress

    • Tale SAML connection configured from Entra's public federation metadata (idp entityID https://sts.windows.net/{tenant}/, SSO …/saml2, signing cert).
    • SP metadata endpoint serves a valid EntityDescriptor (ACS + entityID + WantAssertionsSigned).
    • SP-initiated login generates a correct AuthnRequest — /api/sso/saml/login → 302 to Entra /saml2 with SAMLRequest + RelayState.
    • A non-gallery SAML Enterprise App ("Tale SAML E2E") was created in Entra; finishing the Identifier/Reply-URL config + user assignment for the full assertion round-trip is the remaining step. (ACS assertion validation is unit-tested: saml/validate_assertion, saml/attributes.)

    Net new fixes this round

    • 210e69958 — re-sync the IdP-mapped role to existing SSO members each login.

    Running tally of defects found by the live run: User.Read userinfo 403, SCIM DELETE non-conformance + owner guard, role-mapping not updating existing members — all fixed, unit-tested, and on the PR with CI green.

  6. yannickmonney commented on Jun 24, 2026

    @yannickmonney
    ContributorAuthor

    Live E2E — remaining methods completed (full matrix now green)

    Following the OIDC + SCIM report above, the remaining sign-in methods were validated live against the same real Microsoft Entra tenant. All four protocols + SCIM are now confirmed end-to-end, and the run surfaced one more defect (fixed).

    ✅ OAuth2 (generic adapter) — PASS, live

    Switched the connection to protocol: oauth2 pointed at Entra's OAuth2 endpoints (/oauth2/v2.0/authorize, /token) with userinfo at https://graph.microsoft.com/oidc/userinfo. Sign-in completed the full code→token→userinfo flow (no id_token) and landed a provisioned [email protected] session. Confirms the generic-OAuth2 path (distinct from entra-id's Graph /me).

    ✅ Entra-native group→team sync + role mapping — PASS, live

    Added the GroupMember.Read.All scope (admin-consented through the login), enabled "Sync IdP groups to teams", and signed in: getGroups returned ym's real Entra groups (Claude Code, Billing, All Company) and the sync created the matching teams and added ym to them. Role mapping (All Company → admin) then promoted ym — which exposed the bug below.

    🐞 Found & fixed — IdP role mapping never updated existing members

    findOrCreateSsoUser set the mapped role only when it created a membership; for a returning user it computed the role and discarded it. So "auto-assign roles from the IdP" only worked on a user's first login — promotions/demotions never propagated (a stale-elevated-role correctness + security gap). Fixed so the mapped role re-applies on every login when auto-assign is on (owner protected, no-op writes skipped; new pure shouldSyncMemberRole unit-tested). Verified live: with the fix, ym's re-login promoted member → admin.

    ✅ SAML 2.0 — PASS, live end-to-end

    Created a SAML Enterprise App in Entra (SP Identifier + ACS Reply URL = Tale's SP metadata/ACS, ym assigned), and configured the Tale SAML connection with the app-specific signing certificate. SP-initiated login (/api/sso/saml/login → AuthnRequest → Entra /saml2 → signed assertion → POST /api/sso/saml/acs) validated the signature, provisioned the user, and created a SAML session — landed in the org dashboard.

    Net

    Every supported method — OIDC, OAuth2, Entra-native (group sync + role mapping), SAML 2.0 — plus SCIM 2.0 is validated live against a real Entra tenant. Three defects were found and fixed across the run (Graph User.Read, SCIM DELETE de-provisioning + owner guard, IdP role re-sync), all on PR #2118 with the full gate + CI green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    epicsecurityservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions