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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/plugin-auth': patch
---

fix(plugin-auth)!: a sign-up the email_domain posture admits by an invitation is not bound before its address is verified

Clause-②: no (narrowing) — narrowed: under the `email_domain` audience posture with `membershipPolicy: 'auto'`, a self-serve sign-up whose address is off the allowlist, admitted by a pending invitation addressed to it, is not bound to the Default Organization while its address is unverified; it joins by accepting the invitation.
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches the `email_domain` posture's invitation sign-up; `content/docs/deployment/self-hosting.mdx` gains the rule in this change.

<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value or metadata type is added, removed, renamed or re-shaped. The moved answer is a membership the sign-up seam does not write for an unverified invitation-admitted sign-up, so there is nothing stored for a migration to rewrite and no tombstone. -->

**BREAKING** for an `email_domain` deployment with `membershipPolicy: 'auto'` that relies on an invited address outside its allowlist joining the Default Organization when it signs up.

- Under `email_domain` with `membershipPolicy: 'auto'`, an account that a sign-up off the allowlist created, admitted by a pending invitation addressed to it, is not bound to the Default Organization while its address is unverified. Its membership comes from accepting the invitation once the address is verified, with the role the invitation carries, or from a platform administrator. Verifying the address binds nothing by itself.
- This is the rule that already holds under `invite_only` for a sign-up admitted by the invitation it presents; both postures now read one decision, `isAdmittedByInvitationAlone` (`audience-posture.ts`).

Unchanged: an address on the allowlist, invited or not, which the domain rule admits and the membership policy binds at creation; a sign-up the invitation mail's own link verifies as it accepts; the first account of a deployment, accounts an administrator creates and accounts a boot command provisions, which are bound as before; the `invite_only` and `open` postures.

What to do: an invitee outside the allowlist completes the verification mail the sign-up sends, signs in and accepts the invitation, or opens the invitation mail's own link, which verifies the address and accepts in one step. A platform administrator can instead attach the account with the member list's **Add Member** action.
2 changes: 1 addition & 1 deletion content/docs/deployment/environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Read by `@objectstack/service-print` when `PrintServicePlugin` is composed; see
| `OS_AUTH_EMAIL_PASSWORD_ENABLED` | boolean | settings default | Settings env override for `auth.email_password_enabled`. Controls local email/password login. |
| `OS_AUTH_SIGNUP_ENABLED` | boolean | settings default | Settings env override for `auth.signup_enabled`. Takes precedence over UI settings and is preferred over `OS_DISABLE_SIGNUP`. |
| `OS_AUTH_REQUIRE_EMAIL_VERIFICATION` | boolean | settings default | Settings env override for `auth.require_email_verification`. Under the `open` audience posture, `false` is the deployment's opt-out from the forced verification (one boot warning; see [Email verification under each posture](/docs/deployment/self-hosting#email-verification-under-each-posture)); under `email_domain` it is refused, since verification is forced there. |
| `OS_AUTH_MEMBERSHIP_POLICY` | `auto` \| `invite-only` | `auto` | Settings env override for `auth.membership_policy` — what a newly created user joins (ADR-0093 D1). `auto` binds every new user to the deployment's default organization, except, under the `invite_only` audience posture, a sign-up admitted by the invitation it presents whose address is unverified, which joins by accepting. `invite-only` grants membership solely through an explicit act: creating a workspace, accepting an invitation, an admin adding them, or SSO just-in-time provisioning. Applies to sign-up **and** to the backfill of pre-existing member-less users. An unrecognized value is rejected with an `error` log and **ignored** — the deployment keeps its current policy rather than silently reverting to `auto`. |
| `OS_AUTH_MEMBERSHIP_POLICY` | `auto` \| `invite-only` | `auto` | Settings env override for `auth.membership_policy` — what a newly created user joins (ADR-0093 D1). `auto` binds every new user to the deployment's default organization, except a sign-up admitted by its invitation alone whose address is unverified, which joins by accepting: under the `invite_only` audience posture, one admitted by the invitation it presents; under `email_domain`, one whose address is off the allowlist and which an invitation addressed to it admitted. `invite-only` grants membership solely through an explicit act: creating a workspace, accepting an invitation, an admin adding them, or SSO just-in-time provisioning. Applies to sign-up **and** to the backfill of pre-existing member-less users. An unrecognized value is rejected with an `error` log and **ignored** — the deployment keeps its current policy rather than silently reverting to `auto`. |
| `OS_ORG_INVITATION_LIMIT` | integer \| `off` | unset (100) | How many **pending** invitations one organization may hold at once. When the organization already holds that many, `POST /api/v1/auth/organization/invite-member` answers `403 INVITATION_LIMIT_REACHED` (`Invitation limit reached`) until an invitation is accepted, rejected, cancelled or expires. Unset keeps the auth library's own limit of 100, so a deployment that sets nothing behaves as before. A positive integer `N` allows `N`. `off`, `unlimited` or `none` (any case) removes the limit, for a host that invites people in bulk. `0`, or any value that is not plain digits (`-5`, `2.5`, `1e3`, `1_000`), reads as unset (100), so a typo never refuses every invitation. The count is per organization, not per inviter. Read when the auth plugin builds its organization plugin, so a change needs a process reload. |
| `OS_AUTH_GOOGLE_ENABLED` | boolean | settings default | Settings env override for `auth.google_enabled`. Requires Google OAuth credentials from Settings or env. |
| `GOOGLE_CLIENT_ID` | string | — | Deployment-level Google OAuth client id for the open-source Google login implementation. |
Expand Down
9 changes: 9 additions & 0 deletions content/docs/deployment/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,15 @@ account of a new deployment needs no invitation. Admission is all the
invitation's `id` grants: the account it admits joins no organization until it
accepts the invitation, and accepting needs a verified address.

**Under `email_domain`, an invitation admits an address off the allowlist, and
grants nothing more.** A pending invitation addressed to an address outside
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.

**Accepting, declining and listing an invitation need a verified email
address, on every deployment.** The invitation's `id`, which its link carries,
proves nothing about the mailbox. From a session whose address is not
Expand Down
12 changes: 8 additions & 4 deletions content/docs/deployment/tenancy-modes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,14 @@ The reconciler:
- **yields** to any membership that already exists (e.g. one created by an
invitation, `add-member`, SSO provisioning, or a host hook) — it never
creates a second membership;
- does **not** bind, under the `invite_only` audience posture, a sign-up
admitted by the invitation it presents while the account's email address is
unverified: that account joins by accepting the invitation, which needs a
verified address ([Self-hosting](/docs/deployment/self-hosting));
- does **not** bind a sign-up admitted by its invitation alone while the
account's email address is unverified — under the `invite_only` audience
posture, a sign-up admitted by the invitation it presents; under
`email_domain`, a sign-up whose address is off the allowlist and which an
invitation addressed to it admitted: that account joins by accepting the
invitation, which needs a verified address
([Self-hosting](/docs/deployment/self-hosting)). Under `email_domain` an
address on the allowlist is admitted by its domain and is bound;
- binds only to an **unambiguous** target org — that is `tenancy.defaultOrgId()`,
which returns the single-org default organization under `single` and `null`
under any walled **request** (invitations, `add-member` and SSO provisioning
Expand Down
8 changes: 5 additions & 3 deletions content/docs/permissions/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ OS_AUTH_SIGNUP_ENABLED=false
OS_AUTH_GOOGLE_ENABLED=true

# Optional: what a new user joins (ADR-0093 D1). `auto` (default) binds every
# new user to the default organization (except, under the `invite_only`
# audience posture, a sign-up admitted by the invitation it presents whose
# address is unverified: it joins by accepting); `invite-only` grants membership only
# new user to the default organization (except a sign-up admitted by its
# invitation alone whose address is unverified: under the `invite_only`
# audience posture, one admitted by the invitation it presents; under
# `email_domain`, one off the allowlist that an invitation addressed to it
# admitted. It joins by accepting); `invite-only` grants membership only
# through an explicit act — creating a workspace, accepting an invitation, an
# admin adding them, or SSO just-in-time provisioning.
# Also configurable in Setup → Authentication → Membership.
Expand Down
42 changes: 42 additions & 0 deletions packages/plugins/plugin-auth/src/audience-posture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
emailDomainAllowed,
extractEmailDomain,
invitationProofFor,
isAdmittedByInvitationAlone,
resolveAudience,
resolveEmailVerificationRequirement,
SELF_REGISTRATION_CLOSED,
Expand Down Expand Up @@ -1086,3 +1087,44 @@ describe('the invitation a creation must show (invitationProofFor)', () => {
expect(proof({ audience: audience({ posture: 'open' }), method: 'oauth', emailVerified: false })).toBe('address');
});
});

describe('a sign-up admitted by its invitation alone (isAdmittedByInvitationAlone)', () => {
const DOMAIN = audience({ posture: 'email_domain', allowedEmailDomains: ['acme.com'] });
const alone = (over: Partial<Parameters<typeof isAdmittedByInvitationAlone>[0]> = {}) =>
isAdmittedByInvitationAlone({
audience: DOMAIN,
creationClass: 'self-serve',
email: 'contractor@partner.example',
proof: 'address',
hasPendingInvitation: true,
...over,
});

it('under email_domain, an address off the allowlist admitted by an invitation addressed to it is admitted by its invitation alone', () => {
expect(alone()).toBe(true);
expect(alone({ email: 'Contractor@Mail.Acme.com' }), 'a subdomain is off the list').toBe(true);
expect(alone({ email: undefined }), 'no address is off the list').toBe(true);
});

it('under email_domain, an address on the allowlist is admitted by its domain, invitation or not', () => {
expect(alone({ email: 'colleague@acme.com' })).toBe(false);
expect(alone({ email: 'Colleague+tag@ACME.COM' })).toBe(false);
expect(alone({ email: 'colleague@acme.com', hasPendingInvitation: false })).toBe(false);
});

it('under invite_only, only a sign-up that presented its invitation is admitted by its invitation alone', () => {
const invite = audience();
expect(alone({ audience: invite, proof: 'presented' })).toBe(true);
expect(alone({ audience: invite, proof: 'address' })).toBe(false);
expect(alone({ audience: invite, proof: 'none' })).toBe(false);
});

it('a creation no pending invitation admitted, a creation that is not self-serve, open and an off-vocabulary posture are never admitted by an invitation alone', () => {
expect(alone({ hasPendingInvitation: false })).toBe(false);
expect(alone({ audience: audience(), proof: 'presented', hasPendingInvitation: false })).toBe(false);
expect(alone({ creationClass: 'operator' })).toBe(false);
expect(alone({ creationClass: 'provider' })).toBe(false);
expect(alone({ audience: audience({ posture: 'open' }) })).toBe(false);
expect(alone({ audience: { ...DOMAIN, invalid: { raw: "'bogus'" } } })).toBe(false);
});
});
38 changes: 38 additions & 0 deletions packages/plugins/plugin-auth/src/audience-posture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
* verified the address, is matched by address. `open` and `email_domain`
* match every creation by address.
*
* 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.
*
* ## Pinned domain-matching rules (`email_domain`)
*
* An unpinned matcher is where this class of gate leaks, so the rules are
Expand Down Expand Up @@ -525,6 +531,38 @@ export function invitationProofFor(input: {
return 'address';
}

/**
* Whether an admitted self-serve sign-up was admitted by its invitation alone,
* so the membership settle does not bind it into the deployment's
* organization while its address is unverified (`settleMembership`,
* `auth-manager-membership-admission.ts`). It joins by accepting the
* invitation, which needs a verified address and writes the role the issuer
* chose. An invitation proves no mailbox: under `invite_only` its id is
* carried by the accept link and by a copied link, and under `email_domain`
* the address match reads only the address the sign-up typed.
*
* - `invite_only`: the sign-up presented the invitation, which is pending,
* 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.
* - `open`, an off-vocabulary posture, and every creation that is not
* self-serve: never.
*/
export function isAdmittedByInvitationAlone(input: {
audience: ResolvedAudience;
creationClass: AudienceCreationClass;
email: string | undefined;
proof: InvitationProof;
hasPendingInvitation: boolean;
}): boolean {
const { audience, creationClass, email, proof, hasPendingInvitation } = input;
if (!hasPendingInvitation || audience.invalid || creationClass !== 'self-serve') return false;
if (audience.posture === 'invite_only') return proof === 'presented';
if (audience.posture === 'email_domain') return !emailDomainAllowed(email, audience.allowedEmailDomains);
return false;
}

/** The refusal message for an unknown user arriving through an SSO provider under `invite_only`. */
const SSO_JIT_CLOSED_MESSAGE =
'This single sign-on provider does not create accounts for people who were not invited ' +
Expand Down
Loading
Loading