-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(sso): SAML/OIDC single sign-on #3911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0ski
wants to merge
1
commit into
main
Choose a base branch
from
oskar/feat-sso
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| area: webapp | ||
| type: feature | ||
| --- | ||
|
|
||
| Add `POST /webhooks/v1/accounts`: a thin passthrough that verifies inbound | ||
| webhooks via the SSO plugin and enqueues them on a dedicated worker. No-op | ||
| (404) when no plugin is installed. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| area: webapp | ||
| type: feature | ||
| --- | ||
|
|
||
| Wire the SSO plugin loader (`@trigger.dev/sso`) into the webapp: SSO auth | ||
| method, `hasSso` flag, `SsoStrategy`, and contributor fallback env vars. | ||
| No-op (`no_sso`) without the plugin. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| area: webapp | ||
| type: improvement | ||
| --- | ||
|
|
||
| When an SSO session is revalidated and the IdP reports it invalid, the user is now sent to the login page with a "Your SSO session expired. Please sign in again." notice instead of seeing a raw `sso_session_invalidated` 401. | ||
|
|
||
| Navigations redirect through `/logout` (clearing the cookie) to `/login?reason=session_expired`. Programmatic fetches (Remix fetchers, Electric, etc.) get a 401 carrying an `x-sso-session-invalidated` marker header that a client-side fetch guard turns into the same logout redirect. EventSource streams, which can't read response headers, probe a new lightweight `/resources/session-check` endpoint on stream error to trigger the redirect. |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { Prisma, prisma } from "~/db.server"; | ||
| import { logger } from "~/services/logger.server"; | ||
| import { rbac } from "~/services/rbac.server"; | ||
|
|
||
| export type EnsureOrgMemberParams = { | ||
| userId: string; | ||
| organizationId: string; | ||
| // null = use the seeded MEMBER role from the existing enum. A non-null | ||
| // value is an RBAC role id; when an RBAC plugin is installed it gets | ||
| // attached after the OrgMember row is created. | ||
| roleId: string | null; | ||
| source: "sso_jit" | "invite" | "manual"; | ||
| }; | ||
|
|
||
| export type EnsureOrgMemberResult = { created: boolean; orgMemberId: string }; | ||
|
|
||
| // Idempotent OrgMember upsert. If the (userId, organizationId) row | ||
| // already exists this is a no-op (returns `{ created: false }`); we do | ||
| // NOT touch the existing role to avoid demoting a user that JIT happens | ||
| // to fire for again. | ||
| // | ||
| // Seat-limit enforcement lives at the call sites — every existing | ||
| // OrgMember insert in the codebase does its own seat check before | ||
| // calling in. This helper deliberately does none (SSO JIT and | ||
| // invite-accept are exempt by policy). | ||
| export async function ensureOrgMember( | ||
| params: EnsureOrgMemberParams | ||
| ): Promise<EnsureOrgMemberResult> { | ||
| const { userId, organizationId, roleId, source } = params; | ||
|
|
||
| const existing = await prisma.orgMember.findFirst({ | ||
| where: { userId, organizationId }, | ||
| select: { id: true }, | ||
| }); | ||
| if (existing) { | ||
| return { created: false, orgMemberId: existing.id }; | ||
| } | ||
|
|
||
| // Two concurrent JIT/invite flows can both miss the findFirst above and | ||
| // race to create the same (userId, organizationId) row; the unique | ||
| // constraint makes one lose with P2002. Treat that as the idempotent | ||
| // "already a member" case rather than letting it break sign-in. | ||
| let member: { id: string }; | ||
| try { | ||
| member = await prisma.orgMember.create({ | ||
| data: { | ||
| userId, | ||
| organizationId, | ||
| role: "MEMBER", | ||
| }, | ||
| select: { id: true }, | ||
| }); | ||
| } catch (error) { | ||
| if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") { | ||
| const existingAfterConflict = await prisma.orgMember.findFirst({ | ||
| where: { userId, organizationId }, | ||
| select: { id: true }, | ||
| }); | ||
| if (existingAfterConflict) { | ||
| return { created: false, orgMemberId: existingAfterConflict.id }; | ||
| } | ||
| } | ||
| throw error; | ||
| } | ||
|
|
||
| if (roleId !== null) { | ||
| const result = await rbac.setUserRole({ userId, organizationId, roleId }); | ||
| if (!result.ok) { | ||
| logger.warn("ensureOrgMember.setUserRole failed", { | ||
| source, | ||
| userId, | ||
| organizationId, | ||
| roleId, | ||
| error: result.error, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return { created: true, orgMemberId: member.id }; | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add lower-bound validation to SSO revalidation numeric env vars.
SSO_SESSION_REVALIDATION_INTERVAL_SECONDSandSSO_SESSION_REVALIDATION_TIMEOUT_MSaccept0/negative values today. That can cause pathological revalidation behavior (request-amplification or immediate timeout churn) under misconfiguration. Enforce strictly positive bounds in the schema.Suggested diff
📝 Committable suggestion