Skip to content

Commit 87aac98

Browse files
committed
wip(plugin-auth): SSO group claim projects the IdP group mapping (WIP)
Claude-Session: https://claude.ai/code/session_01ADHkmNwrm1hJ9e7eLARM7n Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6924440 commit 87aac98

8 files changed

Lines changed: 783 additions & 82 deletions

File tree

‎packages/platform-objects/src/identity/sys-idp-group-mapping.object.ts‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
66
* sys_idp_group_mapping — which permission set an identity provider's group
77
* grants (ADR-0134 D4's group seam, filled for permission sets only).
88
*
9-
* One row says: a member of THIS group, pushed by THIS source, holds THIS
10-
* permission set in THIS organization. The source is a SCIM connection today
9+
* One row says: a member of THIS group, sent by THIS source, holds THIS
10+
* permission set in THIS organization. The source is a SCIM connection
1111
* (`source_kind: 'scim'`, `source_id` = the connection id the bearer verifies
12-
* as); the kind column is there so an SSO provider's group claim can name its
13-
* provider the same way later, without a second mapping model.
12+
* as) or an SSO provider whose sign-in carries the user's groups as a claim
13+
* (`source_kind: 'sso'`, `source_id` = the provider id): one mapping model for
14+
* both, never a second one.
1415
*
1516
* Who writes it: the platform administrator, through plugin-auth's
1617
* `/admin/scim/set-group-mapping` and `/admin/scim/delete-group-mapping`
@@ -23,8 +24,10 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
2324
* administrator standing.
2425
*
2526
* Who reads it: the SCIM `projection` (`scim-group-projection.ts`) when a
26-
* group's membership changes. A group is matched by its `externalId` when the
27-
* row names one, else by its `displayName`; the row names exactly one.
27+
* group's membership changes, and the SSO sign-in (`sso-group-projection.ts`)
28+
* on every sign-in through the provider. A group is matched by its
29+
* `externalId` (for SSO: a claim value equal to it) when the row names one,
30+
* else by its `displayName`; the row names exactly one.
2831
*
2932
* @namespace sys
3033
*/
@@ -68,16 +71,19 @@ export const SysIdpGroupMapping = ObjectSchema.create({
6871
label: 'Source Kind',
6972
required: true,
7073
defaultValue: 'scim',
71-
description: 'What pushes the group: a SCIM connection.',
74+
description: 'What sends the group: a SCIM connection, or an SSO provider at sign-in.',
7275
group: 'Source',
73-
options: [{ value: 'scim', label: 'SCIM Connection' }],
76+
options: [
77+
{ value: 'scim', label: 'SCIM Connection' },
78+
{ value: 'sso', label: 'SSO Provider' },
79+
],
7480
}),
7581

7682
source_id: Field.text({
7783
label: 'Source ID',
7884
required: true,
7985
maxLength: 255,
80-
description: 'The SCIM connection ID the group arrives through, e.g. "okta-prod".',
86+
description: 'The SCIM connection ID or the SSO provider ID the group arrives through, e.g. "okta-prod".',
8187
group: 'Source',
8288
}),
8389

@@ -109,7 +115,7 @@ export const SysIdpGroupMapping = ObjectSchema.create({
109115
label: 'Organization',
110116
required: false,
111117
maxLength: 255,
112-
description: 'The organization the grant is made in: the organization that owns the SCIM connection.',
118+
description: 'The organization the grant is made in: the organization that owns the SCIM connection or the SSO provider.',
113119
group: 'Grant',
114120
}),
115121

‎packages/plugins/plugin-auth/src/auth-manager-plugin-list.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,27 @@ export async function buildPluginList(this: PluginListHost): Promise<any[]> {
770770
// OFF by default, so the vendor's own register / update-provider doors
771771
// write them. `saml` hands the vendor its one IdP-initiated option as a
772772
// getter that answers the ACS request's own provider.
773+
//
774+
// IdP group → permission set (the same ruling, item 3; `sso-group-projection.ts`):
775+
// every sign-in's group claim (`userInfo.groups`, filled by the provider's own
776+
// `mapping.extraFields.groups`) is matched against the provider's
777+
// `sys_idp_group_mapping` rows, the SCIM half's one model, and only ordinary
778+
// permission sets inside the organization boundary are granted. On EVERY
779+
// sign-in, so the grants follow the IdP's groups; a failure is logged and
780+
// never fails the sign-in.
781+
const { createSsoGroupProvisioner } = await import('./sso-group-projection.js');
773782
return sso({
774783
organizationProvisioning: { defaultRole: 'member' },
775784
...(enabled.ssoDomainVerification ? { domainVerification: { enabled: true } } : {}),
776785
saml: ssoSamlOptions(),
777786
schema: { ssoProvider: { additionalFields: SSO_PROVIDER_SIGN_IN_FIELDS } },
787+
provisionUser: createSsoGroupProvisioner({
788+
getEngine: () => this.getDataEngine(),
789+
boundary: async () => (await this.config.organizationBoundary?.().catch(() => undefined)) ?? undefined,
790+
warn: (message) => this.config.logger?.warn?.(message),
791+
error: (message) => this.config.logger?.error?.(message),
792+
}),
793+
provisionUserOnEveryLogin: true,
778794
});
779795
});
780796
}

‎packages/plugins/plugin-auth/src/auth-plugin.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4251,14 +4251,16 @@ export class AuthPlugin implements Plugin {
42514251
});
42524252

42534253
// [ADR-0134 D4, filled for permission sets] The identity-provider group
4254-
// mapping door: which ordinary permission set a SCIM connection's group
4255-
// grants. The same gate as the credential door above, then the save
4254+
// mapping door: which ordinary permission set a SCIM connection's group,
4255+
// or an SSO provider's sign-in group claim (ruling record 6718355623,
4256+
// item 3: the same mapping, no second model), grants. The same gate as the credential door above, then the save
42564257
// refuses any set outside the organization boundary (judged by the
42574258
// `security` service), so an IdP group never confers administrator
42584259
// standing. See `idp-group-mapping-admin.ts`.
42594260
const groupMappingDeps = (actor: PlatformAdminActor): import('./idp-group-mapping-admin.js').IdpGroupMappingAdminDeps => ({
42604261
getDataEngine: () => this.authManager!.getDataEngine(),
42614262
isScimEnabled: () => this.authManager!.isScimWired(),
4263+
isSsoEnabled: () => this.authManager!.isSsoWired(),
42624264
boundary: () => this.authManager!.organizationBoundaryJudge(),
42634265
reconcile: (domain) => this.authManager!.reconcileScimProjectionDomain(domain),
42644266
attributed: (fn) => runAttributedToUser(actor, fn),

‎packages/plugins/plugin-auth/src/auth-route-ledger.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ export const AUTH_ROUTE_LEDGER: readonly AuthRouteLedgerEntry[] = [
254254
// #16678 note below.
255255
{ route: 'POST /api/v1/auth/admin/scim/mint-credential', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', requires: 'scim', note: 'no SDK method builds this URL — an operator script or the identity-provider setup posts it; mints the bearer a SCIM connection authenticates with (scim-connection-service.ts) and answers the plaintext once, Cache-Control: no-store — only its keyed one-way digest is stored, and nothing logs it; refused 503 SERVICE_UNAVAILABLE while SCIM is off; one sys_audit_log row per mint naming the admin and the connection, never the credential; platform-admin gated (ADR-0068), ADR-0134' },
256256
{ route: 'POST /api/v1/auth/admin/scim/revoke-credential', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — an operator script posts it with the credentialId the mint answered; switches that credential row inactive, so the SCIM verifier refuses its bearer from the next request on (rotation is a second mint for the same connection, then this); 404 for an unknown credential, 409 when already revoked; one sys_audit_log row per revoke naming the admin and the connection; served whether or not SCIM is on; platform-admin gated (ADR-0068), ADR-0134' },
257-
{ route: 'POST /api/v1/auth/admin/scim/set-group-mapping', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', requires: 'scim', note: 'no SDK method builds this URL — an operator script posts it; saves one sys_idp_group_mapping row (a SCIM connection group, by externalId or displayName, to one permission set in the connection organization) and re-projects the connection so current members gain it; refused 400 VALIDATION_FAILED on permissionSet for any set outside the organization boundary (administrator sets, agent ceilings, superuser wildcards, adminScope, non-organization capabilities), judged by the security service; a re-save of the same group and set is idempotent in the connection organization, and refused 409 RESOURCE_CONFLICT naming the old mapping when that row lives in another organization (delete it first); 503 while SCIM or the security service is absent; one sys_audit_log row per save; platform-admin gated (ADR-0068), ADR-0134 D4' },
258-
{ route: 'POST /api/v1/auth/admin/scim/delete-group-mapping', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — an operator script posts it with the mappingId the save answered; deletes that sys_idp_group_mapping row and re-projects the connection so the grants it made go (with SCIM off nothing is re-projected and those grants stay until removed by hand; the answer says reprojected: false); 404 for an unknown mapping; one sys_audit_log row per delete; platform-admin gated (ADR-0068), ADR-0134 D4' },
257+
{ route: 'POST /api/v1/auth/admin/scim/set-group-mapping', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — an operator script posts it; saves one sys_idp_group_mapping row (a group, by externalId or displayName, to one permission set) for a SCIM connection (connectionId: in the connection organization, re-projected at once so current members gain it) or an SSO provider (providerId: in the provider organization, applied at each member next sign-in through that provider, from the userInfo.groups the provider mapping.extraFields fills; the answer says reprojected: false); exactly one of connectionId / providerId; refused 400 VALIDATION_FAILED on permissionSet for any set outside the organization boundary (administrator sets, agent ceilings, superuser wildcards, adminScope, non-organization capabilities), judged by the security service; a re-save of the same group and set is idempotent in the connection organization, and refused 409 RESOURCE_CONFLICT naming the old mapping when that row lives in another organization (delete it first); 503 while SCIM (connectionId), SSO (providerId) or the security service is absent; one sys_audit_log row per save; platform-admin gated (ADR-0068), ADR-0134 D4' },
258+
{ route: 'POST /api/v1/auth/admin/scim/delete-group-mapping', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — an operator script posts it with the mappingId the save answered; deletes that sys_idp_group_mapping row; a SCIM mapping re-projects the connection so the grants it made go (with SCIM off nothing is re-projected and those grants stay until removed by hand; the answer says reprojected: false), an SSO mapping removes at once the grants its provider projected for that set in that organization unless another of the provider mappings still names it (then each member next sign-in decides); 404 for an unknown mapping; one sys_audit_log row per delete; platform-admin gated (ADR-0068), ADR-0134 D4' },
259259
{ route: 'POST /api/v1/auth/admin/sso/register', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', requires: 'sso', note: 'no SDK method builds this URL — the sys_sso_provider register action posts flat form fields; ObjectStack bridge re-dispatching into @better-auth/sso /sso/register, platform-admin gated ahead of the delegation (ADR-0068 D4), so registering an identity provider never rests on the vendor\'s own check alone. Distinct path from the vendor\'s own /sso/register, which the catch-all serves' },
260260
{ route: 'POST /api/v1/auth/admin/sso/register-saml', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', requires: 'sso', note: 'no SDK method builds this URL — the sys_sso_provider register_saml_provider action posts flat fields the bridge reshapes into better-auth\'s nested samlConfig; platform-admin gated ahead of the delegation (ADR-0068 D4), ADR-0069 P3' },
261261
{ route: 'POST /api/v1/auth/admin/sso/request-domain-verification', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', requires: 'sso', note: 'no SDK method builds this URL — the sys_sso_provider action posts it and renders the returned DNS TXT record; ObjectStack bridge over @better-auth/sso, additionally gated on the opt-in ssoDomainVerification switch (OS_SSO_DOMAIN_VERIFICATION) — off means the inner endpoint 404s, the mount itself is unconditional; platform-admin gated (ADR-0068 D4), ADR-0135 D6' },

0 commit comments

Comments
 (0)