Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
96f3de5
feat(plugin-auth): project the SCIM enterprise manager onto sys_user.…
claude Nov 16, 2026
2f59626
docs(lint): grade SCIM as a route that populates sys_user.manager_id
claude Nov 16, 2026
22baa5e
test(plugin-auth): pin the SCIM manager projection end to end
claude Nov 16, 2026
df5795f
test(plugin-auth): pin that an unchanged SCIM manager is not judged a…
claude Nov 16, 2026
6b34a6b
chore: changesets for the SCIM manager projection
claude Nov 16, 2026
a5f9766
fix(plugin-auth): carry the refusal's ADR-0112 code on the SCIM manag…
claude Nov 16, 2026
64633db
fix(plugin-auth): keep the SCIM error body a literal the code pin reads
claude Nov 16, 2026
ad6c98f
Merge remote-tracking branch 'origin/main' into claude/area-A1-33918
claude Nov 16, 2026
bec3326
refactor(plugin-auth): one shared write of sys_user.manager_id for th…
claude Nov 16, 2026
774391e
Merge remote-tracking branch 'origin/main' into claude/area-A1-33918
claude Nov 16, 2026
585cf6e
feat(plugin-auth)!: serve an unresolvable SCIM manager reference, pro…
claude Nov 16, 2026
e619979
test(plugin-auth): read the admin route's refusal by its own fields
claude Nov 16, 2026
345781c
test(plugin-auth): clear and re-apply a manager through a replace, wh…
claude Nov 16, 2026
165b161
feat(plugin-auth,plugin-audit): an unresolvable SCIM manager referenc…
claude Nov 16, 2026
4958560
chore: changesets for the scim_manager_unresolved audit row
claude Nov 16, 2026
94c33dc
docs(approvals): an unresolvable SCIM manager reference also leaves a…
claude Nov 16, 2026
fa75b59
fix(plugin-auth): stamp each SCIM manager refusal code as a literal, …
claude Nov 16, 2026
c659399
i18n(plugin-audit): label scim_manager_unresolved in every shipped lo…
claude Nov 16, 2026
50a7e17
test(plugin-auth): reach the door's reference cap through a long $ref…
claude Nov 16, 2026
dcf1984
test(plugin-auth): a manager.value past 256 characters is the vendor'…
claude Nov 16, 2026
4c0b0ff
test(plugin-auth): pin the unchanged-manager short-circuit on a repla…
claude Nov 16, 2026
317c495
fix(plugin-auth): serve a manager reference whose platform user is go…
claude Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/33918-lint-scim-manager-route.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/lint': patch
---

docs(lint)!: `os explain approval-approvers-may-resolve-empty` names SCIM as a route that populates `sys_user.manager_id`

Clause-②: yes (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) This package changes explanation text only: no key of any authorable schema and no stored row changes, so there is nothing for `objectstack migrate meta` to rewrite. The narrowing it describes is plugin-auth's SCIM answer, declared in that package's note. -->

**BREAKING** in the behaviour this text now describes, not in the lint package: a SCIM user write whose named manager would make the user their own manager, close a cycle, run past the depth cap or cross an organization boundary was served before and is now refused with SCIM `400 invalidValue` (plugin-auth's note has the details). The lint rule and its findings are unchanged.

The `manager` arm's remedy said the platform declares the SCIM `manager` attribute without projecting it onto the column. plugin-auth now projects it, so the remedy says that the Enterprise User `manager` attribute, whose value is the manager's SCIM resource id, is written onto the column for an active user a SCIM directory holds, from the connection that provisioned that user's profile, on a create, replace or patch that names the attribute, through the admin operation's refusals. A write that does not name it leaves the column as it is, and an id naming no existing user the connection provisioned is served with the column unchanged. Any other directory sync is still named as something your own deployment supplies.
31 changes: 31 additions & 0 deletions .changeset/33918-scim-manager-projection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
'@objectstack/plugin-auth': patch
---

feat(plugin-auth)!: a SCIM directory sets, changes and clears a user's manager through the Enterprise User `manager` attribute

Clause-②: yes (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) No key of any authorable schema is added, removed, renamed or re-shaped and no stored row changes shape: what moves is the answer a SCIM user write gets when the manager it names would be refused by the admin endpoint. There is nothing for `objectstack migrate meta` to rewrite; the identity provider's manager mapping is corrected in the directory. -->

**BREAKING** for a SCIM identity provider that sends a manager the admin endpoint would refuse. A SCIM create, replace or patch that names the Enterprise User `manager` attribute, for an active user the directory holds, whose manager resolves to a User the same connection provisioned, and where that link would make the user their own manager, close a cycle, run past the 20-link depth cap, or cross an organization boundary, used to answer `201` / `200` and leave `manager_id` untouched. It now answers SCIM `400` with `scimType: invalidValue` and the admin endpoint's reason, and nothing of the request is written. Those four are the only requests served before and refused now. Remedy: correct the manager in the directory.

**On upgrade.** An identity provider that syncs by replace and maps no manager clears, on its next sync, a `manager_id` set earlier for a user the directory holds, because a replace without the attribute is a clear. Map the manager attribute in the identity provider before upgrading if those values should stay.

**The gap.** `POST /api/v1/auth/admin/set-user-manager` refuses a person a SCIM directory holds and says to change the manager in the directory, but nothing carried the directory's answer to `sys_user.manager_id`: `@better-auth/scim` stored and echoed `urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:manager` and wrote nothing of it onto the user. So a SCIM-held user's manager could not change from either side, and approvals routed to the manager could not follow a reorganisation.

**The rule.** A SCIM user write that names the attribute now projects `manager.value` onto `sys_user.manager_id`, inside the SCIM transaction. `manager.value` is the manager's SCIM resource `id` (RFC 7643 §4.3), looked up among the Users the same connection provisioned; a `$ref` alone is read by its final `/Users/{id}` segment. The link goes through the admin endpoint's own refusals, above.

- **Silence is not a clear.** A create or PATCH that does not name the attribute leaves `manager_id` as it is. An explicit PATCH `remove`, or a replace without the attribute, clears it.
- **One owner per identity.** The projection writes only on an identity whose manager the directory owns, which is exactly the set the admin endpoint refuses (one shared predicate). On any other identity, for example one holding a local password, the admin endpoint owns the column and the projection writes nothing.
- **A reference that names no User is served.** An unknown id, an `externalId` or email, another connection's id, a `$ref` with no readable `/Users/{id}` segment, or a User of this connection whose platform user no longer exists does not fail the write: the user is saved, `manager_id` stays as it was, and the event is recorded with one operator warning and one `scim_manager_unresolved` audit row (when `@objectstack/plugin-audit` is installed), both once per connection per window, carrying the count held back. The row names the connection, the user and the reference, cut to 256 characters, and nothing else from the request; a request that is refused writes none.
- **An unchanged manager is not judged again**, so a write is never refused over a chain other links have since reshaped, and a report whose manager was deleted keeps working.

**Where it does not project, and why.**

- Outside an authenticated SCIM request: the vendor also runs this step while it decommissions a connection or replays a provisioning domain. Neither is a write the directory made, and a decommission must never be refused over an org-chart reference.
- When the user's profile source belongs to another connection: that connection authors the user's name and email, so its manager is the one that counts, not this request's.
- For an inactive user: a deprovision is never refused over the org chart. A manager named while the user is inactive is not applied on re-activation alone; it lands on the next replace, or on a patch that changes it. (`@better-auth/scim` calls the host only when a PATCH changes what it stores, so a patch that re-sends the same value, or removes an attribute the directory never sent, writes nothing; a replace always reaches the projection.)

The `idp_provisioned` stamp (ADR-0135 D4) is unchanged.
20 changes: 20 additions & 0 deletions .changeset/33918-scim-manager-unresolved-audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/plugin-audit': patch
---

feat(plugin-audit)!: `sys_audit_log` records a SCIM user write whose Enterprise `manager` reference names no user, as one bounded `scim_manager_unresolved` row

Clause-②: yes (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) This package adds one ledger action and its writer: no key of any authorable schema is added, removed, renamed or re-shaped and no stored row changes shape, so there is nothing for `objectstack migrate meta` to rewrite. The narrowing the PR declares is plugin-auth's SCIM answer, described in that package's note. -->

**BREAKING** in the SCIM behaviour this row belongs to, not in this package: plugin-auth now refuses with SCIM `400 invalidValue` a manager link the admin endpoint would refuse (self, cycle, depth cap, cross-organization); plugin-auth's note has the details. Nothing this package already wrote or read changes.

**The new row.** `sys_audit_log.action` gains `scim_manager_unresolved` (label "SCIM Manager Unresolved"), written by the SCIM writer on the `audit` slot (`recordScimManagerUnresolved`, beside `recordScimRefusal`, through the same insert). plugin-auth hands it one event when a SCIM user write it served named an Enterprise User `manager` whose reference resolves to no user that connection provisioned: the write is saved, `manager_id` is left as it was, and the event is recorded with one operator warning and this row.

- **Bounded rate.** The row and the warning share one admission: one per SCIM connection per 10-minute window. The next row carries the number held back in between as `metadata.suppressed`. The admission happens inside the SCIM transaction, before the answer is known: a request refused after its reference was admitted still logs the warning and spends the window, so the next served unresolvable reference in that window is counted only in `suppressed`.
- **Bounded content.** `actor` is the connection's service principal (`svc:scim:CONNECTION_ID`), `object_name` / `record_id` the `sys_user` the write was about, `tenant_id` the connection's organization, and `metadata` holds `scim_connection_id`, `reference_kind` (`id` or `unreadable`) and `manager_reference`, the reference as the directory sent it, cut to 256 characters (`manager_reference_truncated: true` when it was longer). Nothing else from the request or the user is recorded.
- **Only served writes.** A refused request writes no such row (its `scim_refused` row is unchanged), and the row is written after the response, outside the SCIM transaction.

Find them in the Audit Log under the "SCIM Manager Unresolved" action, or on the user's own audit history.
20 changes: 13 additions & 7 deletions content/docs/automation/approvals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,19 @@ file exists, through the same refusals as the endpoint above, and reports each o
row's `manager` result: a link it cannot make never fails the user it imported.

The column is also written by a seed, or by any other system-context write, which bypasses the
managed-update whitelist. SCIM provisioning and directory sync can populate it too, but only
through a provisioning path your own deployment supplies: this platform declares the SCIM
`manager` attribute without projecting it onto the column. Where a SCIM directory holds an
identity (it carries `source: 'idp_provisioned'` and the directory has provisioned or linked it)
the admin operation **refuses**, the import's `manager_id` column included, so that directory
stays the one surface that authors its manager; for such a user the column is written only by that
deployment-supplied path, and a value the column already holds stays as it is. A person who only
managed-update whitelist. SCIM provisioning populates it too: the Enterprise User `manager`
attribute, whose `value` is the manager's SCIM resource `id`, is written onto the column on a SCIM
create, replace or patch that names the attribute, through the same refusals (each answered as a
SCIM `400 invalidValue`). It is written only for an active user the directory holds, and only from
the connection that provisioned that user's profile. A write that does not name the attribute
leaves the column as it is; removing the attribute, or a replace without it, clears the column. An
id that names no existing user the connection provisioned does not fail the write: the user is saved, the
column stays as it was, and the server logs a warning for the operator and records a
`scim_manager_unresolved` row in the audit log, naming the connection, the user and the reference, once per
connection per ten minutes. Where a SCIM directory holds an identity (it carries `source: 'idp_provisioned'` and
the directory has provisioned or linked it) the admin operation **refuses**, the import's
`manager_id` column included, so that directory stays the one surface that authors its manager.
Any other directory sync writes it only through a path your own deployment supplies. A person who only
signs in through SSO also carries `source: 'idp_provisioned'`, but no directory holds them: their
manager is set with **Set Manager** or the import like anyone else's.

Expand Down
5 changes: 3 additions & 2 deletions content/docs/capabilities/approvals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ A specific person · everyone holding a position (e.g. sales managers) · the su
admin sets it one user at a time from **Setup → Users → ⋯ → Set Manager**, which calls
`POST /api/v1/auth/admin/set-user-manager` — for anyone, people who sign in through SSO included,
except a person a SCIM directory holds, whose manager is changed in that directory. For many users at once, provisioning fills it: the
admin bulk-import endpoint reads a `manager_id` column, and a seed, or a SCIM / directory-sync
path your deployment supplies, can write it too. Until it is set, a manager-only approval step
admin bulk-import endpoint reads a `manager_id` column, SCIM provisioning writes it from the
Enterprise User `manager` attribute, and a seed, or a directory-sync path your deployment
supplies, can write it too. Until it is set, a manager-only approval step
resolves to nobody and the node's `onEmptyApprovers` policy decides what happens — by default the
request opens and waits for an administrator. The details, and the fallback that needs no manager
data at all, are in [Automation → Approvals](/docs/automation/approvals).
Expand Down
18 changes: 11 additions & 7 deletions packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3333,13 +3333,17 @@ const MANAGER_ONLY_ROUTES =
'an existing user — and links each row once every row in the file exists, through those same ' +
'refusals; a link it cannot make is reported on that row\'s manager result and never fails the ' +
'user it imported. The column is also written by a seed, or by any other system-context ' +
'write, which bypasses the managed-update whitelist. SCIM provisioning and directory sync can ' +
'populate it too, but only through a provisioning path your own deployment supplies: this ' +
'platform declares the SCIM \'manager\' attribute without projecting it onto the column — and ' +
'where a SCIM directory holds an identity the admin operation refuses, the import\'s ' +
'manager_id column included, leaving that directory the one surface that authors its ' +
'manager. An identity that only signs in through SSO, with no SCIM directory behind it, is set ' +
'through the admin operation like any other. Or declare onEmptyApprovers: \'fallback\' on the node, with a ' +
'write, which bypasses the managed-update whitelist. SCIM provisioning populates it too, for an ' +
'active user a SCIM directory holds and only from the connection that provisioned that user\'s ' +
'profile: the Enterprise User \'manager\' attribute, whose value is the manager\'s SCIM resource ' +
'id, is written onto the column on a SCIM create, replace or patch that names the attribute, ' +
'through those same refusals. A write that does not name it leaves the column as it is, and an ' +
'id that names no existing user the connection provisioned is served and leaves the column unchanged. ' +
'Where a SCIM directory holds an identity, the admin operation refuses it, the import\'s ' +
'manager_id column included, leaving that directory the one surface that authors its manager. Any other directory sync ' +
'populates it only through a provisioning path your own deployment supplies. An identity that ' +
'only signs in through SSO, with no SCIM directory behind it, is set through the admin ' +
'operation like any other. Or declare onEmptyApprovers: \'fallback\' on the node, with a ' +
'fallbackApprovers list: an empty manager rung then opens the request on those people instead ' +
'of on the organization\'s administrators, which needs no write to the column at all.';

Expand Down
9 changes: 6 additions & 3 deletions packages/lint/src/validate-approval-approvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,19 @@ describe('unset-manager dead-end (#16748)', () => {
// ⛔ The one that is NOT this repo's to offer must be marked as the
// deployment's own, and the hint must say WHY rather than merely hedging.
expect(remedy).toContain('a provisioning path your own deployment supplies');
expect(remedy).toContain("declares the SCIM 'manager' attribute without projecting it");
// SCIM is no longer among them: its `manager` attribute is projected onto
// the column (plugin-auth `scim-manager-projection.ts`).
expect(remedy).not.toContain('without projecting it');
expect(remedy).toContain("Enterprise User 'manager' attribute, whose value is the manager's SCIM resource id");

// ⛔ And they must not be deleted: a deployment running a real directory
// sync may well populate the column, and the defect was presenting all
// three as equally available, never naming them at all. They now also take
// PRECEDENCE — the endpoint refuses an identity a SCIM directory holds, and
// so does the import's `manager_id` column, which runs the same derivation —
// so the hint must not read as "use the endpoint instead of your directory".
expect(remedy).toContain('SCIM provisioning and directory sync can populate it');
expect(remedy).toContain('where a SCIM directory holds an identity the admin operation refuses');
expect(remedy).toContain('SCIM provisioning populates it too');
expect(remedy).toContain('Where a SCIM directory holds an identity, the admin operation refuses it');
expect(remedy).toContain("the import's manager_id column included");
// ⛔ But only where a directory exists: the `idp_provisioned` mark alone
// also covers a person who only signs in through SSO, whose manager the
Expand Down
34 changes: 23 additions & 11 deletions packages/lint/src/validate-approval-approvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,23 @@ const STAYS_LOCKED = ', and (lockRecord) the record stays locked';
* `system-write-guard.ts`, plugin-auth `identity-write-guard.ts`). A
* system-context write therefore bypasses the managed-update whitelist by
* construction.
* - SCIM — NOT here, re-measured and unchanged. The Enterprise `manager`
* attribute IS declared (`scim.zod.ts`), but no non-test file under
* `packages/plugins` or `packages/runtime` projects it onto the column:
* measured 0, against a control (`SysScimGroup`) the same scan does find,
* so the scan discriminates.
* - SCIM — AVAILABLE HERE, and the grade this block used to give it ("NOT
* here, 0 projection sites") went stale when the projection landed.
* plugin-auth `scim-manager-projection.ts` carries the Enterprise User
* `manager.value` — the manager's SCIM resource id among the Users the
* same connection provisioned (RFC 7643 §4.3) — onto the column, inside
* the SCIM transaction, through the endpoint's own refusals
* (`screenUserManagerLink`: self-assignment, cycle, depth cap,
* cross-organization, each a SCIM 400 `invalidValue`). It runs only for
* an ACTIVE user whose manager the directory owns (the one predicate the
* endpoint's directory refusal reads), only from the connection that
* holds that user's profile source, and only on a create, replace or
* patch that NAMES the attribute: a write that does not name it leaves
* the column as it is, and an explicit remove (or a replace without it)
* clears it. A reference naming no User is served with the column left
* unchanged and a bounded operator warn (maintainer ruling record
* 6909383114). Measured by `scim-manager-projection.test.ts`, end to end
* through the vendor.
* - Admin bulk import — AVAILABLE HERE, and the grade this block used to
* give it ("NOT here") went stale when the import tier admitted the column.
* `POST /api/v1/auth/admin/import-users` (`admin-import-users.ts`) reads a
Expand All @@ -178,12 +190,12 @@ const STAYS_LOCKED = ', and (lockRecord) the record stays locked';
* It is the route to name for a whole file; a remedy that said otherwise
* sent the author away from a supported path.
*
* ⇒ SCIM and directory sync stay NAMED, because a deployment running a real
* one may well populate the column through it — but named as something the
* operator's own provisioning supplies, ⛔ never as something this repo gives
* them. They also now have PRECEDENCE over the endpoint rather than merely
* sitting beside it: on an identity a SCIM directory holds the endpoint refuses, so
* the directory is the one authoring surface for those rows.
* ⇒ SCIM is NAMED as a route this repo gives, with PRECEDENCE over the
* endpoint rather than beside it: on an identity a SCIM directory holds the
* endpoint refuses, so the directory's `manager` attribute is the one
* authoring surface for those rows. Any other directory sync stays named as
* something the operator's own provisioning supplies, ⛔ never as something
* this repo gives them.
*
* ⛔ WHAT DID NOT CHANGE — and why this rule is not deleted. The dead end the
* finding reports SURVIVES the write surface: a static check still cannot read
Expand Down
Loading
Loading