Skip to content

Commit 4e55e4e

Browse files
fix(plugin-auth)!: deleting an SSO provider ends the sessions a sign-in through it opened and removes its projected grants (#36173)
Clause-②: no (narrowing) Metadata-protocol: none Skills-docs: none — no published skill teaches deleting an SSO provider, its sessions or its projected grants; the rule is documented in `content/docs/permissions/sso.mdx` ("Deleting an SSO provider") ## 维护者速读 - 管理员删除一个企业单点登录提供方后,经它登录的用户的在线会话随之结束;其他方式登录的会话不受影响。 - 安全加固:删除身份提供方即收回它所担保的访问(安全席位的无卡派单)。 - 若出错,经该提供方登录的用户会被要求重新登录;改动可直接撤回,会话表多出的一列不影响旧版本。 - 要你做的事:无(合同层审核归安全席位)。 ## What changes Rule: **deleting an SSO provider ends the sessions a sign-in through it opened and removes its projected grants.** 1. **Sessions.** Each session an SSO sign-in opens (OIDC or SAML, SP- or IdP-initiated, new or returning user) records the provider it was signed in through, in a new read-only, system-managed column `sys_session.sso_provider_id`. After `POST /api/v1/auth/sso/delete-provider` succeeds, the live sessions that record the deleted provider are revoked in place (`revoke_reason: 'sso_provider_deleted'`), the same shape every other revocation writes. A session signed in any other way is left as it is; a delete the vendor refuses ends nothing. 2. **The delete's answer** carries `revokedSessions` beside the other counts, and its `message` says it. 3. **Projected grants of a provider that no longer exists are removed at every boot**, as are live sessions recording such a provider. The delete already removes its own projected grants at delete time (unchanged, on `main` since the SSO provider lifecycle landed); the boot sweep settles what a provider with no `sys_sso_provider` row left behind. It reads only marker grants and stamped live sessions, re-reads the provider rows after reading the candidates (a provider registered mid-sweep keeps its own), and logs at `info` what it removed and at `error` (with the remedy) when it could not. **Bounded batches.** Every revoke and removal is written in batches of at most 500 rows, walked in id order (keyset paging), so the rule holds for any number of sessions or grants; a batch that fails is logged at `error` with the remedy, and the next boot's sweep ends what remains. **Boot sweep, not one-shot backfill — chosen by measurement:** - A path that leaves a projected grant behind once the provider row is gone still exists after this change: a delete whose cleanup fails after the vendor's own delete succeeded (`dependentsRemoved: false`). A one-shot backfill would leave those for good; the pin "what a delete whose cleanup failed left behind is removed at the next boot" shows the sweep settling it. - Cost, measured on better-sqlite3 with 20,000 grants (10% projected, all by live providers) and 10,000 sessions (half stamped): a sweep with nothing to remove takes median 5.3 ms over 5 runs (min 4.2, max 17.5) and does 3 reads; removing 1,000 grants of a gone provider took 0.9 s, once. - Neither changes product behaviour beyond the two rules: the sweep removes only what rule 2 (and rule 1 for sessions) already says must not exist. **Where the producer lives.** The rule lands in `packages/plugins/plugin-auth` (lifecycle, sign-in seams, boot hook). One file outside it: `packages/platform-objects/src/identity/sys-session.object.ts` declares the new column (plus its index and the `sso_provider_deleted` revoke reason in the published vocabulary), because `sys_session` is declared there; its translation bundles are regenerated and the new label translated. The tenant-audit census page for plugin-auth is regenerated for the two new session writes, both stating their system context. Not touched: `client-address.ts` and `objectql-adapter.ts` (other in-flight work). ## Tests - `src/sso-saml-refusal-landing.test.ts` — new top-level describe on the real SAML end-to-end harness (real `AuthManager`, real `sso()` plugin, the IdP played with the vendor's own `samlify`): two providers, a new and a returning sign-in through one, a sign-in through the other, a real delete through the vendor's door. Pins that the first provider's sessions end (with the reason and the count in the answer) and the other provider's session stays; a control where the vendor refuses the delete and nothing ends. The sign-in helper gained an optional `providerId` (default unchanged). - `src/sso-provider-lifecycle.test.ts` (real ObjectQL over better-sqlite3, real `AuthPlugin` boot hooks): - the delete door revokes the provider's live sessions; an already-ended one keeps its own reason; another provider's and a password session stay; - at boot, grants of a provider with no row are removed while a live provider's, one by hand and a SCIM one stay; - at boot, live sessions of a gone provider are revoked while another provider's, an unstamped one and an ended one stay as they are; - a provider registered while the sweep runs keeps what its sign-ins wrote; - what a delete whose cleanup failed left behind is removed at the next boot; - the existing delete-answer pin now includes `revokedSessions`. - `src/sso-session-provider.test.ts` (new) — which sign-in source names a provider; the settle writes once on the session its request minted; a control for another request or a non-SSO sign-in; a write failure is said once at `error` naming the provider and the session, and the sign-in is not failed. ## Acceptance notes - The preflight (`GET /admin/sso/delete-impact`, the delete action's confirmation) still counts users, mappings and grants only; the session count appears in the delete's own answer. Adding it to the preflight is a separate UX change, not done here. - L2 contract-tier review is owed to the security seat. ## Verification **Current head `4beed2475`:** the three SSO suites 152/152 and the lifecycle file 48/48 (seat's contract-tier delta read, from a `git archive` export); pins at the bulk ceiling + 1 for the delete-time revoke and the boot sweep are red on the previous head and green here; CI green. Earlier rounds below: Local runs on `6a7ee0ae` unless a row names another commit. - Red on base (`dc10b3b4`): rule 1 pin — 1 failed (the assertion after a 200 delete); rule 2 pin — 1 failed (2 grants left that the rule removes). Green after. - Guard ablation (each: mutation proven on disk by `scripts/ablation-replace.mjs`, then restored to the HEAD blob with `git diff HEAD` empty): 6 guards — staging the provider at sign-in, settling it on the session, revoking at delete, the boot hook, the mid-sweep provider re-read, the liveness filter on revocation — each turned its pin red (1 or 3 failed) and green on restore. Two guards first stayed green (no pin reached them); the two pins above were added and both then went red under ablation. - Package suites: `@objectstack/plugin-auth` 292/292 files, 6194 passed, 10 skipped; `@objectstack/platform-objects` 125/125 files, 2117 passed. Typecheck of both packages: exit 0. - Gate union: the 111 families `node scripts/pm/dispatch-gates.mjs --commands` derives for this diff, each run locally on `6a7ee0ae` with its exit code captured before any pipe: 111 exit 0. `dispatch-gates --ran`: 111 derived, 111 run, 0 unrun. An earlier run on a previous head surfaced four findings, each fixed on this branch (translation bundles, the tenant-audit census, the optional error-sink contract, module-top loading in edited test files), and three prerequisite refusals cleared by building or fetching what they read. CI-only families are read from this pull request's check-runs. - Dogfood battery (narrowing arm): `6a7ee0ae` · lock VERDICT command-exit 0 · Test Files 483 passed, 3 skipped (486) · Tests 4101 passed, 68 skipped (4169) · no failures. **Read first (risk order):** `packages/plugins/plugin-auth/src/sso-provider-lifecycle.ts` (`sweepDeletedSsoProviderAccess`, `removeSsoProviderDependents`), `packages/plugins/plugin-auth/src/sso-session-provider.ts`, `packages/plugins/plugin-auth/src/auth-manager-database-hooks.ts` (the settle call in `session.create.after`). **Two-minute check:** `pnpm --filter @objectstack/plugin-auth exec vitest run src/sso-saml-refusal-landing.test.ts -t "deleting an identity provider"` — 2 passed. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes (CI). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: not touched. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. Dispatched as a no-card security order by `security#2 · sunhaolin · session_017xRBcW9L8Noz9BxEwjwiov`; developer session `session_017xRBcVBc1xrigvFwcDc9mc`. The draft was opened by the seat from the developer's payload (the developer's own relay write was refused by its session's permission check). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017xRBcVBc1xrigvFwcDc9mc <!-- signed: security#2 · sunhaolin · session_017xRBcW9L8Noz9BxEwjwiov --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 674f877 commit 4e55e4e

23 files changed

Lines changed: 1033 additions & 42 deletions

‎.changeset/sec2-ggfh.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
'@objectstack/platform-objects': patch
4+
---
5+
6+
fix(plugin-auth)!: deleting an SSO provider ends the sessions a sign-in through it opened and removes its projected grants
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: none
10+
Skills-docs: none — no published skill teaches deleting an SSO provider, its sessions or its projected grants; the rule is documented in `content/docs/permissions/sso.mdx` ("Deleting an SSO provider")
11+
12+
<!-- adr-0087: not-required (no-migration-prescription) No authorable key, value or export is added, removed, renamed or re-shaped. `sys_session` gains a system-managed, read-only column the platform writes itself, and what changes is which sessions and projected grants stay live once an SSO provider is gone: no stored metadata row, registry key or authored value moves, so there is nothing for a migration to rewrite. -->
13+
14+
**BREAKING** for a session a sign-in through an SSO provider opened: deleting that provider ends the session, and its next request is answered as signed out. Sessions opened any other way are not touched.
15+
16+
- **Sessions.** Each session an SSO sign-in opens records the provider it was signed in through, in the new read-only `sys_session.sso_provider_id` column. `POST /api/v1/auth/sso/delete-provider` revokes the live sessions that record the deleted provider (`revoke_reason: 'sso_provider_deleted'`). A session signed in any other way (a password, another provider) is left as it is, and a delete the vendor refuses ends nothing.
17+
- **The answer.** A successful delete's `data` carries `revokedSessions`, the number of live sessions it ended, beside the other counts, and its `message` says so.
18+
- **Projected grants.** A permission-set grant projected by an SSO provider's group mapping exists only while that provider does: the delete removes them, as before, and at every boot the grants whose `reason` names a provider with no `sys_sso_provider` row are removed too, as are live sessions recording such a provider. The boot does not remove the provider's group mappings (delete each with **Delete Mapping**, or `POST /api/v1/auth/admin/scim/delete-group-mapping`); it logs at `info` what it removed, and at `error`, with the remedy, when it could not. Several servers sweeping at once each remove what is left, and none reports the others' removals as a failure.

‎content/docs/permissions/sso.mdx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,41 @@ the next one applies the mappings again.
10111011

10121012
---
10131013

1014+
## Deleting an SSO provider
1015+
1016+
Deleting a provider ends the sessions a sign-in through it opened and removes
1017+
the permission-set grants its group mappings projected. Setup's **Delete SSO
1018+
Provider** (or `POST /api/v1/auth/sso/delete-provider` with
1019+
`{ "providerId": "…" }`) first shows what the delete removes, then:
1020+
1021+
- **unlinks** every user who signed in through the provider;
1022+
- **ends the live sessions signed in through it.** Each session an SSO sign-in
1023+
opens records its provider (`sys_session.sso_provider_id`); the delete
1024+
revokes the live sessions that record this provider, with `revoke_reason`
1025+
`sso_provider_deleted`, so their next request is signed out. A session signed
1026+
in any other way (a password, another provider) is left as it is;
1027+
- **removes its group mappings and the permission-set grants they projected**
1028+
(the grants whose `reason` is the provider's projection marker), never a grant
1029+
made by hand or by SCIM.
1030+
1031+
The answer names each count: `unlinkedUsers`, `usersWithoutOtherSignIn`,
1032+
`revokedSessions`, `removedGroupMappings` and `removedGrants`. When the cleanup
1033+
after the delete fails, the answer says so (`dependentsRemoved: false`) and the
1034+
failure is logged once at `error`.
1035+
1036+
**At every boot**, the projected grants and live sessions of a provider that no
1037+
longer exists are removed too: a projected grant whose `reason` names a
1038+
provider with no `sys_sso_provider` row is deleted, and a live session that
1039+
records such a provider is revoked. So the grants and sessions a failed cleanup
1040+
left are settled at the next start; the boot logs at `info` what it removed,
1041+
and at `error` when it could not. The boot does **not** remove the provider's
1042+
group mappings: delete each one with Setup's **Delete Mapping** on its row, or
1043+
`POST /api/v1/auth/admin/scim/delete-group-mapping` with `{ "mappingId": "…" }`.
1044+
Several servers booting at once may run the sweep together; each removes what is
1045+
left and none reports the others' removals as a failure.
1046+
1047+
---
1048+
10141049
## Verify configuration
10151050

10161051
Restart the server (`pnpm dev`), then:

‎docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins/plugin-auth.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ a row or a number here — fix the code, or the census, and regenerate.
1414

1515
| Measure | Value |
1616
|---|---:|
17-
| Write call sites | 106 |
18-
| Object name statically decidable | 58 |
17+
| Write call sites | 108 |
18+
| Object name statically decidable | 60 |
1919
| Object name chosen at run time | 48 |
2020
| Object name spelled inline | 47 |
21-
| Object name spelled through a `const` | 11 |
21+
| Object name spelled through a `const` | 13 |
2222
| Object name is an `object: string` parameter | 3 |
2323
| Object name is some other run-time expression | 45 |
24-
| Against a tenancy-enabled object | 56 |
24+
| Against a tenancy-enabled object | 58 |
2525
| Against an object declaring tenancy off | 2 |
26-
| Threading a tenant context | 62 |
26+
| Threading a tenant context | 64 |
2727
| Provably carrying none (options read, no context key) | 15 |
2828
| …and decidably tenancy-enabled | 3 |
2929
| Options argument unreadable | 29 |
3030
| …and decidably tenancy-enabled | 16 |
31-
| Threading a decidably elevated (`isSystem`) context | 44 |
31+
| Threading a decidably elevated (`isSystem`) context | 46 |
3232
| Threading a decidably non-elevated context | 0 |
3333
| Threading a context of undecidable elevation | 47 |
3434
| Receiver carried a readable engine type | 80 |
35-
| Receiver erased, placed by the object NAME | 24 |
35+
| Receiver erased, placed by the object NAME | 26 |
3636
| Receiver erased, placed by an `object: string` PARAMETER | 1 |
3737
| Receiver erased, placed by an `UNTYPED_RECEIVERS` row | 1 |
3838

@@ -125,7 +125,9 @@ a row or a number here — fix the code, or the census, and regenerate.
125125
| `packages/plugins/plugin-auth/src/session-tombstone.ts` | `update` | `objectName` | undecidable | options unreadable | 1 |
126126
| `packages/plugins/plugin-auth/src/sso-client-secret.ts` | `update` | `sys_sso_provider` | disabled | elevated | 1 |
127127
| `packages/plugins/plugin-auth/src/sso-provider-lifecycle.ts` | `delete` | `IDP_GROUP_MAPPING_OBJECT` | undecidable | PROVABLY NONE | 1 |
128+
| `packages/plugins/plugin-auth/src/sso-provider-lifecycle.ts` | `update` | `sys_session` | enabled | elevated | 1 |
128129
| `packages/plugins/plugin-auth/src/sso-provider-lifecycle.ts` | `delete` | `sys_user_permission_set` | enabled | elevated | 1 |
130+
| `packages/plugins/plugin-auth/src/sso-session-provider.ts` | `update` | `sys_session` | enabled | elevated | 1 |
129131
| `packages/plugins/plugin-auth/src/sys-session-revoke.ts` | `update` | `SystemObjectName.SESSION` | undecidable | elevated | 1 |
130132
| `packages/plugins/plugin-auth/src/user-ban-write.ts` | `update` | `sys_user` | enabled | context, elevation undecidable | 1 |
131133
| `packages/plugins/plugin-auth/src/user-session-admission.ts` | `update` | `sys_user` | enabled | elevated | 2 |

‎packages/platform-objects/src/apps/translations/ar.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ export const arObjects: NonNullable<TranslationData['objects']> = {
497497
label: "سبب الإلغاء",
498498
help: "سبب إلغاء الجلسة (idle_timeout، absolute_max، concurrent_cap، ip_not_allowed، user_revoked، admin، organization_membership_ended، admin_password_reset، password_reset، …)."
499499
},
500+
sso_provider_id: {
501+
label: "مزوّد SSO",
502+
help: "مزوّد SSO الذي سُجّل الدخول من خلاله في هذه الجلسة، إن وُجد. حذف ذلك المزوّد يُنهي الجلسة. يُدار من قِبل النظام."
503+
},
500504
active_organization_id: {
501505
label: "المؤسسة النشطة"
502506
},

‎packages/platform-objects/src/apps/translations/de.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ export const deObjects: NonNullable<TranslationData['objects']> = {
497497
label: "Widerrufsgrund",
498498
help: "Warum die Sitzung widerrufen wurde (idle_timeout, absolute_max, concurrent_cap, ip_not_allowed, user_revoked, admin, organization_membership_ended, admin_password_reset, password_reset, …)."
499499
},
500+
sso_provider_id: {
501+
label: "SSO-Anbieter",
502+
help: "Der SSO-Anbieter, über den diese Sitzung angemeldet wurde, falls vorhanden. Das Löschen dieses Anbieters beendet die Sitzung. Vom System verwaltet."
503+
},
500504
active_organization_id: {
501505
label: "Aktive Organisation"
502506
},

‎packages/platform-objects/src/apps/translations/en.objects.generated.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
495495
},
496496
revoke_reason: {
497497
label: "Revoke Reason",
498-
help: "Why the session was revoked (idle_timeout, absolute_max, concurrent_cap, ip_not_allowed, user_revoked, admin, organization_membership_ended, admin_password_reset, password_reset, …)."
498+
help: "Why the session was revoked (idle_timeout, absolute_max, concurrent_cap, ip_not_allowed, user_revoked, admin, organization_membership_ended, admin_password_reset, password_reset, sso_provider_deleted, …)."
499+
},
500+
sso_provider_id: {
501+
label: "SSO Provider",
502+
help: "The SSO provider this session was signed in through, if any. Deleting that provider ends the session. System-managed."
499503
},
500504
active_organization_id: {
501505
label: "Active Organization"

‎packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ export const esESObjects: NonNullable<TranslationData['objects']> = {
497497
label: "Motivo de la revocación",
498498
help: "Por qué se revocó la sesión (idle_timeout, absolute_max, concurrent_cap, ip_not_allowed, user_revoked, admin, organization_membership_ended, admin_password_reset, password_reset, …)."
499499
},
500+
sso_provider_id: {
501+
label: "Proveedor SSO",
502+
help: "El proveedor SSO a través del cual se inició esta sesión, si lo hay. Eliminar ese proveedor finaliza la sesión. Gestionado por el sistema."
503+
},
500504
active_organization_id: {
501505
label: "Organización activa"
502506
},

‎packages/platform-objects/src/apps/translations/fr.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ export const frObjects: NonNullable<TranslationData['objects']> = {
497497
label: "Motif de la révocation",
498498
help: "Pourquoi la session a été révoquée (idle_timeout, absolute_max, concurrent_cap, user_revoked, admin, organization_membership_ended, admin_password_reset, password_reset, …)."
499499
},
500+
sso_provider_id: {
501+
label: "Fournisseur SSO",
502+
help: "Le fournisseur SSO par lequel cette session a été ouverte, le cas échéant. Supprimer ce fournisseur met fin à la session. Géré par le système."
503+
},
500504
active_organization_id: {
501505
label: "Organisation active"
502506
},

‎packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ export const jaJPObjects: NonNullable<TranslationData['objects']> = {
497497
label: "失効理由",
498498
help: "セッションが失効した理由(idle_timeout、absolute_max、concurrent_cap、ip_not_allowed、user_revoked、admin、organization_membership_ended、admin_password_reset、password_reset など)。"
499499
},
500+
sso_provider_id: {
501+
label: "SSO プロバイダー",
502+
help: "このセッションのサインインに使われた SSO プロバイダー(ある場合)。そのプロバイダーを削除するとセッションは終了します。システム管理。"
503+
},
500504
active_organization_id: {
501505
label: "アクティブ組織"
502506
},

‎packages/platform-objects/src/apps/translations/ko.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ export const koObjects: NonNullable<TranslationData['objects']> = {
497497
label: "취소 사유",
498498
help: "세션이 취소된 이유입니다(idle_timeout, absolute_max, concurrent_cap, ip_not_allowed, user_revoked, admin, organization_membership_ended, admin_password_reset, password_reset, …)."
499499
},
500+
sso_provider_id: {
501+
label: "SSO 공급자",
502+
help: "이 세션이 로그인할 때 거친 SSO 공급자(있는 경우)입니다. 해당 공급자를 삭제하면 세션이 종료됩니다. 시스템에서 관리합니다."
503+
},
500504
active_organization_id: {
501505
label: "활성 조직"
502506
},

0 commit comments

Comments
 (0)