Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions .changeset/34971-allowlist-invite-grant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/plugin-auth': patch
'@objectstack/spec': patch
---

fix(plugin-auth)!: an invited sign-up the audience posture's own rule admits receives the declared self-registration permission set, and is refused when that set cannot be resolved

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches the audience posture's invitation sign-up or `selfRegistrationPermissionSet`; `content/docs/deployment/self-hosting.mdx` gains the rule in this change.

<!-- adr-0087: registered self-registration-permission-set-reaches-invited-sign-ups -->

**BREAKING** for a deployment under the `open` audience posture, or under `email_domain` for an address on `allowedEmailDomains`, whose declared `selfRegistrationPermissionSet` cannot be resolved (no such set, or the set is switched off) and that relies on an invited person still being able to sign up.

- Under `open`, and under `email_domain` for an address on the allowlist, a self-serve sign-up is admitted by the posture's own rule, invitation or not. It now receives the declared `selfRegistrationPermissionSet` whether or not it also holds a pending invitation. Before, a pending invitation addressed to it was read ahead of the posture in `decideAudienceAdmission` (`audience-posture.ts`), and the sign-up was admitted with no self-registration grant, though the membership settle already treated it as admitted by the posture and bound it at creation. The verdict and the settle now read one classification, the module-private `isAdmittedByPostureRule`.
- When the declared set cannot be resolved, such an invited sign-up is now refused `403 AUTH_CONFIG_ERROR`, naming the set, as an uninvited one already was. No account is created. Before, the invitation admitted it without the set.
- The invitation still places the sign-up as it names: once the address is verified and the invitation accepted, the membership and role it names are written beside the grant.

Unchanged: under `invite_only` an invitation admits with no self-registration grant; under `email_domain` an address off the allowlist that an invitation admitted gets the account and no grant, and is not bound while its address is unverified, whatever state the declared set is in; operator, bootstrap and SSO-provider creations; a social-provider creation whose address the provider did not verify is still refused under `email_domain`, and under `open` while email verification is in force; `admin_full_access` is still refused as the self-registration set.

No authorable key, accepted value or default changes; `selfRegistrationPermissionSet` keeps its meaning, the set each self-registrant receives, and now reaches the invited sign-ups its posture admits.

What to do: keep `selfRegistrationPermissionSet` naming a permission set that exists and is switched on. A person refused this way signs up again once an administrator has corrected the setting or switched the set on, or an administrator creates the account directly. An invitation can expire while the set is broken; send it again after the fix.
19 changes: 17 additions & 2 deletions content/docs/deployment/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,28 @@ the list admits that address's sign-up. Verification is forced on under this
posture, and while the account's address is unverified it joins no
organization: it joins by accepting the invitation once the address is
verified, and the acceptance writes the membership the invitation names. Verifying the address binds nothing by itself.
An address on the list is admitted by its domain, invitation or not, and the
membership policy binds it at creation as before. Both admissions have one
An address on the list is admitted by its domain, invitation or not: the
membership policy binds it at creation as before, it receives the declared
`selfRegistrationPermissionSet` like an uninvited sign-up, and a pending
invitation still places it as the invitation names once it accepts. Both admissions have one
exception: under this posture a sign-in through a social provider creates an
account only when the provider reports the address verified, and is otherwise
refused `403 SELF_REGISTRATION_CLOSED`, whatever the list or an invitation
says ([Authentication](/docs/permissions/authentication#2-handle-callback)).
Once the provider verifies the address, the next sign-in is admitted.
Under `open` every address is admitted by the posture, invitation or not, so an
invited sign-up likewise receives the declared set beside its invitation.

**A sign-up the posture admits needs its declared set, invited or not.** When
`selfRegistrationPermissionSet` cannot be resolved (no such set, or the set is
switched off), every sign-up the posture's own rule admits is refused
`403 AUTH_CONFIG_ERROR`, and the message names the set: any address under
`open`, an address on the list under `email_domain`, with or without a pending
invitation. Nothing is created, and the deployment logs the same reason at
error level. Correct the setting, or switch the set on, and the next sign-up is
admitted. A pending invitation does not admit such a sign-up without the set.
The two admissions an invitation makes alone, under `invite_only` and for an
address off the list under `email_domain`, ask for no set and are unaffected.

**Accepting, declining and listing an invitation need a verified email
address, on every deployment.** The invitation's `id`, which its link carries,
Expand Down
71 changes: 71 additions & 0 deletions packages/plugins/plugin-auth/src/audience-posture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import { assertEngineDeleteDispatch, assertEngineUpdateDispatch, assertEngineFin
import { ERROR_CODE_LEDGER } from '@objectstack/spec/api';
import { MCP_AGENT_PERMISSION_SETS } from '@objectstack/spec/ai';
import { AuthManager } from './auth-manager';
// The SSO discovery egress guard the source loads with a dynamic import, paid
// here, during collection (check-test-source-alias, "The source reach").
import '@objectstack/core/egress';
import { bindTestSecurityCatalog, catalogFromTables } from './__tests__/security-catalog.testkit.js';
import {
assertAudienceConfig,
Expand Down Expand Up @@ -339,6 +342,31 @@ describe('admission decision matrix (#11739): posture × creation class', () =>
expect(verdict).toEqual({ admit: true, grantPermissionSet: false });
});

// A sign-up the posture's own rule admits is admitted by that rule,
// invitation or not, and receives the declared set; one admitted by its
// invitation alone gets the account and no grant.
it.each([
['email_domain', 'on the allowlist', 'colleague@acme.com', true, { admit: true, grantPermissionSet: true }],
['email_domain', 'on the allowlist', 'colleague@acme.com', false, { admit: true, grantPermissionSet: true }],
['email_domain', 'off the allowlist', 'contractor@external.com', true, { admit: true, grantPermissionSet: false }],
['open', 'any address', 'anyone@external.com', true, { admit: true, grantPermissionSet: true }],
['open', 'any address', 'anyone@external.com', false, { admit: true, grantPermissionSet: true }],
['invite_only', 'any address', 'anyone@external.com', true, { admit: true, grantPermissionSet: false }],
] as const)('%s, an address %s (%s), invited %s: %o', (posture, _where, email, invited, expected) => {
const verdict = decideAudienceAdmission({
...base,
email,
hasPendingInvitation: invited,
audience: audience({
posture,
allowedEmailDomains: posture === 'email_domain' ? ['acme.com'] : [],
selfRegistrationPermissionSet: posture === 'invite_only' ? undefined : 'portal_user',
}),
creationClass: 'self-serve',
});
expect(verdict).toEqual(expected);
});

it('open admits self-serve with the grant', () => {
const verdict = decideAudienceAdmission({
...base,
Expand Down Expand Up @@ -921,6 +949,47 @@ describe('end of the chain: better-auth pipeline over the memory engine (#11739)
expect((engine.tables.get('sys_user') ?? []).length).toBe(1);
});

// An invited sign-up the posture's own rule admits is a self-registrant: it
// asks for the declared set like an uninvited one, so a set that cannot be
// resolved refuses it too. The invitation does not admit it without the grant.
it.each([
['open', 'missing', { posture: 'open' }, 'invited@anywhere.com'],
['open', 'switched off', { posture: 'open' }, 'invited@anywhere.com'],
['email_domain (on the allowlist)', 'missing', { posture: 'email_domain', allowedEmailDomains: ['acme.com'] }, 'invited@acme.com'],
['email_domain (on the allowlist)', 'switched off', { posture: 'email_domain', allowedEmailDomains: ['acme.com'] }, 'invited@acme.com'],
] as const)('%s: an invited sign-up whose declared set is %s is refused AUTH_CONFIG_ERROR, like an uninvited one', async (_posture, state, posture, email) => {
const engine = createMemoryEngine();
seedExistingUser(engine);
if (state === 'switched off') {
seedPermissionSet(engine, 'member_default');
engine.tables.set('sys_metadata_activation', [
{ id: 'act_member', metadata_type: 'permission', name: 'member_default', package_id: 'pkg', active: false },
]);
}
seedPendingInvitation(engine, email);
const set = state === 'missing' ? 'ghost' : 'member_default';
const manager = makeManager(engine, { audience: { ...posture, selfRegistrationPermissionSet: set } });
const res = await signUp(manager, email);
expect(res.status).toBe(403);
const body = await res.json();
expect(body.code).toBe(AUDIENCE_CONFIG_ERROR);
expect(String(body.message)).toContain(`'${set}'`);
expect((engine.tables.get('sys_user') ?? []).length).toBe(1);
});

it('CONTROL: email_domain, an invited sign-up OFF the allowlist is admitted by its invitation alone, asking for no set, so a missing set does not refuse it', async () => {
const engine = createMemoryEngine();
seedExistingUser(engine);
seedPendingInvitation(engine, 'contractor@external.com');
const manager = makeManager(engine, {
audience: { posture: 'email_domain', allowedEmailDomains: ['acme.com'], selfRegistrationPermissionSet: 'ghost' },
});
const res = await signUp(manager, 'contractor@external.com');
expect(res.status, await res.clone().text()).toBeLessThan(300);
expect((engine.tables.get('sys_user') ?? []).length).toBe(2);
expect(engine.tables.get('sys_user_permission_set') ?? []).toEqual([]);
});

it('[ADR-0131 D3] the set ROW\'s `active` switches nothing: a row flagged off still admits and grants', async () => {
// The resolver reads no catalog row, so the row flag is not a deactivation.
const engine = createMemoryEngine();
Expand Down Expand Up @@ -1165,6 +1234,8 @@ describe('a self-serve social creation under an address-based posture is admitte
admit: true,
grantPermissionSet: false,
});
// On the allowlist, the verified creation is admitted by its domain, invitation or not.
expect(decide({ hasPendingInvitation: true, emailVerified: true })).toEqual({ admit: true, grantPermissionSet: true });
});

it('open: refused while email verification is in force (undeclared or declared true), an invitation included', () => {
Expand Down
70 changes: 54 additions & 16 deletions packages/plugins/plugin-auth/src/audience-posture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@
* `email_domain` an explicit invitation also trumps the domain list — an
* operator inviting an external contractor must not dead-end them), except a
* social-provider creation whose address the provider did not verify under a
* posture whose admission rests on the address (below). Without
* this carve-out the posture would be "admin-create only" and the invitation
* surface would be dead for new users — the invite dead-end class.
* posture whose admission rests on the address (below), and except a creation
* the posture's own rule already admits ({@link isAdmittedByPostureRule}): that
* one is a self-registrant, invitation or not, so it asks for the declared
* self-registration set and is refused with the uninvited sign-up when the set
* cannot be resolved — the invitation does not admit it without the grant.
* Without this carve-out the posture would be "admin-create only" and the
* invitation surface would be dead for new users — the invite dead-end class.
*
* What "holding" means is {@link invitationProofFor}'s answer. Under
* `invite_only` a self-serve sign-up is admitted only by the invitation it
Expand All @@ -76,9 +80,14 @@
*
* Admission by an invitation alone grants the account and nothing more
* ({@link isAdmittedByInvitationAlone}): under `invite_only`, and under
* `email_domain` for an address off the list, the sign-up is not bound into
* the deployment's organization while its address is unverified, and joins by
* accepting the invitation.
* `email_domain` for an address off the list, the sign-up receives no
* self-registration permission set, is not bound into the deployment's
* organization while its address is unverified, and joins by accepting the
* invitation. A sign-up the posture's own rule admits — any address under
* `open`, an address on the list under `email_domain` — is admitted by that
* rule, invitation or not ({@link isAdmittedByPostureRule}): it receives the
* declared set and binds as an uninvited one does, and the invitation still
* places it as the invitation names once it accepts.
*
* ## A social provider's word on the address
*
Expand Down Expand Up @@ -120,7 +129,8 @@
* ("a valid posture said no") because sending the debugger to re-read a
* setting that looks exactly as they left it is the recorded failure mode. A
* declared permission set that cannot be resolved refuses admission the same
* way: admitting a self-registrant WITHOUT the declared grant would be the
* way, for every sign-up the posture's rule admits, invited or not: admitting
* a self-registrant WITHOUT the declared grant would be the
* ADR-0078 "declared but inert" defect at runtime, and fail-open is the one
* direction this gate must never take.
*/
Expand Down Expand Up @@ -603,7 +613,8 @@ export function invitationProofFor(input: {
* unexpired and addressed to it ({@link invitationProofFor} `presented`).
* - `email_domain`: the sign-up's address is off the allowlist, and a pending
* invitation addressed to it admitted it. An address on the list is admitted
* by the domain rule, invitation or not, and binds as before.
* by the domain rule, invitation or not ({@link isAdmittedByPostureRule}),
* binds as before and receives the declared self-registration set.
* - `open`, an off-vocabulary posture, and every creation that is not
* self-serve: never.
*/
Expand All @@ -616,8 +627,26 @@ export function isAdmittedByInvitationAlone(input: {
}): boolean {
const { audience, creationClass, email, proof, hasPendingInvitation } = input;
if (!hasPendingInvitation || audience.invalid || creationClass !== 'self-serve') return false;
// `open`, and `email_domain` on the allowlist: admitted by the posture's rule.
if (isAdmittedByPostureRule(audience, email)) return false;
if (audience.posture === 'invite_only') return proof === 'presented';
if (audience.posture === 'email_domain') return !emailDomainAllowed(email, audience.allowedEmailDomains);
return audience.posture === 'email_domain';
}

/**
* Whether a valid posture's own rule admits a self-serve creation by its
* address, with no invitation: `open` admits every address, `email_domain` an
* address on the allowlist ({@link emailDomainAllowed}), and `invite_only`
* none. The one classification both readers of an invitation share: a
* sign-up the rule admits is admitted by that rule, invitation or not, so the
* admission verdict grants it the declared self-registration set
* ({@link decideAudienceAdmission}) and the membership settle binds it at
* creation ({@link isAdmittedByInvitationAlone}).
*/
function isAdmittedByPostureRule(audience: ResolvedAudience, email: string | undefined): boolean {
if (audience.invalid) return false;
if (audience.posture === 'open') return true;
if (audience.posture === 'email_domain') return emailDomainAllowed(email, audience.allowedEmailDomains);
return false;
}

Expand All @@ -636,7 +665,9 @@ const socialAddressUnverifiedMessage = (posture: AudiencePosture): string =>
/**
* THE admission decision — pure, so the posture × method matrix is a table of
* direct calls. Order: creation-class exemptions → bootstrap → vocabulary
* guard (fail closed) → the social-provider address rule → posture semantics.
* guard (fail closed) → the social-provider address rule → the posture's own
* rule ({@link isAdmittedByPostureRule}, with the self-registration grant) →
* the invitation carve-out (no grant) → the posture's refusal.
*
* The social-provider address rule: under a posture whose admission rests on
* the address ({@link admissionRestsOnAddress}: `email_domain` always, `open`
Expand Down Expand Up @@ -682,10 +713,20 @@ export function decideAudienceAdmission(input: AudienceAdmissionInput): Audience
) {
return { admit: false, code: SELF_REGISTRATION_CLOSED, message: socialAddressUnverifiedMessage(audience.posture) };
}
if (isAdmittedByPostureRule(audience, email)) {
// The posture's own rule first: `open`, and `email_domain` for an address
// on the allowlist, admit the sign-up by that rule, invitation or not, so
// it receives the declared self-registration set. A pending invitation
// still places it as the invitation names once it accepts. The membership
// settle reads the same classification (`isAdmittedByInvitationAlone`).
return { admit: true, grantPermissionSet: true };
}
if (hasPendingInvitation) {
// An explicit invitation is a stronger operator act than any posture —
// it admits the invitee's own account creation under invite_only AND
// trumps the email_domain allowlist (module doc: the invite dead-end).
// Admitted by the invitation alone, the sign-up gets the account and no
// self-registration grant.
return { admit: true, grantPermissionSet: false };
}
switch (audience.posture) {
Expand All @@ -698,20 +739,17 @@ export function decideAudienceAdmission(input: AudienceAdmissionInput): Audience
'Ask an administrator for an invitation.',
};
case 'email_domain':
if (emailDomainAllowed(email, audience.allowedEmailDomains)) {
return { admit: true, grantPermissionSet: true };
}
// An address on the allowlist was admitted by the posture's rule above.
return {
admit: false,
code: EMAIL_DOMAIN_NOT_ALLOWED,
message:
'Self-registration is limited to approved email domains, and this address ' +
'is not on the list. Use your organization email, or ask an administrator for an invitation.',
};
case 'open':
return { admit: true, grantPermissionSet: true };
default: {
// Unreachable for a well-typed posture; keep the fail-closed floor.
// `open` was admitted by the posture's rule above, so this is
// unreachable for a well-typed posture; keep the fail-closed floor.
return {
admit: false,
code: AUDIENCE_CONFIG_ERROR,
Expand Down
Loading
Loading