From 5c1f929a689ef8710c3af51a7d202d5049a076bd Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 00:30:53 +0000 Subject: [PATCH 01/16] test(plugin-auth): pin the membership doors on a cloud-managed environment Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .../plugin-auth/src/cloud-managed.test.ts | 111 ++++++++++++++++++ .../plugins/plugin-auth/src/cloud-managed.ts | 17 +++ 2 files changed, 128 insertions(+) diff --git a/packages/plugins/plugin-auth/src/cloud-managed.test.ts b/packages/plugins/plugin-auth/src/cloud-managed.test.ts index ca583317d6a..0af925d4fa0 100644 --- a/packages/plugins/plugin-auth/src/cloud-managed.test.ts +++ b/packages/plugins/plugin-auth/src/cloud-managed.test.ts @@ -799,6 +799,117 @@ describe('SSO-only mode keeps IdP-provisioned users off local passwords at the s }); }); +// ───────────────────────────────────────────────────────────────────────────── +// Membership and roles +// ───────────────────────────────────────────────────────────────────────────── + +/** + * On a cloud-managed environment the organisation that hosts it manages who + * is a member and with which role. The two doors that change a membership, + * `remove-member` and `update-member-role` (Make Owner sends the owner role to + * the second), refuse with the invite-member envelope and write nothing; the + * remove-member permission arm and the role-change grant read stay behind the + * refusal, so neither runs. `add-member`, platform-administrator only, stays + * open: it restores a membership the environment lost. Self-hosted, every door + * answers as before. + */ +describe('on a cloud-managed environment, membership and roles are managed by the hosting organisation', () => { + type Staged = Awaited>; + const memberships = (s: Staged) => + ((s.engine.tables.get('sys_member') ?? []) as any[]).filter((m) => m.organization_id === DEFAULT_ORG); + const membershipOf = (s: Staged, userId: string) => memberships(s).find((m) => String(m.user_id) === userId); + + /** The ordinary user's membership row, read before the case changes anything. */ + const memberRow = (s: Staged) => { + const row = membershipOf(s, s.ids.member); + expect(row, 'fixture invariant: the ordinary user holds a default-org membership').toBeDefined(); + expect(row.role, 'fixture invariant: as a plain member').toBe('member'); + return row; + }; + + type DoorPath = '/organization/remove-member' | '/organization/update-member-role'; + const DOORS: ReadonlyArray< + [string, DoorPath, 'removeMember' | 'updateMemberRole', (memberId: string) => Record] + > = [ + ['remove-member', '/organization/remove-member', 'removeMember', + (memberId) => ({ memberIdOrEmail: memberId, organizationId: DEFAULT_ORG })], + ['update-member-role', '/organization/update-member-role', 'updateMemberRole', + (memberId) => ({ memberId, role: 'admin', organizationId: DEFAULT_ORG })], + ['update-member-role to owner (Make Owner)', '/organization/update-member-role', 'updateMemberRole', + (memberId) => ({ memberId, role: 'owner', organizationId: DEFAULT_ORG })], + ]; + + it.each(DOORS)('%s answers 409 RESOURCE_CONFLICT to the owner, and the membership row is unchanged', async (_door, path, door, body) => { + const s = await stage(); + const row = memberRow(s); + const before = structuredClone(memberships(s)); + setManaged(true); + const v = await verdict(await s.fire(path, body(String(row.id)), s.bearers.admin)); + expectManagedRefusal(v, door); + expect(memberships(s)).toEqual(before); + }, 120_000); + + it.each(DOORS)('%s refuses ahead of the arms behind it: no permission judge runs and no grant read is taken', async (_door, path, _key, body) => { + const s = await stage(); + const row = memberRow(s); + const permissionJudge = vi.spyOn(s.manager, 'assertRemoveMemberPermitted'); + const grantRead = vi.spyOn(s.manager as any, 'roleChangeGrantDeps'); + setManaged(true); + const v = await verdict(await s.fire(path, body(String(row.id)), s.bearers.admin)); + expect(v.status, v.text).toBe(409); + expect(permissionJudge).not.toHaveBeenCalled(); + expect(grantRead).not.toHaveBeenCalled(); + }, 120_000); + + it.each(DOORS)('CONTROL: self-hosted, %s answers 200 and changes the membership as before', async (_door, path, _key, body) => { + const s = await stage(); + const row = memberRow(s); + const permissionJudge = vi.spyOn(s.manager, 'assertRemoveMemberPermitted'); + const grantRead = vi.spyOn(s.manager as any, 'roleChangeGrantDeps'); + const sent = body(String(row.id)); + const v = await verdict(await s.fire(path, sent, s.bearers.admin)); + expect(v.status, v.text).toBe(200); + if (path === '/organization/remove-member') { + expect(membershipOf(s, s.ids.member)).toBeUndefined(); + // The spy legs above are measured against arms that do run here. + expect(permissionJudge).toHaveBeenCalled(); + } else { + expect(membershipOf(s, s.ids.member)?.role).toBe(sent.role); + expect(grantRead).toHaveBeenCalled(); + } + }, 120_000); + + it('CONTROL: add-member still answers a platform administrator, and restores a membership the environment lost', async () => { + const s = await stage(); + const row = memberRow(s); + s.engine.tables.set( + 'sys_member', + ((s.engine.tables.get('sys_member') ?? []) as any[]).filter((m) => m.id !== row.id), + ); + expect(membershipOf(s, s.ids.member)).toBeUndefined(); + setManaged(true); + const v = await verdict( + await s.fire('/organization/add-member', { userId: s.ids.member, role: 'member', organizationId: DEFAULT_ORG }, s.bearers.admin), + ); + expect(v.status, v.text).toBe(200); + expect(membershipOf(s, s.ids.member)?.role).toBe('member'); + }, 120_000); + + it('CONTROL: invite-member keeps its own refusal, not a membership one', async () => { + const s = await stage(); + setManaged(true); + const v = await verdict( + await s.fire('/organization/invite-member', { + email: 'newcomer.membership@example.com', + role: 'member', + organizationId: DEFAULT_ORG, + }, s.bearers.admin), + ); + expectManagedRefusal(v, 'invitation'); + expect(s.invitationsOf('newcomer.membership@example.com')).toHaveLength(0); + }, 120_000); +}); + describe('[#25083] what a host that mounts its own twin of a door imports', () => { // The cloud mounts a per-environment twin of `set-initial-password` // (objectstack-ai/cloud#3169). It takes the same arm from the package entry, diff --git a/packages/plugins/plugin-auth/src/cloud-managed.ts b/packages/plugins/plugin-auth/src/cloud-managed.ts index 857ae5f94e5..b56123847d6 100644 --- a/packages/plugins/plugin-auth/src/cloud-managed.ts +++ b/packages/plugins/plugin-auth/src/cloud-managed.ts @@ -30,6 +30,14 @@ * break-glass clause, which kept a local credential reachable by population, * holds on self-hosted deployments only. * + * Membership and membership roles are the hosting organisation's too: the two + * doors that change them, `/organization/remove-member` and + * `/organization/update-member-role` (Make Owner included, which sends the + * owner role to it), refuse every request, as `/organization/invite-member` + * does. A change made here would hold in the environment alone. The one door + * left open is `/organization/add-member`, platform-administrator only: it is + * the operator's way to restore a membership the environment lost. + * * Every refusal is `409 RESOURCE_CONFLICT`, no code minted — the answer * cloud-connection's platform-managed doors give, on the same rule: the * refusal comes from the runtime's state, not from the request (ADR-0112's @@ -83,6 +91,15 @@ export const CLOUD_MANAGED_REFUSAL_MESSAGES = { requestPasswordReset: "This environment is cloud-managed: you sign in through the hosting organisation's identity provider, and no " + 'local password is set or reset here for anyone, an administrator included. No reset link or code was sent.', + // `/organization/remove-member` (`sys_member.remove_member`). + removeMember: + 'This environment is cloud-managed: its members and their roles are managed in the organisation that hosts it, ' + + 'so a member cannot be removed here. Remove them in that organisation instead. No member was removed.', + // `/organization/update-member-role` (`sys_member.update_member_role` and + // `sys_member.transfer_ownership`, which sends the owner role to it). + updateMemberRole: + 'This environment is cloud-managed: its members and their roles are managed in the organisation that hosts it, ' + + "so a member's role cannot be changed here. Change it in that organisation instead. No role was changed.", } as const; /** The doors a cloud-managed environment narrows. */ From 31e81c460a6598a2e782b10643ab659b8402c2ce Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 00:55:18 +0000 Subject: [PATCH 02/16] fix(plugin-auth)!: a cloud-managed environment refuses remove-member and update-member-role Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .../src/auth-manager-before-hook.ts | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/plugins/plugin-auth/src/auth-manager-before-hook.ts b/packages/plugins/plugin-auth/src/auth-manager-before-hook.ts index f50335908a1..38c5a2e3e3b 100644 --- a/packages/plugins/plugin-auth/src/auth-manager-before-hook.ts +++ b/packages/plugins/plugin-auth/src/auth-manager-before-hook.ts @@ -12,7 +12,8 @@ * it stood, re-indented four levels and otherwise unedited: the same actor * resolver handed to the attribution scope, the same refresh skip for a minted * principal session, the same per-number OTP send guard, the same password - * complexity and reuse checks, the same + * complexity and reuse checks, the cloud-managed refusal on the two doors that + * change a membership or its role (added after the move), the same * remove-member, organization-delete and no-record revoke refusals, the same * held-caller refusal on the admin plugin's role-scalar actions, the same * no-record admin revoke refusal, the same held-caller refusal on rewriting or @@ -123,6 +124,19 @@ const CLOUD_MANAGED_RESET_DOORS: ReadonlySet = new Set([ '/phone-number/request-password-reset', ]); +/** + * The doors that change a membership or its role, which a cloud-managed + * environment refuses: the organisation that hosts it manages both. Make + * Owner (`sys_member.transfer_ownership`) sends the owner role to + * update-member-role, so it is refused there. `/organization/add-member` + * (platform administrators only) is deliberately absent: it restores a + * membership the environment lost. + */ +const CLOUD_MANAGED_MEMBERSHIP_DOORS: ReadonlyMap = new Map([ + ['/organization/remove-member', 'removeMember'], + [UPDATE_MEMBER_ROLE_PATH, 'updateMemberRole'], +]); + /** * The `AuthManager` members the function below reads — every one of them, and * no other. Each is typed AS the class member (an indexed access on the @@ -364,6 +378,26 @@ export async function globalBeforeHook( // fall through to the path's own handling below } + // ── Cloud-managed: membership and roles are the hosting organisation's ── + // On a cloud-managed environment the organisation that hosts it manages + // who is a member and with which role, so remove-member and + // update-member-role (Make Owner included) refuse every request with the + // invite-member envelope (`cloud-managed.ts`), ahead of the vendor's + // handler: nothing is written. AHEAD of the remove-member permission arm + // below and of the role-change grant read further down, so a refused + // request runs neither. As with invite-member, the fact is public + // (`features.cloudManaged` on `/auth/config`), so answering it ahead of the + // session check tells an anonymous caller nothing new. add-member is not + // among these doors (see `CLOUD_MANAGED_MEMBERSHIP_DOORS`). + const membershipDoor = CLOUD_MANAGED_MEMBERSHIP_DOORS.get(ctx?.path ?? ''); + if (membershipDoor && isCloudManaged()) { + const { APIError } = await import('better-auth/api'); + throw new APIError('CONFLICT', { + message: CLOUD_MANAGED_REFUSAL_MESSAGES[membershipDoor], + code: CLOUD_MANAGED_REFUSAL_CODE, + }); + } + // ── #8289: remove-member answers its PERMISSION denial itself ── // better-auth's `removeMember` orders "only an owner may remove an // owner" AHEAD of its real permission check and reports it with the From 3288c0d6cc2a897a67062b6c9418327d24f21f62 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 00:56:33 +0000 Subject: [PATCH 03/16] fix(platform-objects,spec)!: hide the membership-change actions while cloud-managed; docs and changeset Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- ...loud-managed-membership-changes-refused.md | 19 +++++++++ content/docs/permissions/authentication.mdx | 8 ++++ .../src/feature-gate-guard.test.ts | 11 +++--- .../identity/cloud-managed-visibility.test.ts | 39 +++++++++++++++++++ .../src/identity/sys-member.object.ts | 9 ++++- .../spec/src/kernel/public-auth-features.ts | 5 +++ 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 .changeset/cloud-managed-membership-changes-refused.md diff --git a/.changeset/cloud-managed-membership-changes-refused.md b/.changeset/cloud-managed-membership-changes-refused.md new file mode 100644 index 00000000000..6a87e70ed3e --- /dev/null +++ b/.changeset/cloud-managed-membership-changes-refused.md @@ -0,0 +1,19 @@ +--- +'@objectstack/plugin-auth': patch +'@objectstack/platform-objects': patch +'@objectstack/spec': patch +--- + +fix(auth)!: a cloud-managed environment refuses remove-member and update-member-role; membership and roles are managed by the hosting organisation + +Clause-②: no (narrowing) — narrowed: on a cloud-managed environment only (`OS_CLOUD_MANAGED=1`), `POST /organization/remove-member` and `POST /organization/update-member-role` now answer `409 RESOURCE_CONFLICT` to every request, where they removed the member or changed their role; Make Owner sends the owner role to update-member-role, so it is refused too. Two refusal sentences are added (`CLOUD_MANAGED_REFUSAL_MESSAGES.removeMember` and `.updateMemberRole`). The `sys_member` actions `update_member_role`, `remove_member` and `transfer_ownership` are hidden while `features.cloudManaged` is on, as the invite actions are, and `PUBLIC_AUTH_FEATURES.cloudManaged.gatedInputs` books the three paths. +Metadata-protocol: none +Skills-docs: none — no skill under `skills/**` teaches the organization membership doors or the cloud-managed mode; `content/docs/permissions/authentication.mdx` gains the rule in this change. + + + +**BREAKING** for a cloud-managed environment (`OS_CLOUD_MANAGED=1`, set only on hosted containers): membership and membership roles are managed by the organisation that hosts the environment. `POST /organization/remove-member` (Remove Member) and `POST /organization/update-member-role` (Change Role, and Make Owner, which calls it) refuse every request with `409 RESOURCE_CONFLICT` and write nothing, as `POST /organization/invite-member` already did; the three row actions are hidden there. + +Who moves: an owner (or administrator) of a cloud-managed environment who changed membership from inside the environment. Remove the person, or change their role, in the hosting organisation instead. + +Unchanged: every self-hosted deployment (the variable unset), where both doors answer as before; and `POST /organization/add-member`, which stays open on a managed environment to a platform administrator, to restore a membership the environment lost. diff --git a/content/docs/permissions/authentication.mdx b/content/docs/permissions/authentication.mdx index 0ec63634653..3d566db983e 100644 --- a/content/docs/permissions/authentication.mdx +++ b/content/docs/permissions/authentication.mdx @@ -1301,6 +1301,14 @@ sign-in through any other one leaves the person pending. Their positions, permis from the moment they are added, so seed data and approval flows can name them before they sign in. Off a managed environment both doors answer `409`. +Membership and membership roles on a cloud-managed environment are managed in +the organisation that hosts it, so `POST /api/v1/auth/organization/remove-member` +and `POST /api/v1/auth/organization/update-member-role` (Make Owner included) +answer `409 RESOURCE_CONFLICT` there and change nothing, and their row actions +are hidden; the one exception is `POST /api/v1/auth/organization/add-member`, +which stays open to a platform administrator to restore a membership the +environment lost. + Signing in does not lock the manager: a platform administrator still changes it with **Set Manager** (`POST /api/v1/auth/admin/set-user-manager`). That endpoint refuses only a person a SCIM directory holds, whose manager is changed diff --git a/packages/platform-objects/src/feature-gate-guard.test.ts b/packages/platform-objects/src/feature-gate-guard.test.ts index 49ce7e50945..0016a881cb7 100644 --- a/packages/platform-objects/src/feature-gate-guard.test.ts +++ b/packages/platform-objects/src/feature-gate-guard.test.ts @@ -264,11 +264,12 @@ describe('feature-gate completeness guard (#2874)', () => { } it('finds the gated surface (guards the walker itself)', () => { - // 37 booked inputs exist today (38 before #9968 retired - // sys_user.actions.set_user_role); if the walker ever goes blind and - // finds none, the it.each below would vacuously pass — pin a floor - // instead. - expect(referencedInputs.length).toBeGreaterThanOrEqual(37); + // 40 booked inputs exist today (37 before the three sys_member + // membership actions were hidden while cloud-managed; 38 before #9968 + // retired sys_user.actions.set_user_role); if the walker ever goes + // blind and finds none, the it.each below would vacuously pass — pin a + // floor instead. + expect(referencedInputs.length).toBeGreaterThanOrEqual(40); }); it.each(referencedInputs)('%s references registered flag %s and is booked', (path, flag) => { diff --git a/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts b/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts index cf214fa6366..389db40e300 100644 --- a/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts +++ b/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts @@ -189,3 +189,42 @@ describe('features.cloudManaged offers the two doors that add a pending person', expect(offeredSites).toEqual(SIX.map(([site]) => site)); }); }); + +/** + * Membership and roles on a cloud-managed environment are managed by the + * organisation that hosts it, so the three row actions that change them are + * hidden while the flag is on: Change Role and Make Owner (both call + * update-member-role) and Remove Member (remove-member), each of whose doors + * refuses there. Each is offered as before when the flag is off. Add Member + * stays offered to a platform administrator on a managed environment: its + * door is the one left open, to restore a membership the environment lost. + */ +describe('features.cloudManaged hides the row actions that change a membership or its role', () => { + const MEMBER_ROW = { id: 'mem_1', user_id: 'u_member', organization_id: 'org_1', role: 'member' }; + const THREE: ReadonlyArray<[string]> = [['update_member_role'], ['remove_member'], ['transfer_ownership']]; + + const rowOffered = (name: string, features: Record): boolean | string => { + const r = celEngine.evaluate( + { dialect: 'cel', source: visibleOf(SysMember, name) }, + { record: MEMBER_ROW, extra: { current_user: ADMIN, user: ADMIN, ctx: { user: ADMIN }, features } }, + ); + if (!r.ok) return `FAULT ${r.error.message.split('\n')[0].trim()}`; + return typeof r.value === 'boolean' ? r.value : `NON-BOOLEAN ${JSON.stringify(r.value)}`; + }; + + it.each(THREE)('sys_member.%s is hidden while the environment is cloud-managed', (name) => { + expect(rowOffered(name, { ...OTHER_FLAGS, cloudManaged: true })).toBe(false); + }); + + it.each(THREE)('sys_member.%s is offered to the owner as before when the flag is off', (name) => { + expect(rowOffered(name, { ...OTHER_FLAGS, cloudManaged: false })).toBe(true); + }); + + it.each(THREE)('sys_member.%s keeps its organization gate: off hides it whatever cloudManaged says', (name) => { + expect(rowOffered(name, { organization: false, admin: true, cloudManaged: false })).toBe(false); + }); + + it('sys_member.add_member stays offered to a platform administrator while the environment is cloud-managed', () => { + expect(rowOffered('add_member', { ...OTHER_FLAGS, cloudManaged: true })).toBe(true); + }); +}); diff --git a/packages/platform-objects/src/identity/sys-member.object.ts b/packages/platform-objects/src/identity/sys-member.object.ts index ab0d3441c65..ddd03e71b43 100644 --- a/packages/platform-objects/src/identity/sys-member.object.ts +++ b/packages/platform-objects/src/identity/sys-member.object.ts @@ -228,6 +228,9 @@ export const SysMember = ObjectSchema.create({ type: 'api', target: '/api/v1/auth/organization/update-member-role', recordIdParam: 'memberId', + // Hidden while cloud-managed: the hosting organisation manages members + // and their roles there, and the door refuses (409 RESOURCE_CONFLICT). + visible: 'features.cloudManaged != true', requiresFeature: 'organization', requiresMembershipReach: 'update_member_role', successMessage: 'Member role updated', @@ -254,6 +257,8 @@ export const SysMember = ObjectSchema.create({ type: 'api', target: '/api/v1/auth/organization/remove-member', recordIdParam: 'memberIdOrEmail', + // Hidden while cloud-managed, as `update_member_role` above. + visible: 'features.cloudManaged != true', requiresFeature: 'organization', requiresMembershipReach: 'remove_member', confirmText: 'Remove this member from the organization? They will lose access to all org resources.', @@ -301,7 +306,9 @@ export const SysMember = ObjectSchema.create({ // predicate at key resolution and drop the button silently. `has()` // alone — the operand is a bare equality against a literal (see // `materializeDeclaredFields` in `@objectstack/objectql`). - visible: "has(record.role) && record.role != 'owner'", + // Hidden while cloud-managed, as `update_member_role` above (the same + // door). + visible: "has(record.role) && record.role != 'owner' && features.cloudManaged != true", requiresFeature: 'organization', requiresMembershipReach: 'transfer_ownership', confirmText: 'Make the selected member an owner of this organization? They get every owner privilege, including deleting the organization. You stay an owner too; to step down, use Change Role on your own membership.', diff --git a/packages/spec/src/kernel/public-auth-features.ts b/packages/spec/src/kernel/public-auth-features.ts index 644544c4e24..5d3faef74f3 100644 --- a/packages/spec/src/kernel/public-auth-features.ts +++ b/packages/spec/src/kernel/public-auth-features.ts @@ -303,6 +303,11 @@ export const PUBLIC_AUTH_FEATURES = { // Hidden in the console only: the server keeps answering it on an // `env_native` row, so the break-glass admin stays editable. 'sys_user.actions.set_user_password', + // Membership and roles are managed by the hosting organisation: the two + // doors that change them refuse, and Make Owner rides update-member-role. + 'sys_member.actions.update_member_role', + 'sys_member.actions.remove_member', + 'sys_member.actions.transfer_ownership', ], notes: 'Served from the one isCloudManaged() accessor in @objectstack/core. ' + From 2267499a7ef228f0b641ec73a200cab2857565ba Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 01:06:38 +0000 Subject: [PATCH 04/16] test(dogfood): pin that a person with no membership row reads no organization data Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- ...hip-required-every-posture.dogfood.test.ts | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/qa/dogfood/test/membership-required-every-posture.dogfood.test.ts b/packages/qa/dogfood/test/membership-required-every-posture.dogfood.test.ts index 4ca11423baf..4b16a137522 100644 --- a/packages/qa/dogfood/test/membership-required-every-posture.dogfood.test.ts +++ b/packages/qa/dogfood/test/membership-required-every-posture.dogfood.test.ts @@ -21,7 +21,11 @@ * `403 PERMISSION_DENIED` and nothing lands, and the key they minted is * refused; a flow they launch that runs as them reads none of the * organization's data and writes nothing; the other person — still a - * member — is served throughout, by the same doors and the same flows. + * member — is served throughout, by the same doors and the same flows; + * 4. a third person whose membership row is taken away by no door at all + * (under the system context) signs in to no active organization, adopts + * no membership, and reads and writes none of the organization's data, + * their own note included. * * The posture is read off the `tenancy` service, not assumed: a degraded boot * resolves to `single`, and a matrix whose walled legs were really `single` @@ -219,6 +223,47 @@ describe.each(['single', 'isolated', 'group'] as const)( expect(await readNotesByKey(stays.key)).toBe(200); }); + it('a person whose membership row is gone by no door signs in to no active organization and reads and writes none of its data', async () => { + // The row is taken away under the system context, not through any + // membership door: the state of a person the environment holds no + // membership for, however they arrived there. The person first writes a + // note as a member and reads it back, so the empty read below is + // measured against their own row. + const email = `membership.${posture}.no-row@example.com`; + await stack.signUp(email, PASSWORD, 'Membership no-row'); + const [u] = await findRows(ql, 'sys_user', { email }, 1); + const userId = String(u.id); + if (posture !== 'single') await ql.insert('sys_member', { user_id: userId, organization_id: orgId, role: 'member' }, { context: SYS }); + const row = await waitForMembership(ql, userId, orgId); + const asMember = await stack.signIn(email, PASSWORD); + const created = await stack.apiAs(asMember, 'POST', `/data/${NOTE}`, { title: 'no-row note, written as a member' }); + expect(created.status, await created.clone().text()).toBe(201); + const createdBody: any = await created.json(); + const noteId = String(createdBody?.data?.id ?? createdBody?.id ?? createdBody?.record?.id); + expect((await readNotes(asMember)).ids).toContain(noteId); + + await ql.delete('sys_member', row.id, { context: SYS }); + expect(await findRows(ql, 'sys_member', { user_id: userId }, 5)).toEqual([]); + + const token = await stack.signIn(email, PASSWORD); + const me = await stack.apiAs(token, 'GET', '/auth/get-session'); + expect(me.status, await me.clone().text()).toBe(200); + const meBody: any = await me.json(); + expect(meBody?.session?.activeOrganizationId ?? null, JSON.stringify(meBody?.session)).toBeNull(); + // Signing in adopted no membership either. + expect(await findRows(ql, 'sys_member', { user_id: userId }, 5)).toEqual([]); + + const read = await readNotes(token); + expect(read.status).toBe(200); + expect(read.ids).toEqual([]); + expect((await stack.apiAs(token, 'GET', `/data/${NOTE}/${noteId}`)).status).toBe(404); + + const write = await stack.apiAs(token, 'POST', `/data/${NOTE}`, { title: 'written with no membership row' }); + expect(write.status).toBe(403); + expect(errorCodeOf(await write.json())).toBe('PERMISSION_DENIED'); + expect(await findRows(ql, NOTE, { title: 'written with no membership row' }, 5)).toEqual([]); + }); + it('CONTROL: the person who is still a member is served — reads its note, and its write lands', async () => { const read = await readNotes(stays.token); expect(read.status).toBe(200); From 58e77a1d971f1ed73e32210cd8d43309b813d9de Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 01:23:15 +0000 Subject: [PATCH 05/16] docs(auth): name the two membership doors in a marked wire fence Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- content/docs/permissions/authentication.mdx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/content/docs/permissions/authentication.mdx b/content/docs/permissions/authentication.mdx index 3d566db983e..1ae4c64ea88 100644 --- a/content/docs/permissions/authentication.mdx +++ b/content/docs/permissions/authentication.mdx @@ -1301,13 +1301,18 @@ sign-in through any other one leaves the person pending. Their positions, permis from the moment they are added, so seed data and approval flows can name them before they sign in. Off a managed environment both doors answer `409`. -Membership and membership roles on a cloud-managed environment are managed in -the organisation that hosts it, so `POST /api/v1/auth/organization/remove-member` -and `POST /api/v1/auth/organization/update-member-role` (Make Owner included) -answer `409 RESOURCE_CONFLICT` there and change nothing, and their row actions -are hidden; the one exception is `POST /api/v1/auth/organization/add-member`, -which stays open to a platform administrator to restore a membership the -environment lost. +On a cloud-managed environment the organisation that hosts it decides who is a +member and at which membership tier, so the two doors that change an existing +membership (below; Make Owner calls the second) answer `409 RESOURCE_CONFLICT` +there and change nothing, and their row actions are hidden; the one exception +is `POST /api/v1/auth/organization/add-member`, which stays open to a platform +administrator to restore a membership the environment lost. + +{/* os:vendor-wire better-auth */} +```http +POST /api/v1/auth/organization/remove-member +POST /api/v1/auth/organization/update-member-role +``` Signing in does not lock the manager: a platform administrator still changes it with **Set Manager** (`POST /api/v1/auth/admin/set-user-manager`). That From 858d8b5a6707dfa1d3f8f9b1e501be279e6dd7ba Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 01:41:12 +0000 Subject: [PATCH 06/16] test(platform-objects): the lowering matrix and sparse-face sweep read the cloudManaged gate on the membership actions Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .../src/identity/action-predicate-sparse-face.test.ts | 3 +++ packages/platform-objects/src/platform-objects.test.ts | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/platform-objects/src/identity/action-predicate-sparse-face.test.ts b/packages/platform-objects/src/identity/action-predicate-sparse-face.test.ts index 1b40d2692b6..ac5201fec2a 100644 --- a/packages/platform-objects/src/identity/action-predicate-sparse-face.test.ts +++ b/packages/platform-objects/src/identity/action-predicate-sparse-face.test.ts @@ -106,6 +106,9 @@ function sourceOf(raw: unknown): string | undefined { const FEATURES = { organization: true, multiOrgEnabled: true, twoFactor: true, oidcProvider: true, admin: true, phoneNumber: true, apiKey: true, sso: true, + // The one hide-when-on flag the swept actions read: off is its "on" here, + // the setting that leaves the record half reachable. + cloudManaged: false, }; /** Evaluate through the canonical engine; a fault is reported, never thrown. */ diff --git a/packages/platform-objects/src/platform-objects.test.ts b/packages/platform-objects/src/platform-objects.test.ts index 55397b56017..e42d77e4ebb 100644 --- a/packages/platform-objects/src/platform-objects.test.ts +++ b/packages/platform-objects/src/platform-objects.test.ts @@ -781,9 +781,11 @@ describe('feature-gate lowering matrix (#2874)', () => { ['SysSsoProvider', SysSsoProvider, 'edit_sso_groups_claim', STANDING], ['SysSsoProvider', SysSsoProvider, 'show_sso_attribute_mapping', STANDING], ['SysSsoProvider', SysSsoProvider, 'edit_sso_attribute_mapping', STANDING], - ['SysMember', SysMember, 'update_member_role', `${ADMINS} && ${ORG}`], - ['SysMember', SysMember, 'remove_member', `${ADMINS} && ${ORG}`], - ['SysMember', SysMember, 'transfer_ownership', `((has(record.role) && record.role != 'owner') && ${OWNER}) && ${ORG}`], + // Hidden while cloud-managed: membership and its tiers are the hosting + // organisation's there, and both doors refuse. + ['SysMember', SysMember, 'update_member_role', `((${MANAGED}) && ${ADMINS}) && ${ORG}`], + ['SysMember', SysMember, 'remove_member', `((${MANAGED}) && ${ADMINS}) && ${ORG}`], + ['SysMember', SysMember, 'transfer_ownership', `((has(record.role) && record.role != 'owner' && ${MANAGED}) && ${OWNER}) && ${ORG}`], ['SysInvitation', SysInvitation, 'invite_user', `((${MANAGED}) && ${INVITE}) && ${ORG}`], ['SysInvitation', SysInvitation, 'cancel_invitation', `${ADMINS} && ${ORG}`], ['SysInvitation', SysInvitation, 'resend_invitation', `((${MANAGED}) && ${INVITE}) && ${ORG}`], From 83d41f41dfebb90d3d54837a281a92b99938c33a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 01:59:59 +0000 Subject: [PATCH 07/16] test(plugin-auth): spy on the two private arms through an untyped handle Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- packages/plugins/plugin-auth/src/cloud-managed.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugins/plugin-auth/src/cloud-managed.test.ts b/packages/plugins/plugin-auth/src/cloud-managed.test.ts index 0af925d4fa0..44a795d1740 100644 --- a/packages/plugins/plugin-auth/src/cloud-managed.test.ts +++ b/packages/plugins/plugin-auth/src/cloud-managed.test.ts @@ -852,7 +852,7 @@ describe('on a cloud-managed environment, membership and roles are managed by th it.each(DOORS)('%s refuses ahead of the arms behind it: no permission judge runs and no grant read is taken', async (_door, path, _key, body) => { const s = await stage(); const row = memberRow(s); - const permissionJudge = vi.spyOn(s.manager, 'assertRemoveMemberPermitted'); + const permissionJudge = vi.spyOn(s.manager as any, 'assertRemoveMemberPermitted'); const grantRead = vi.spyOn(s.manager as any, 'roleChangeGrantDeps'); setManaged(true); const v = await verdict(await s.fire(path, body(String(row.id)), s.bearers.admin)); @@ -864,7 +864,7 @@ describe('on a cloud-managed environment, membership and roles are managed by th it.each(DOORS)('CONTROL: self-hosted, %s answers 200 and changes the membership as before', async (_door, path, _key, body) => { const s = await stage(); const row = memberRow(s); - const permissionJudge = vi.spyOn(s.manager, 'assertRemoveMemberPermitted'); + const permissionJudge = vi.spyOn(s.manager as any, 'assertRemoveMemberPermitted'); const grantRead = vi.spyOn(s.manager as any, 'roleChangeGrantDeps'); const sent = body(String(row.id)); const v = await verdict(await s.fire(path, sent, s.bearers.admin)); From 83ae9a60e4e80c29448483c9f3bff040b8b5ec28 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 02:00:32 +0000 Subject: [PATCH 08/16] docs(plugin-auth): state the membership rule only in the cloud-managed header Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- packages/plugins/plugin-auth/src/cloud-managed.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugins/plugin-auth/src/cloud-managed.ts b/packages/plugins/plugin-auth/src/cloud-managed.ts index b56123847d6..83176688275 100644 --- a/packages/plugins/plugin-auth/src/cloud-managed.ts +++ b/packages/plugins/plugin-auth/src/cloud-managed.ts @@ -34,9 +34,9 @@ * doors that change them, `/organization/remove-member` and * `/organization/update-member-role` (Make Owner included, which sends the * owner role to it), refuse every request, as `/organization/invite-member` - * does. A change made here would hold in the environment alone. The one door - * left open is `/organization/add-member`, platform-administrator only: it is - * the operator's way to restore a membership the environment lost. + * does. The one door left open is `/organization/add-member`, + * platform-administrator only: it is the operator's way to restore a + * membership the environment lost. * * Every refusal is `409 RESOURCE_CONFLICT`, no code minted — the answer * cloud-connection's platform-managed doors give, on the same rule: the From 5ace81e58aae4409040348d69c148c07406f442f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 02:45:24 +0000 Subject: [PATCH 09/16] test(dogfood): delete the membership row with the engine's where-shaped delete Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .../test/membership-required-every-posture.dogfood.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/qa/dogfood/test/membership-required-every-posture.dogfood.test.ts b/packages/qa/dogfood/test/membership-required-every-posture.dogfood.test.ts index 4b16a137522..2d783ebea9c 100644 --- a/packages/qa/dogfood/test/membership-required-every-posture.dogfood.test.ts +++ b/packages/qa/dogfood/test/membership-required-every-posture.dogfood.test.ts @@ -242,7 +242,7 @@ describe.each(['single', 'isolated', 'group'] as const)( const noteId = String(createdBody?.data?.id ?? createdBody?.id ?? createdBody?.record?.id); expect((await readNotes(asMember)).ids).toContain(noteId); - await ql.delete('sys_member', row.id, { context: SYS }); + await ql.delete('sys_member', { where: { id: row.id }, context: SYS }); expect(await findRows(ql, 'sys_member', { user_id: userId }, 5)).toEqual([]); const token = await stack.signIn(email, PASSWORD); From 6ad55722de39601b0f39ab9234f487b645db9c96 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 03:53:08 +0000 Subject: [PATCH 10/16] fix(plugin-auth,platform-objects,spec)!: every door that writes or deletes a membership row refuses on a cloud-managed environment, add-member excepted Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .../src/identity/sys-invitation.object.ts | 5 +- .../src/identity/sys-organization.object.ts | 10 ++ .../src/auth-manager-before-hook.ts | 49 ++++-- .../plugin-auth/src/cloud-managed.test.ts | 143 ++++++++++++++++++ .../plugins/plugin-auth/src/cloud-managed.ts | 38 ++++- .../spec/src/kernel/public-auth-features.ts | 15 +- 6 files changed, 232 insertions(+), 28 deletions(-) diff --git a/packages/platform-objects/src/identity/sys-invitation.object.ts b/packages/platform-objects/src/identity/sys-invitation.object.ts index 81560437a0c..4a46d3758c8 100644 --- a/packages/platform-objects/src/identity/sys-invitation.object.ts +++ b/packages/platform-objects/src/identity/sys-invitation.object.ts @@ -251,7 +251,10 @@ export const SysInvitation = ObjectSchema.create({ type: 'api', target: '/api/v1/auth/organization/accept-invitation', recordIdParam: 'invitationId', - visible: "has(record.email) && record.email == ctx.user.email && has(record.status) && record.status == 'pending'", + // Hidden while cloud-managed: accepting creates a membership, which is + // the hosting organisation's there; the door refuses (409 + // RESOURCE_CONFLICT). Decline stays: it writes no membership. + visible: "has(record.email) && record.email == ctx.user.email && has(record.status) && record.status == 'pending' && features.cloudManaged != true", successMessage: 'Invitation accepted', refreshAfter: true, // ADR-0011 identity-actions note, bucket E: exposed by plain declaration. diff --git a/packages/platform-objects/src/identity/sys-organization.object.ts b/packages/platform-objects/src/identity/sys-organization.object.ts index 5725023818d..01ed4415973 100644 --- a/packages/platform-objects/src/identity/sys-organization.object.ts +++ b/packages/platform-objects/src/identity/sys-organization.object.ts @@ -71,6 +71,10 @@ export const SysOrganization = ObjectSchema.create({ locations: ['list_toolbar'], type: 'api', target: '/api/v1/auth/organization/create', + // Hidden while cloud-managed: creating an organization makes the caller + // its owner, and membership is the hosting organisation's there; the + // door refuses (409 RESOURCE_CONFLICT). + visible: 'features.cloudManaged != true', successMessage: 'Organization created', refreshAfter: true, // Hidden when the deployment is provisioned in single-org mode @@ -132,6 +136,9 @@ export const SysOrganization = ObjectSchema.create({ type: 'api', target: '/api/v1/auth/organization/delete', recordIdParam: 'organizationId', + // Hidden while cloud-managed: deleting ends every membership, and the + // door refuses there (409 RESOURCE_CONFLICT). + visible: 'features.cloudManaged != true', requiresFeature: 'multiOrgEnabled', // `organization/delete` admits the owner alone (ADR-0108 D1). requiresMembershipReach: 'delete_organization', @@ -242,6 +249,9 @@ export const SysOrganization = ObjectSchema.create({ type: 'api', target: '/api/v1/auth/organization/leave', recordIdParam: 'organizationId', + // Hidden while cloud-managed: leaving ends a membership, which is the + // hosting organisation's there; the door refuses (409 RESOURCE_CONFLICT). + visible: 'features.cloudManaged != true', requiresFeature: 'multiOrgEnabled', // Names what is lost (#24021's copy half, ruling 6228318638 item 2). confirmText: 'Leave this organization? You will lose access to its environments and members.', diff --git a/packages/plugins/plugin-auth/src/auth-manager-before-hook.ts b/packages/plugins/plugin-auth/src/auth-manager-before-hook.ts index 8ac0327ce5c..ae34d217508 100644 --- a/packages/plugins/plugin-auth/src/auth-manager-before-hook.ts +++ b/packages/plugins/plugin-auth/src/auth-manager-before-hook.ts @@ -125,16 +125,27 @@ const CLOUD_MANAGED_RESET_DOORS: ReadonlySet = new Set([ ]); /** - * The doors that change a membership or its role, which a cloud-managed - * environment refuses: the organisation that hosts it manages both. Make - * Owner (`sys_member.transfer_ownership`) sends the owner role to - * update-member-role, so it is refused there. `/organization/add-member` - * (platform administrators only) is deliberately absent: it restores a - * membership the environment lost. + * Every organization-family door that writes or deletes an organization + * membership row, which a cloud-managed environment refuses: the + * organisation that hosts it manages membership and its tiers. Make Owner + * (`sys_member.transfer_ownership`) sends the owner tier to + * update-member-role, so it is refused there; create makes the caller the + * new organization's owner, and delete ends every membership of the + * organization. `/organization/add-member` (exactly a platform administrator, + * adding a membership) is deliberately absent: it restores a membership the + * environment lost. The census of the family, with each other route's reason, + * is `cloud-managed.ts`'s header. */ -const CLOUD_MANAGED_MEMBERSHIP_DOORS: ReadonlyMap = new Map([ +const CLOUD_MANAGED_MEMBERSHIP_DOORS: ReadonlyMap< + string, + 'removeMember' | 'updateMemberRole' | 'leaveOrganization' | 'acceptInvitation' | 'createOrganization' | 'deleteOrganization' +> = new Map([ ['/organization/remove-member', 'removeMember'], [UPDATE_MEMBER_ROLE_PATH, 'updateMemberRole'], + ['/organization/leave', 'leaveOrganization'], + ['/organization/accept-invitation', 'acceptInvitation'], + ['/organization/create', 'createOrganization'], + [ORGANIZATION_DELETE_PATH, 'deleteOrganization'], ]); /** @@ -388,17 +399,23 @@ export async function globalBeforeHook( // fall through to the path's own handling below } - // ── Cloud-managed: membership and roles are the hosting organisation's ── + // ── Cloud-managed: membership and its tiers are the hosting organisation's ── // On a cloud-managed environment the organisation that hosts it manages - // who is a member and with which role, so remove-member and - // update-member-role (Make Owner included) refuse every request with the + // who is a member and at which tier, so every door that writes or deletes + // an organization membership row (`CLOUD_MANAGED_MEMBERSHIP_DOORS`: + // remove-member, update-member-role with Make Owner, leave, + // accept-invitation, create, delete) refuses every request with the // invite-member envelope (`cloud-managed.ts`), ahead of the vendor's - // handler: nothing is written. AHEAD of the remove-member permission arm - // below and of the role-change grant read further down, so a refused - // request runs neither. As with invite-member, the fact is public - // (`features.cloudManaged` on `/auth/config`), so answering it ahead of the - // session check tells an anonymous caller nothing new. add-member is not - // among these doors (see `CLOUD_MANAGED_MEMBERSHIP_DOORS`). + // handler: nothing is written. AHEAD of the remove-member permission arm, + // the organization-delete records arm and the role-change grant read below, + // so a refused request runs none of them. As with invite-member, the fact + // is public (`features.cloudManaged` on `/auth/config`), so answering it + // ahead of the session check tells an anonymous caller nothing new. + // add-member is not among these doors. This line is the only one: the + // invitation refusal has a second line in `beforeCreateInvitation`, but no + // in-process caller reaches these vendor operations (each is reached + // through its route alone, so through this hook), so one line is enough + // today. A future in-process caller of one of them needs its own refusal. const membershipDoor = CLOUD_MANAGED_MEMBERSHIP_DOORS.get(ctx?.path ?? ''); if (membershipDoor && isCloudManaged()) { const { APIError } = await import('better-auth/api'); diff --git a/packages/plugins/plugin-auth/src/cloud-managed.test.ts b/packages/plugins/plugin-auth/src/cloud-managed.test.ts index 44a795d1740..c30a8a34a2b 100644 --- a/packages/plugins/plugin-auth/src/cloud-managed.test.ts +++ b/packages/plugins/plugin-auth/src/cloud-managed.test.ts @@ -908,6 +908,149 @@ describe('on a cloud-managed environment, membership and roles are managed by th expectManagedRefusal(v, 'invitation'); expect(s.invitationsOf('newcomer.membership@example.com')).toHaveLength(0); }, 120_000); + + it('add-member admits exactly a platform administrator there: an ordinary member hears 403 PERMISSION_DENIED and nothing is written', async () => { + const s = await stage(); + const row = memberRow(s); + s.engine.tables.set( + 'sys_member', + ((s.engine.tables.get('sys_member') ?? []) as any[]).filter((m) => m.id !== row.id), + ); + const before = structuredClone(memberships(s)); + setManaged(true); + const v = await verdict( + await s.fire('/organization/add-member', { userId: s.ids.member, role: 'member', organizationId: DEFAULT_ORG }, s.bearers.member), + ); + expect(v.status, v.text).toBe(403); + expect(v.code, v.text).toBe('PERMISSION_DENIED'); + expect(memberships(s)).toEqual(before); + }, 120_000); + + // ── leave: a member ends their own membership ───────────────────────────── + + it('leave answers 409 RESOURCE_CONFLICT to a member, and their membership row is unchanged', async () => { + const s = await stage(); + memberRow(s); + const before = structuredClone(memberships(s)); + setManaged(true); + const v = await verdict(await s.fire('/organization/leave', { organizationId: DEFAULT_ORG }, s.bearers.member)); + expectManagedRefusal(v, 'leaveOrganization'); + expect(memberships(s)).toEqual(before); + }, 120_000); + + it('CONTROL: self-hosted, leave answers 200 and ends the membership as before', async () => { + const s = await stage(); + memberRow(s); + const v = await verdict(await s.fire('/organization/leave', { organizationId: DEFAULT_ORG }, s.bearers.member)); + expect(v.status, v.text).toBe(200); + expect(membershipOf(s, s.ids.member)).toBeUndefined(); + }, 120_000); + + // ── accept-invitation: an invitation still pending from before ──────────── + + /** The ordinary user, with no membership, holding a pending invitation issued while unmanaged. */ + const pendingInvitationFor = async (s: Staged): Promise => { + const row = memberRow(s); + s.engine.tables.set( + 'sys_member', + ((s.engine.tables.get('sys_member') ?? []) as any[]).filter((m) => m.id !== row.id), + ); + const email = String(s.users().find((u) => String(u.id) === s.ids.member)!.email); + const issued = await verdict( + await s.fire('/organization/invite-member', { email, role: 'member', organizationId: DEFAULT_ORG }, s.bearers.admin), + ); + expect(issued.status, `fixture: the invitation is issued while unmanaged — ${issued.text}`).toBe(200); + const [invitation] = s.invitationsOf(email); + expect(invitation?.status, 'fixture: the invitation is pending').toBe('pending'); + return String(invitation.id); + }; + + it('accept-invitation answers 409 RESOURCE_CONFLICT to the invitee: no membership is created and the invitation stays pending', async () => { + const s = await stage(); + const invitationId = await pendingInvitationFor(s); + setManaged(true); + const v = await verdict(await s.fire('/organization/accept-invitation', { invitationId }, s.bearers.member)); + expectManagedRefusal(v, 'acceptInvitation'); + expect(membershipOf(s, s.ids.member)).toBeUndefined(); + const invitation = ((s.engine.tables.get('sys_invitation') ?? []) as any[]).find((r) => String(r.id) === invitationId); + expect(invitation?.status).toBe('pending'); + }, 120_000); + + it('CONTROL: self-hosted, accept-invitation answers 200 and creates the membership as before', async () => { + const s = await stage(); + const invitationId = await pendingInvitationFor(s); + const v = await verdict(await s.fire('/organization/accept-invitation', { invitationId }, s.bearers.member)); + expect(v.status, v.text).toBe(200); + expect(membershipOf(s, s.ids.member)?.role).toBe('member'); + }, 120_000); + + // ── create and delete: an organization's owner membership, and every one ── + + const organizations = (s: Staged) => (s.engine.tables.get('sys_organization') ?? []) as any[]; + const allMemberships = (s: Staged) => (s.engine.tables.get('sys_member') ?? []) as any[]; + const SECOND_ORG = { name: 'Second Org', slug: 'second-org-membership' }; + + it('create answers 409 RESOURCE_CONFLICT to the owner: no organization and no owner membership are written', async () => { + const s = await stage(); + const orgsBefore = structuredClone(organizations(s)); + const membersBefore = structuredClone(allMemberships(s)); + setManaged(true); + const v = await verdict(await s.fire('/organization/create', SECOND_ORG, s.bearers.admin)); + expectManagedRefusal(v, 'createOrganization'); + expect(organizations(s)).toEqual(orgsBefore); + expect(allMemberships(s)).toEqual(membersBefore); + }, 120_000); + + it('CONTROL: self-hosted, create answers 200 and makes the caller the new organization\'s owner as before', async () => { + const s = await stage(); + const v = await verdict(await s.fire('/organization/create', SECOND_ORG, s.bearers.admin)); + expect(v.status, v.text).toBe(200); + const org = organizations(s).find((o) => o.slug === SECOND_ORG.slug); + expect(org, v.text).toBeDefined(); + const owner = allMemberships(s).find((m) => m.organization_id === org.id && String(m.user_id) === s.ids.admin); + expect(owner?.role).toBe('owner'); + }, 120_000); + + it('delete answers 409 RESOURCE_CONFLICT to the owner, ahead of the records arm: the organization and its memberships remain', async () => { + const s = await stage(); + const created = await verdict(await s.fire('/organization/create', SECOND_ORG, s.bearers.admin)); + expect(created.status, `fixture: the organization is created while unmanaged — ${created.text}`).toBe(200); + const org = organizations(s).find((o) => o.slug === SECOND_ORG.slug); + const orgsBefore = structuredClone(organizations(s)); + const membersBefore = structuredClone(allMemberships(s)); + const recordsArm = vi.spyOn(s.manager as any, 'assertOrganizationDeletable'); + setManaged(true); + const v = await verdict(await s.fire('/organization/delete', { organizationId: org.id }, s.bearers.admin)); + expectManagedRefusal(v, 'deleteOrganization'); + expect(recordsArm).not.toHaveBeenCalled(); + expect(organizations(s)).toEqual(orgsBefore); + expect(allMemberships(s)).toEqual(membersBefore); + }, 120_000); + + it('CONTROL: self-hosted, delete answers 200 and ends the organization\'s memberships as before', async () => { + const s = await stage(); + const created = await verdict(await s.fire('/organization/create', SECOND_ORG, s.bearers.admin)); + expect(created.status, `fixture: the organization is created — ${created.text}`).toBe(200); + const org = organizations(s).find((o) => o.slug === SECOND_ORG.slug); + expect(allMemberships(s).some((m) => m.organization_id === org.id), 'fixture: the owner membership exists').toBe(true); + const recordsArm = vi.spyOn(s.manager as any, 'assertOrganizationDeletable'); + const v = await verdict(await s.fire('/organization/delete', { organizationId: org.id }, s.bearers.admin)); + expect(v.status, v.text).toBe(200); + expect(recordsArm).toHaveBeenCalled(); + expect(organizations(s).some((o) => o.id === org.id)).toBe(false); + expect(allMemberships(s).some((m) => m.organization_id === org.id)).toBe(false); + }, 120_000); + + // ── the rest of the family writes no membership row ─────────────────────── + + it('CONTROL: reject-invitation, which writes no membership, answers the invitee as before', async () => { + const s = await stage(); + const invitationId = await pendingInvitationFor(s); + setManaged(true); + const v = await verdict(await s.fire('/organization/reject-invitation', { invitationId }, s.bearers.member)); + expect(v.status, v.text).toBe(200); + expect(membershipOf(s, s.ids.member)).toBeUndefined(); + }, 120_000); }); describe('[#25083] what a host that mounts its own twin of a door imports', () => { diff --git a/packages/plugins/plugin-auth/src/cloud-managed.ts b/packages/plugins/plugin-auth/src/cloud-managed.ts index 83176688275..5d697901391 100644 --- a/packages/plugins/plugin-auth/src/cloud-managed.ts +++ b/packages/plugins/plugin-auth/src/cloud-managed.ts @@ -30,13 +30,19 @@ * break-glass clause, which kept a local credential reachable by population, * holds on self-hosted deployments only. * - * Membership and membership roles are the hosting organisation's too: the two - * doors that change them, `/organization/remove-member` and - * `/organization/update-member-role` (Make Owner included, which sends the - * owner role to it), refuse every request, as `/organization/invite-member` - * does. The one door left open is `/organization/add-member`, - * platform-administrator only: it is the operator's way to restore a - * membership the environment lost. + * Membership and membership tiers are the hosting organisation's too. Every + * organization-family door that writes or deletes an organization membership + * row refuses every request, as `/organization/invite-member` does: + * `/organization/remove-member`, `/organization/update-member-role` (Make + * Owner included, which sends the owner tier to it), `/organization/leave`, + * `/organization/accept-invitation`, `/organization/create` (it makes the + * caller the new organization's owner) and `/organization/delete` (it ends + * every membership of the organization). The one door left open is + * `/organization/add-member`: it admits exactly a platform administrator, + * adding a membership, and is the operator's way to restore one the + * environment lost. The rest of the family writes no membership row (team + * rows, invitation rows, the session's active organization, the + * organization's own fields) or only reads, and answers as before. * * Every refusal is `409 RESOURCE_CONFLICT`, no code minted — the answer * cloud-connection's platform-managed doors give, on the same rule: the @@ -100,6 +106,24 @@ export const CLOUD_MANAGED_REFUSAL_MESSAGES = { updateMemberRole: 'This environment is cloud-managed: its members and their roles are managed in the organisation that hosts it, ' + "so a member's role cannot be changed here. Change it in that organisation instead. No role was changed.", + // `/organization/leave` (`sys_organization.leave_organization`). + leaveOrganization: + 'This environment is cloud-managed: its members and their roles are managed in the organisation that hosts it, ' + + 'so you cannot leave it here. Ask that organisation to remove you instead. No membership was ended.', + // `/organization/accept-invitation` (`sys_invitation.accept_invitation`). + acceptInvitation: + 'This environment is cloud-managed: its members and their roles are managed in the organisation that hosts it, ' + + 'so an invitation cannot be accepted here. Ask that organisation to add you instead. No membership was created.', + // `/organization/create` (`sys_organization.create_organization`), which + // makes the caller the new organization's owner. + createOrganization: + 'This environment is cloud-managed: its members and their roles are managed in the organisation that hosts it, ' + + 'so an organization, which would make you its owner, cannot be created here. No organization was created.', + // `/organization/delete` (`sys_organization.delete_organization`), which + // ends every membership of the organization. + deleteOrganization: + 'This environment is cloud-managed: its members and their roles are managed in the organisation that hosts it, ' + + 'so an organization, and every membership in it, cannot be deleted here. No organization was deleted.', } as const; /** The doors a cloud-managed environment narrows. */ diff --git a/packages/spec/src/kernel/public-auth-features.ts b/packages/spec/src/kernel/public-auth-features.ts index 5d3faef74f3..ab48be09fcc 100644 --- a/packages/spec/src/kernel/public-auth-features.ts +++ b/packages/spec/src/kernel/public-auth-features.ts @@ -303,16 +303,23 @@ export const PUBLIC_AUTH_FEATURES = { // Hidden in the console only: the server keeps answering it on an // `env_native` row, so the break-glass admin stays editable. 'sys_user.actions.set_user_password', - // Membership and roles are managed by the hosting organisation: the two - // doors that change them refuse, and Make Owner rides update-member-role. + // Membership and its tiers are managed by the hosting organisation: + // every door that writes or deletes a membership row refuses (Make + // Owner rides update-member-role; create makes the caller an owner; + // delete ends every membership), add-member alone excepted. 'sys_member.actions.update_member_role', 'sys_member.actions.remove_member', 'sys_member.actions.transfer_ownership', + 'sys_organization.actions.leave_organization', + 'sys_organization.actions.create_organization', + 'sys_organization.actions.delete_organization', + 'sys_invitation.actions.accept_invitation', ], notes: 'Served from the one isCloudManaged() accessor in @objectstack/core. ' + - 'Each gated input is also gated on `organization` or `admin`, so its ' + - '`visible` predicate carries two gates. Also read straight off ' + + 'Each gated input but sys_invitation.actions.accept_invitation is also ' + + 'gated on `organization`, `multiOrgEnabled` or `admin`, so its `visible` ' + + 'predicate carries two gates. Also read straight off ' + '/auth/config by objectui (the Setup → Users copy, the password reminder).', }, phoneNumberOtp: { From 1b22e67b6d06dc68bf7866a35b95f7bf86f8f9c9 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 04:09:00 +0000 Subject: [PATCH 11/16] test,docs: pin the full membership census on a cloud-managed environment; docs and changeset state it Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- ...loud-managed-membership-changes-refused.md | 12 +++--- content/docs/permissions/authentication.mdx | 20 ++++++--- .../src/feature-gate-guard.test.ts | 6 +-- .../identity/cloud-managed-visibility.test.ts | 41 +++++++++++++++++++ .../src/platform-objects.test.ts | 8 ++-- .../plugin-auth/src/cloud-managed.test.ts | 36 +++++++++------- 6 files changed, 92 insertions(+), 31 deletions(-) diff --git a/.changeset/cloud-managed-membership-changes-refused.md b/.changeset/cloud-managed-membership-changes-refused.md index 6a87e70ed3e..951de16dd46 100644 --- a/.changeset/cloud-managed-membership-changes-refused.md +++ b/.changeset/cloud-managed-membership-changes-refused.md @@ -4,16 +4,16 @@ '@objectstack/spec': patch --- -fix(auth)!: a cloud-managed environment refuses remove-member and update-member-role; membership and roles are managed by the hosting organisation +fix(auth)!: on a cloud-managed environment every organization door that writes or deletes a membership row refuses, add-member excepted; membership is managed by the hosting organisation -Clause-②: no (narrowing) — narrowed: on a cloud-managed environment only (`OS_CLOUD_MANAGED=1`), `POST /organization/remove-member` and `POST /organization/update-member-role` now answer `409 RESOURCE_CONFLICT` to every request, where they removed the member or changed their role; Make Owner sends the owner role to update-member-role, so it is refused too. Two refusal sentences are added (`CLOUD_MANAGED_REFUSAL_MESSAGES.removeMember` and `.updateMemberRole`). The `sys_member` actions `update_member_role`, `remove_member` and `transfer_ownership` are hidden while `features.cloudManaged` is on, as the invite actions are, and `PUBLIC_AUTH_FEATURES.cloudManaged.gatedInputs` books the three paths. +Clause-②: no (narrowing) — narrowed: on a cloud-managed environment only (`OS_CLOUD_MANAGED=1`), six organization doors that write or delete a membership row now answer `409 RESOURCE_CONFLICT` to every request and write nothing, where they changed membership: `POST /organization/remove-member`, `POST /organization/update-member-role` (Make Owner calls it), `POST /organization/leave`, `POST /organization/accept-invitation`, `POST /organization/create` (it made the caller the new organization's owner) and `POST /organization/delete` (it ended every membership of the organization). Six refusal sentences are added (`CLOUD_MANAGED_REFUSAL_MESSAGES.removeMember`, `.updateMemberRole`, `.leaveOrganization`, `.acceptInvitation`, `.createOrganization`, `.deleteOrganization`). Their seven actions are hidden while `features.cloudManaged` is on, as the invite actions are (`sys_member.update_member_role`, `remove_member`, `transfer_ownership`; `sys_organization.leave_organization`, `create_organization`, `delete_organization`; `sys_invitation.accept_invitation`), and `PUBLIC_AUTH_FEATURES.cloudManaged.gatedInputs` books the seven paths. Metadata-protocol: none Skills-docs: none — no skill under `skills/**` teaches the organization membership doors or the cloud-managed mode; `content/docs/permissions/authentication.mdx` gains the rule in this change. - + -**BREAKING** for a cloud-managed environment (`OS_CLOUD_MANAGED=1`, set only on hosted containers): membership and membership roles are managed by the organisation that hosts the environment. `POST /organization/remove-member` (Remove Member) and `POST /organization/update-member-role` (Change Role, and Make Owner, which calls it) refuse every request with `409 RESOURCE_CONFLICT` and write nothing, as `POST /organization/invite-member` already did; the three row actions are hidden there. +**BREAKING** for a cloud-managed environment (`OS_CLOUD_MANAGED=1`, set only on hosted containers): membership and membership tiers are managed by the organisation that hosts the environment. Every organization door that writes or deletes a membership row refuses every request with `409 RESOURCE_CONFLICT` and writes nothing, as `POST /organization/invite-member` already did: Remove Member, Change Role and Make Owner, Leave Organization, Accept Invitation, Create Organization and Delete Organization. Their actions are hidden there. -Who moves: an owner (or administrator) of a cloud-managed environment who changed membership from inside the environment. Remove the person, or change their role, in the hosting organisation instead. +Who moves: an owner (or administrator) of a cloud-managed environment who changed membership from inside the environment, and a member who left, accepted an invitation, or created or deleted an organization there. Make the change in the hosting organisation instead. -Unchanged: every self-hosted deployment (the variable unset), where both doors answer as before; and `POST /organization/add-member`, which stays open on a managed environment to a platform administrator, to restore a membership the environment lost. +Unchanged: every self-hosted deployment (the variable unset), where every door answers as before; `POST /organization/add-member`, which on a managed environment admits exactly a platform administrator, adding a membership, to restore one the environment lost; and the organization doors that write no membership row (teams, invitations, the active organization, the organization's own fields) or only read. diff --git a/content/docs/permissions/authentication.mdx b/content/docs/permissions/authentication.mdx index 7b3862a31a4..d269a13f281 100644 --- a/content/docs/permissions/authentication.mdx +++ b/content/docs/permissions/authentication.mdx @@ -1309,16 +1309,26 @@ from the moment they are added, so seed data and approval flows can name them before they sign in. Off a managed environment both doors answer `409`. On a cloud-managed environment the organisation that hosts it decides who is a -member and at which membership tier, so the two doors that change an existing -membership (below; Make Owner calls the second) answer `409 RESOURCE_CONFLICT` -there and change nothing, and their row actions are hidden; the one exception -is `POST /api/v1/auth/organization/add-member`, which stays open to a platform -administrator to restore a membership the environment lost. +member and at which membership tier, so every organization door that writes or +deletes a membership row (below: removing a member, changing a member's tier +with Make Owner included, leaving, accepting an invitation, creating an +organization, which makes the caller its owner, and deleting one, which ends +every membership in it) answers `409 RESOURCE_CONFLICT` there and changes +nothing, and their actions are hidden. The one exception is +`POST /api/v1/auth/organization/add-member`, which admits exactly a platform +administrator, adding a membership, so the operator can restore one the +environment lost; anyone else is refused `403 PERMISSION_DENIED`. The other +organization doors write no membership row (teams, invitations, the active +organization, the organization's own fields) or only read, and answer as before. {/* os:vendor-wire better-auth */} ```http POST /api/v1/auth/organization/remove-member POST /api/v1/auth/organization/update-member-role +POST /api/v1/auth/organization/leave +POST /api/v1/auth/organization/accept-invitation +POST /api/v1/auth/organization/create +POST /api/v1/auth/organization/delete ``` Signing in does not lock the manager: a platform administrator still changes diff --git a/packages/platform-objects/src/feature-gate-guard.test.ts b/packages/platform-objects/src/feature-gate-guard.test.ts index 0016a881cb7..6747346bd4e 100644 --- a/packages/platform-objects/src/feature-gate-guard.test.ts +++ b/packages/platform-objects/src/feature-gate-guard.test.ts @@ -264,12 +264,12 @@ describe('feature-gate completeness guard (#2874)', () => { } it('finds the gated surface (guards the walker itself)', () => { - // 40 booked inputs exist today (37 before the three sys_member - // membership actions were hidden while cloud-managed; 38 before #9968 + // 44 booked inputs exist today (37 before the seven membership actions + // were hidden while cloud-managed; 38 before #9968 // retired sys_user.actions.set_user_role); if the walker ever goes // blind and finds none, the it.each below would vacuously pass — pin a // floor instead. - expect(referencedInputs.length).toBeGreaterThanOrEqual(40); + expect(referencedInputs.length).toBeGreaterThanOrEqual(44); }); it.each(referencedInputs)('%s references registered flag %s and is booked', (path, flag) => { diff --git a/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts b/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts index 389db40e300..623ee7b5d84 100644 --- a/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts +++ b/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts @@ -228,3 +228,44 @@ describe('features.cloudManaged hides the row actions that change a membership o expect(rowOffered('add_member', { ...OTHER_FLAGS, cloudManaged: true })).toBe(true); }); }); + +/** + * The rest of the membership census: every other action whose door writes or + * deletes a membership row is hidden while the flag is on, each offered as + * before when it is off. Leave Organization ends the caller's membership, + * Create Organization makes the caller an owner, Delete Organization ends + * every membership of the organization, and Accept Invitation creates one. + * Decline Invitation writes no membership, so it is not gated. + */ +describe('features.cloudManaged hides every other action whose door writes or deletes a membership row', () => { + const ORG_ROW = { id: 'org_1', name: 'Org', slug: 'org' }; + const INVITATION_ROW = { id: 'inv_1', email: ADMIN.email, status: 'pending', role: 'member', organization_id: 'org_1' }; + const MULTI = { ...OTHER_FLAGS, multiOrgEnabled: true }; + const FOUR: ReadonlyArray<[string, { actions?: unknown }, string, Record]> = [ + ['sys_organization.leave_organization', SysOrganization, 'leave_organization', ORG_ROW], + ['sys_organization.create_organization', SysOrganization, 'create_organization', {}], + ['sys_organization.delete_organization', SysOrganization, 'delete_organization', ORG_ROW], + ['sys_invitation.accept_invitation', SysInvitation, 'accept_invitation', INVITATION_ROW], + ]; + + const offeredOn = (def: { actions?: unknown }, name: string, record: Record, features: Record): boolean | string => { + const r = celEngine.evaluate( + { dialect: 'cel', source: visibleOf(def, name) }, + { record, extra: { current_user: ADMIN, user: ADMIN, ctx: { user: ADMIN }, features } }, + ); + if (!r.ok) return `FAULT ${r.error.message.split('\n')[0].trim()}`; + return typeof r.value === 'boolean' ? r.value : `NON-BOOLEAN ${JSON.stringify(r.value)}`; + }; + + it.each(FOUR)('%s is hidden while the environment is cloud-managed', (_site, def, name, record) => { + expect(offeredOn(def, name, record, { ...MULTI, cloudManaged: true })).toBe(false); + }); + + it.each(FOUR)('%s is offered as before when the flag is off', (_site, def, name, record) => { + expect(offeredOn(def, name, record, { ...MULTI, cloudManaged: false })).toBe(true); + }); + + it('sys_invitation.reject_invitation, which writes no membership, stays offered while the environment is cloud-managed', () => { + expect(offeredOn(SysInvitation, 'reject_invitation', INVITATION_ROW, { ...MULTI, cloudManaged: true })).toBe(true); + }); +}); diff --git a/packages/platform-objects/src/platform-objects.test.ts b/packages/platform-objects/src/platform-objects.test.ts index e42d77e4ebb..fcf4a3a6adf 100644 --- a/packages/platform-objects/src/platform-objects.test.ts +++ b/packages/platform-objects/src/platform-objects.test.ts @@ -743,16 +743,18 @@ describe('feature-gate lowering matrix (#2874)', () => { const MANAGED_ON = 'has(features.cloudManaged) && features.cloudManaged == true'; const rows: Array<[string, { actions?: readonly { name?: string; visible?: unknown; params?: readonly unknown[] }[] }, string, string]> = [ - ['SysOrganization', SysOrganization, 'create_organization', MULTI_ORG], + // Hidden while cloud-managed: create makes the caller an owner, and + // membership is the hosting organisation's there. + ['SysOrganization', SysOrganization, 'create_organization', `(${MANAGED}) && ${MULTI_ORG}`], // Their doors are better-auth's `organization/update` (owner, admin) and // `organization/delete` (owner), so the grade term leads the feature gate. ['SysOrganization', SysOrganization, 'update_organization', `${ADMINS} && ${MULTI_ORG}`], // [#25347] The name/logo-only rename is on the capability: under `single` // it is the one organization's only name door. ['SysOrganization', SysOrganization, 'rename_organization', `${ADMINS} && ${ORG}`], - ['SysOrganization', SysOrganization, 'delete_organization', `(${OWNER}) && ${MULTI_ORG}`], + ['SysOrganization', SysOrganization, 'delete_organization', `((${MANAGED}) && ${OWNER}) && ${MULTI_ORG}`], ['SysOrganization', SysOrganization, 'set_active_organization', MULTI_ORG], - ['SysOrganization', SysOrganization, 'leave_organization', MULTI_ORG], + ['SysOrganization', SysOrganization, 'leave_organization', `(${MANAGED}) && ${MULTI_ORG}`], ['SysUser', SysUser, 'invite_user', `((${MANAGED}) && ${INVITE}) && ${ORG}`], ['SysUser', SysUser, 'create_user', `(${STANDING} && ${MANAGED}) && features.admin == true`], // Their managed counterparts carry no feature gate (their doors mount diff --git a/packages/plugins/plugin-auth/src/cloud-managed.test.ts b/packages/plugins/plugin-auth/src/cloud-managed.test.ts index c30a8a34a2b..88621b4d096 100644 --- a/packages/plugins/plugin-auth/src/cloud-managed.test.ts +++ b/packages/plugins/plugin-auth/src/cloud-managed.test.ts @@ -223,10 +223,10 @@ beforeAll(async () => { * staging gave, so no case sees another's writes. The tests switch the mode * on afterwards: every door under test reads the accessor per request. */ -async function stage() { +async function stage(extra: Record = {}) { const engine = createMemoryEngine(); for (const [name, rows] of structuredClone(staged.tables)) engine.tables.set(name, rows); - const manager = makeManager(engine); + const manager = makeManager(engine, extra); const { ids, bearers } = staged; const users = () => (engine.tables.get('sys_user') ?? []) as any[]; @@ -805,15 +805,19 @@ describe('SSO-only mode keeps IdP-provisioned users off local passwords at the s /** * On a cloud-managed environment the organisation that hosts it manages who - * is a member and with which role. The two doors that change a membership, - * `remove-member` and `update-member-role` (Make Owner sends the owner role to - * the second), refuse with the invite-member envelope and write nothing; the - * remove-member permission arm and the role-change grant read stay behind the - * refusal, so neither runs. `add-member`, platform-administrator only, stays - * open: it restores a membership the environment lost. Self-hosted, every door - * answers as before. + * is a member and at which tier. Every organization door that writes or + * deletes a membership row refuses with the invite-member envelope and writes + * nothing: `remove-member`, `update-member-role` (Make Owner sends the owner + * tier to it), `leave`, `accept-invitation`, `create` (the caller would own + * the new organization) and `delete` (every membership would end). The arms + * behind the refusal (the remove-member permission judge, the role-change + * grant read, the organization-delete records judge) do not run. + * `add-member` stays open and admits exactly a platform administrator: it + * restores a membership the environment lost. Self-hosted, every door answers + * as before, and a door that writes no membership row (`reject-invitation`) + * answers as before on a managed environment too. */ -describe('on a cloud-managed environment, membership and roles are managed by the hosting organisation', () => { +describe('on a cloud-managed environment, membership and its tiers are managed by the hosting organisation', () => { type Staged = Awaited>; const memberships = (s: Staged) => ((s.engine.tables.get('sys_member') ?? []) as any[]).filter((m) => m.organization_id === DEFAULT_ORG); @@ -989,9 +993,13 @@ describe('on a cloud-managed environment, membership and roles are managed by th const organizations = (s: Staged) => (s.engine.tables.get('sys_organization') ?? []) as any[]; const allMemberships = (s: Staged) => (s.engine.tables.get('sys_member') ?? []) as any[]; const SECOND_ORG = { name: 'Second Org', slug: 'second-org-membership' }; + /** A walled posture, where a second organization may be created at all. */ + const multiOrg = () => stage({ + getTenancy: () => ({ ...singleOrgTenancy(), posture: 'isolated', requestedPosture: 'isolated', isolationActive: true }), + }); it('create answers 409 RESOURCE_CONFLICT to the owner: no organization and no owner membership are written', async () => { - const s = await stage(); + const s = await multiOrg(); const orgsBefore = structuredClone(organizations(s)); const membersBefore = structuredClone(allMemberships(s)); setManaged(true); @@ -1002,7 +1010,7 @@ describe('on a cloud-managed environment, membership and roles are managed by th }, 120_000); it('CONTROL: self-hosted, create answers 200 and makes the caller the new organization\'s owner as before', async () => { - const s = await stage(); + const s = await multiOrg(); const v = await verdict(await s.fire('/organization/create', SECOND_ORG, s.bearers.admin)); expect(v.status, v.text).toBe(200); const org = organizations(s).find((o) => o.slug === SECOND_ORG.slug); @@ -1012,7 +1020,7 @@ describe('on a cloud-managed environment, membership and roles are managed by th }, 120_000); it('delete answers 409 RESOURCE_CONFLICT to the owner, ahead of the records arm: the organization and its memberships remain', async () => { - const s = await stage(); + const s = await multiOrg(); const created = await verdict(await s.fire('/organization/create', SECOND_ORG, s.bearers.admin)); expect(created.status, `fixture: the organization is created while unmanaged — ${created.text}`).toBe(200); const org = organizations(s).find((o) => o.slug === SECOND_ORG.slug); @@ -1028,7 +1036,7 @@ describe('on a cloud-managed environment, membership and roles are managed by th }, 120_000); it('CONTROL: self-hosted, delete answers 200 and ends the organization\'s memberships as before', async () => { - const s = await stage(); + const s = await multiOrg(); const created = await verdict(await s.fire('/organization/create', SECOND_ORG, s.bearers.admin)); expect(created.status, `fixture: the organization is created — ${created.text}`).toBe(200); const org = organizations(s).find((o) => o.slug === SECOND_ORG.slug); From 6e53e34f286e95389c2e83e6e41b2f126021e216 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 04:09:33 +0000 Subject: [PATCH 12/16] test,docs: each new hide keeps its other gate; the docs name the six doors and seven actions Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- content/docs/permissions/authentication.mdx | 4 ++-- .../src/identity/cloud-managed-visibility.test.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/content/docs/permissions/authentication.mdx b/content/docs/permissions/authentication.mdx index d269a13f281..a91fbfe6fb0 100644 --- a/content/docs/permissions/authentication.mdx +++ b/content/docs/permissions/authentication.mdx @@ -1310,11 +1310,11 @@ before they sign in. Off a managed environment both doors answer `409`. On a cloud-managed environment the organisation that hosts it decides who is a member and at which membership tier, so every organization door that writes or -deletes a membership row (below: removing a member, changing a member's tier +deletes a membership row (the six below: removing a member, changing a member's tier with Make Owner included, leaving, accepting an invitation, creating an organization, which makes the caller its owner, and deleting one, which ends every membership in it) answers `409 RESOURCE_CONFLICT` there and changes -nothing, and their actions are hidden. The one exception is +nothing, and their seven actions are hidden. The one exception is `POST /api/v1/auth/organization/add-member`, which admits exactly a platform administrator, adding a membership, so the operator can restore one the environment lost; anyone else is refused `403 PERMISSION_DENIED`. The other diff --git a/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts b/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts index 623ee7b5d84..08925e08a93 100644 --- a/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts +++ b/packages/platform-objects/src/identity/cloud-managed-visibility.test.ts @@ -265,6 +265,19 @@ describe('features.cloudManaged hides every other action whose door writes or de expect(offeredOn(def, name, record, { ...MULTI, cloudManaged: false })).toBe(true); }); + // Each keeps its other gate: the three organization actions their + // `multiOrgEnabled` gate, Accept Invitation its pending-row predicate. + const OTHER_GATE_OFF: ReadonlyArray<[string, { actions?: unknown }, string, Record, Record]> = [ + ['sys_organization.leave_organization', SysOrganization, 'leave_organization', ORG_ROW, { ...OTHER_FLAGS, multiOrgEnabled: false, cloudManaged: false }], + ['sys_organization.create_organization', SysOrganization, 'create_organization', {}, { ...OTHER_FLAGS, multiOrgEnabled: false, cloudManaged: false }], + ['sys_organization.delete_organization', SysOrganization, 'delete_organization', ORG_ROW, { ...OTHER_FLAGS, multiOrgEnabled: false, cloudManaged: false }], + ['sys_invitation.accept_invitation', SysInvitation, 'accept_invitation', { ...INVITATION_ROW, status: 'accepted' }, { ...MULTI, cloudManaged: false }], + ]; + + it.each(OTHER_GATE_OFF)('%s keeps its other gate: closed, it hides the action whatever cloudManaged says', (_site, def, name, record, features) => { + expect(offeredOn(def, name, record, features)).toBe(false); + }); + it('sys_invitation.reject_invitation, which writes no membership, stays offered while the environment is cloud-managed', () => { expect(offeredOn(SysInvitation, 'reject_invitation', INVITATION_ROW, { ...MULTI, cloudManaged: true })).toBe(true); }); From dc93845fe941accac09bf93c3dcdad9438e9ceb5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 04:28:37 +0000 Subject: [PATCH 13/16] test(platform-objects): the lowering matrix pins accept_invitation's served predicate Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- packages/platform-objects/src/platform-objects.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/platform-objects/src/platform-objects.test.ts b/packages/platform-objects/src/platform-objects.test.ts index fcf4a3a6adf..9550679fcb3 100644 --- a/packages/platform-objects/src/platform-objects.test.ts +++ b/packages/platform-objects/src/platform-objects.test.ts @@ -791,6 +791,10 @@ describe('feature-gate lowering matrix (#2874)', () => { ['SysInvitation', SysInvitation, 'invite_user', `((${MANAGED}) && ${INVITE}) && ${ORG}`], ['SysInvitation', SysInvitation, 'cancel_invitation', `${ADMINS} && ${ORG}`], ['SysInvitation', SysInvitation, 'resend_invitation', `((${MANAGED}) && ${INVITE}) && ${ORG}`], + // No feature gate to lower: the authored pending-row predicate is served + // as written, with the cloud-managed conjunct (accepting creates a + // membership, which the hosting organisation manages there). + ['SysInvitation', SysInvitation, 'accept_invitation', `has(record.email) && record.email == ctx.user.email && has(record.status) && record.status == 'pending' && ${MANAGED}`], ['SysTeam', SysTeam, 'create_team', `${ADMINS} && ${ORG}`], ['SysTeam', SysTeam, 'update_team', `${ADMINS} && ${ORG}`], ['SysTeam', SysTeam, 'remove_team', `${ADMINS} && ${ORG}`], From d25bb9f5a1eb5bb8d3984643e3be2bf45b7e6fd5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 08:50:08 +0000 Subject: [PATCH 14/16] docs(permissions): add-member names its tier in the required role; no session answers 401 Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- content/docs/permissions/authentication.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/content/docs/permissions/authentication.mdx b/content/docs/permissions/authentication.mdx index a91fbfe6fb0..6f45e6b7710 100644 --- a/content/docs/permissions/authentication.mdx +++ b/content/docs/permissions/authentication.mdx @@ -1317,7 +1317,11 @@ every membership in it) answers `409 RESOURCE_CONFLICT` there and changes nothing, and their seven actions are hidden. The one exception is `POST /api/v1/auth/organization/add-member`, which admits exactly a platform administrator, adding a membership, so the operator can restore one the -environment lost; anyone else is refused `403 PERMISSION_DENIED`. The other +environment lost. The administrator names the membership tier in the request's +required `role` (a request without one is refused `400`), and ObjectStack passes +it to better-auth unchanged. A signed-in caller who is not a platform +administrator is refused `403 PERMISSION_DENIED`, and a caller with no session +is answered `401 UNAUTHENTICATED`. The other organization doors write no membership row (teams, invitations, the active organization, the organization's own fields) or only read, and answer as before. From 74eb16dca1b1896d965548c01e1de4acf9ab0c75 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 09:00:13 +0000 Subject: [PATCH 15/16] test(dogfood): change_slug's multi-org cross-check reads set_active_organization, the action gated by multi-org alone Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .../test/org-change-slug-bound-action.dogfood.test.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/qa/dogfood/test/org-change-slug-bound-action.dogfood.test.ts b/packages/qa/dogfood/test/org-change-slug-bound-action.dogfood.test.ts index ae8876d9e38..1b2e0e245a3 100644 --- a/packages/qa/dogfood/test/org-change-slug-bound-action.dogfood.test.ts +++ b/packages/qa/dogfood/test/org-change-slug-bound-action.dogfood.test.ts @@ -119,10 +119,14 @@ describe('a cloud-shaped composition binds change_slug to sys_organization, and it('carries the multiOrgEnabled gate, lowered as the platform lowers its own', () => { const changeSlug = actions.find((a) => a.name === 'change_slug'); - const leave = actions.find((a) => a.name === 'leave_organization'); + const setActive = actions.find((a) => a.name === 'set_active_organization'); expect(changeSlug?.visible).toEqual({ dialect: 'cel', source: featureGatePredicate('multiOrgEnabled') }); - // The platform's own multi-org action, gated by nothing else, serves the same predicate. - expect(changeSlug?.visible).toEqual(leave?.visible); + // The reference is `set_active_organization`: of the platform's own + // `sys_organization` actions it is the one whose only gate is + // `requiresFeature: 'multiOrgEnabled'` (no `visible` of its own, no + // membership reach), so its served predicate is the multi-org gate exactly + // as the platform lowers it, and nothing else. + expect(changeSlug?.visible).toEqual(setActive?.visible); }); it('the gate admits it with multi-org on and hides it with multi-org off', () => { From 852c9a0e942bfc395181fa9739dd889144632c35 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 09:07:14 +0000 Subject: [PATCH 16/16] docs(permissions): name add-member's tier field without the reserved word Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- content/docs/permissions/authentication.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/docs/permissions/authentication.mdx b/content/docs/permissions/authentication.mdx index 33b30255002..e593728b4ca 100644 --- a/content/docs/permissions/authentication.mdx +++ b/content/docs/permissions/authentication.mdx @@ -1318,9 +1318,9 @@ every membership in it) answers `409 RESOURCE_CONFLICT` there and changes nothing, and their seven actions are hidden. The one exception is `POST /api/v1/auth/organization/add-member`, which admits exactly a platform administrator, adding a membership, so the operator can restore one the -environment lost. The administrator names the membership tier in the request's -required `role` (a request without one is refused `400`), and ObjectStack passes -it to better-auth unchanged. A signed-in caller who is not a platform +environment lost. The administrator names the membership tier in the request +body, where it is required (a request without it is refused `400`), and +ObjectStack passes it to better-auth unchanged. A signed-in caller who is not a platform administrator is refused `403 PERMISSION_DENIED`, and a caller with no session is answered `401 UNAUTHENTICATED`. The other organization doors write no membership row (teams, invitations, the active