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
25 changes: 25 additions & 0 deletions .changeset/auth-declared-defaults-every-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@objectstack/plugin-auth': patch
---

fix(plugin-auth)!: Setup → Authentication shows what the deployment runs for every auth setting it declares, and says when sign-up is forced off over a value saved on

Clause-②: yes (narrowing) — with nothing stored, 24 more `auth` keys answer the deployment's declaration where they answered the manifest default, so a published response changes for an existing reader, and a save of a key a declaration now shows or bounds can be refused where it was stored
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches the auth settings page, these keys or the settings cascade's bottom rung.

<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value or metadata type is added, removed, renamed or re-shaped: these are settings values, runtime state, not authorable metadata, and the settings manifest is unchanged. What moves is the value a key with nothing stored resolves to, which keys that value shows, and the save of it that a write predicate is now asked about; one stored case is read differently: an `audience_allowed_email_domains` or `audience_self_registration_permission_set` stored while no `audience_posture` is, ignored until now, takes effect under a declared audience. That is a settings row, not metadata, so there is nothing for `objectstack migrate meta` to rewrite and no tombstone; the upgrader's check is in the body. -->

What narrows: with nothing stored, `SettingsService.get('auth', …)` and `GET /api/settings/auth` answer 24 more `auth` keys with the deployment's declaration (still `source: 'default'`) where they answered the manifest default: `password_min_length`, `password_max_length`, `membership_policy`, `password_reject_breached`, `password_require_complexity`, `password_min_classes`, `password_history_count`, `password_expiry_days`, `mfa_required`, `mfa_grace_period_days`, `api_key_default_expiry_days`, `api_key_max_expiry_days`, `api_key_inactivity_days`, `session_expiry_days`, `session_refresh_days`, `session_idle_timeout_minutes`, `session_absolute_max_hours`, `max_concurrent_sessions_per_user`, `allowed_ip_ranges`, `lockout_threshold`, `lockout_duration_minutes`, `audience_posture`, `audience_allowed_email_domains`, `audience_self_registration_permission_set`; so a published response's value changes for an existing reader on any deployment whose own configuration differs from the manifest default for one of them. Four keys gate another key's visibility, so with nothing stored a declaration now shows a key that was hidden, and a save that touches it or its gate is judged for its options and bounds where it was not: `lockout_duration_minutes` under a declared `lockoutThreshold` above 0 (for example `lockout_duration_minutes: 5000` is now refused `400 SETTINGS_VALIDATION` where it was stored), `mfa_grace_period_days` under a declared `mfaRequirement` other than `off`, `password_min_classes` under a declared `passwordRequireComplexity: true`, and `audience_allowed_email_domains` / `audience_self_registration_permission_set` under a declared `audience.posture` of `email_domain` or `open`. A save that sets one of these keys to its manifest default where the declaration differs now asks the key's write predicates. Widened: a save that sets one of these keys to the declaration with nothing stored is no change and asks no predicate. The Setup → Authentication live-status banner adds a `warning` for `signup_enabled` stored on where the deployment forces sign-up off (SSO-only, cloud-managed, `OS_DISABLE_SIGNUP`), in all 11 languages; where both that and the cloud-managed email-and-password hold apply, one banner carries both statements.

A declared value outside its specifier's own bounds or options is answered as declared, because it is what runs, and is then judged whenever the key is touched without a value of its own: a clear of that key beside any other key in one patch, or a save of `email_password_enabled`, which gates the visibility of eight of these keys (the password keys and `mfa_required`). For example a declared `session.expiresIn` under one day reads below `session_expiry_days`'s minimum of 1, and a declared `minPasswordLength` under 6 below `password_min_length`'s; such a save is refused `400 SETTINGS_VALIDATION` at that key, where the manifest default sat in the slot and passed. Save the key within its bounds in the same patch, or clear it alone.

The audience trio is one declaration the auth manager replaces whole. Once any of the three is stored, the settings pass now composes the audience from the three as the page reads them: each as stored, else as the deployment declares it. A domain list or permission set saved alone under a declared posture now runs, where it was stored and ignored; a posture saved beside a declared permission set the console did not resend now runs with that set, where it was refused. A saved audience the merged-result validation refuses is still refused, and the standing audience keeps ruling. A sibling saved where the deployment declares no audience is still ignored, with no posture to read it under.

**BREAKING** for a reader of `GET /api/settings/auth` or `SettingsService.get('auth', …)` on a deployment whose own configuration differs from the manifest default for one of these keys, with nothing saved: the value answered is now what runs (for example `lockout_threshold: { value: 5, source: 'default' }` where the deployment declares `lockoutThreshold: 5`), not the manifest default. A saved value and an `OS_AUTH_*` override still win, and a clear returns to the declaration. A deployment that declares none of these reads exactly as before.

**BREAKING** also for a deployment that declares an audience (`audience` in its auth configuration) and holds a stored `audience_allowed_email_domains` or `audience_self_registration_permission_set` with no stored `audience_posture` (left by clearing the posture alone, or set through that key's `OS_AUTH_*` override alone). Every earlier release ignored such a value with an `error` line; from this release it takes effect under the declared posture, so it can change which email domains may self-register, or which permission set a self-registered user receives.

Each answer takes the key's own shape: session lifetimes in days (the declared seconds divided by 86 400), allowed IP ranges and email domains one per line, and a select's value only when it is one of its options (an off-vocabulary `membershipPolicy` or `mfaRequirement` leaves the manifest default). Not stated, by design: `rate_limit_max` and `rate_limit_window_seconds` (with nothing stored, the auth library's own per-path rules run, or, under a declared `rateLimit`, that declared global pair; neither is the per-endpoint cap the setting writes, so no one number states what runs), `api_key_policy_started_at` (recorded into the store at first boot), and the Google keys (the toggle's runtime default is the manifest default, and a declared credential outranks a saved one).

What to do: before upgrading a deployment that declares an audience, look for `audience_allowed_email_domains` or `audience_self_registration_permission_set` stored while `audience_posture` is not (on `GET /api/settings/auth`, either key with a `source` other than `default` while `audience_posture` reads `source: 'default'`), including one set through its `OS_AUTH_*` override alone; clear it, or confirm it is the value to enforce. Nothing else to migrate. A client that read `source: 'default'` as "the manifest default" should read it as "nothing is saved; this is the deployment's default".
14 changes: 11 additions & 3 deletions content/docs/protocol/kernel/config-resolution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ configuration when nothing is stored (plugin options, a host declaration)
states that value with `registerDeclaredDefault(namespace, key, provider)`;
otherwise the manifest `default` answers. Either way the answer reports
`source: 'default'`: nothing is stored, and a clear returns to it. The auth
plugin states `email_password_enabled`, `signup_enabled` and
`require_email_verification` this way, so Setup → Authentication shows what
the deployment runs, not a console default it never applies.
plugin states every `auth` key its runtime takes from the deployment's own
configuration this way (the sign-in switches, password, MFA, API-key,
session, network, lockout, membership and audience settings), so
Setup → Authentication shows what the deployment runs, not a console default
it never applies. It leaves three groups on the manifest default. The
rate-limit pair: with nothing stored the auth library's own per-path rules
run, or a declared `rateLimit` global pair, and neither is the per-endpoint
cap the setting writes. The Google sign-in keys: the toggle's runtime default
is the manifest's, and a declared credential outranks a saved one, so it is
not what a clear returns to. And the API-key policy start date, which the
first boot records into the store.

Two rules follow from the walk, and both are enforced in `SettingsService`:

Expand Down
113 changes: 75 additions & 38 deletions packages/plugins/plugin-auth/src/auth-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
// same question. [#14157] The dev-admin seed no longer GATES on it (a
// directory row is not a login); it still reads it to find the seed account
// among existing users when re-arming the credential hint.
import { isHumanUserRow, OPEN_POSTURE_VERIFICATION_OFF_WARNING } from './audience-posture.js';
import { isHumanUserRow, OPEN_POSTURE_VERIFICATION_OFF_WARNING, resolveAudience } from './audience-posture.js';
// [#14157] The dev-admin seed's own precondition — "does a login exist?".
import { decideDevAdminSeedGate } from './dev-admin-seed-gate.js';
import { localizationMailCurrencyResolver, withMailTenantCurrency } from './mail-tenant-currency.js';
Expand Down Expand Up @@ -159,7 +159,12 @@ import {
ssoProviderDeleteRefusal,
type SignInMethodFloorDeps,
} from './sign-in-method-floor.js';
import { describeEmailPasswordLiveStatus, type AuthLiveStatus } from './auth-settings-live-status.js';
import {
combineAuthLiveStatus,
describeEmailPasswordLiveStatus,
describeSignUpLiveStatus,
type AuthLiveStatus,
} from './auth-settings-live-status.js';
import { registerAuthDeclaredDefaults } from './auth-settings-declared-defaults.js';
import { judgePlatformAdmin, judgeHeldSession, isPlatformAdminUser, type PlatformAdminActor } from './platform-admin-gate.js';
import {
Expand Down Expand Up @@ -2539,6 +2544,7 @@ export class AuthPlugin implements Plugin {
declared: () => this.declaredAuthOptions,
resolveDisableSignUp: (declared) => declaringManager.resolveDisableSignUp(declared),
audiencePosture: () => declaringManager.getAudience().posture,
apiKeyMaxExpiryDays: () => declaringManager.resolveApiKeyLifecyclePolicy().maxExpiryDays,
}, ctx.logger);

const applySettings = async (): Promise<void> => {
Expand Down Expand Up @@ -3057,19 +3063,22 @@ export class AuthPlugin implements Plugin {
// ride whatever posture the coercion picked).
//
// Composition rule: the declaration carries only the keys the
// explicitly selected posture READS (the spec marks the siblings
// selected posture (stored, else declared) READS (the spec marks the siblings
// "only read under" their postures). In particular, switching BACK to
// `invite_only` sends `{ posture: 'invite_only' }` alone — leftover
// text in the (hidden) domain-list field must never make CLOSING the
// wall refusable, because that refusal would leave the previous, more
// open posture ruling: the one direction that must not fail.
// Missing required siblings are NOT guessed: the patch goes out
// without them and `applyConfigPatch` refuses the merged result
// (standing config keeps ruling — refusing to OPEN fails closed).
// A required sibling neither stored nor declared is NOT guessed: the
// patch goes out without it and `applyConfigPatch` refuses the merged
// result (standing config keeps ruling — refusing to OPEN fails
// closed). One the deployment declares is what the page shows for it,
// so it rides the patch (below).
// [#30312] No posture stored any more (cleared, or the namespace
// restored) while an audience key had been: the declared audience comes
// back whole, judged by the same merged-result validation. A sibling
// still stored without a posture is then IGNORED as below.
// still stored without a posture is then composed under the declared
// posture as below, or IGNORED where the deployment declares none.
if (!isExplicit('audience_posture')) {
const audienceRestoring = audienceKeys.filter(restoring);
if (audienceRestoring.length > 0) {
Expand All @@ -3084,11 +3093,23 @@ export class AuthPlugin implements Plugin {
}
}
}
// Composed as the page reads the trio: each key as stored, else as the
// deployment declares it (the declared defaults of
// auth-settings-declared-defaults.ts, through the same
// `resolveAudience`). Once one key is stored, the patch carries the
// other two as the page shows them, so a sibling saved under a
// declared posture, or a posture saved beside a declared sibling the
// console did not resend (it posts only the keys edited), runs as
// shown, or is refused by the merged-result validation, never stored
// without effect. A sibling stored where the deployment declares no
// audience has no posture to read it under and is IGNORED, as before:
// the manifest's `invite_only` is a console default, never guessed.
if (audienceKeys.some((key) => isExplicit(key))) {
const rawPosture = values.audience_posture;
if (!isExplicit('audience_posture')) {
const declaredAudience = declared.audience === undefined ? undefined : resolveAudience(declared.audience);
const rawPosture = isExplicit('audience_posture') ? values.audience_posture : declaredAudience?.posture;
if (rawPosture === undefined) {
ctx.logger.error(
'[auth] audience settings IGNORED — a domain list or permission set is declared without a posture. ' +
'[auth] audience settings IGNORED — a domain list or permission set is stored without a posture, and the deployment declares no audience. ' +
`The standing posture ('${this.authManager.getAudience().posture}') keeps ruling. ` +
`Set auth.audience_posture (or OS_AUTH_AUDIENCE_POSTURE) to one of: ${AUDIENCE_POSTURES.join(', ')}.`,
);
Expand All @@ -3100,24 +3121,27 @@ export class AuthPlugin implements Plugin {
);
} else {
const audience: AudienceConfig = { posture: rawPosture };
if (rawPosture === 'email_domain' && isExplicit('audience_allowed_email_domains')) {
const rawDomains = typeof values.audience_allowed_email_domains === 'string'
? values.audience_allowed_email_domains
: '';
// Same textarea convention as `allowed_ip_ranges`: newline- or
// comma-separated. Entries are NOT filtered for shape here —
// a malformed domain must be refused loudly by the validator,
// never silently dropped from the allowlist it was typed into.
audience.allowedEmailDomains = rawDomains
.split(/[\n,]+/)
.map((d) => d.trim())
.filter(Boolean);
if (rawPosture === 'email_domain') {
if (isExplicit('audience_allowed_email_domains')) {
const rawDomains = typeof values.audience_allowed_email_domains === 'string'
? values.audience_allowed_email_domains
: '';
// Same textarea convention as `allowed_ip_ranges`: newline- or
// comma-separated. Entries are NOT filtered for shape here —
// a malformed domain must be refused loudly by the validator,
// never silently dropped from the allowlist it was typed into.
audience.allowedEmailDomains = rawDomains
.split(/[\n,]+/)
.map((d) => d.trim())
.filter(Boolean);
} else if (declaredAudience && declaredAudience.allowedEmailDomains.length > 0) {
audience.allowedEmailDomains = [...declaredAudience.allowedEmailDomains];
}
}
if (
audiencePermitsSelfRegistration(rawPosture) &&
isExplicit('audience_self_registration_permission_set')
) {
const set = asTrimmedString(values.audience_self_registration_permission_set);
if (audiencePermitsSelfRegistration(rawPosture)) {
const set = isExplicit('audience_self_registration_permission_set')
? asTrimmedString(values.audience_self_registration_permission_set)
: declaredAudience?.selfRegistrationPermissionSet;
if (set !== undefined) audience.selfRegistrationPermissionSet = set;
}
try {
Expand Down Expand Up @@ -3192,28 +3216,41 @@ export class AuthPlugin implements Plugin {
let pass: Promise<void> = Promise.resolve();
const runPass = (): Promise<void> => (pass = applySettings());

// Setup → Authentication states what runs when the switch says otherwise:
// a value stored on that a cloud-managed runtime does not apply, or any
// other disagreement. See auth-settings-live-status.ts.
// Setup → Authentication states what runs when a switch says otherwise:
// email and password stored on that a cloud-managed runtime does not
// apply, or any other disagreement; sign-up stored on where the
// deployment forces it off. See auth-settings-live-status.ts.
if (typeof settings.registerLiveStatus === 'function') {
const floorDeps = this.signInMethodFloorDeps(ctx, this.authManager);
try {
settings.registerLiveStatus('auth', async ({ ctx: pageCtx, locale }) => {
await pass;
const manager = this.authManager;
if (!manager) return undefined;
return describeEmailPasswordLiveStatus({
running: manager.getPublicConfig().emailPassword.enabled,
shown: await settings.get('auth', 'email_password_enabled', pageCtx),
heldOffByHost: emailPasswordHeldOffByHost(floorDeps),
locale,
});
const running = manager.getPublicConfig().emailPassword;
const emailPasswordShown = await settings.get('auth', 'email_password_enabled', pageCtx);
return combineAuthLiveStatus([
describeEmailPasswordLiveStatus({
running: running.enabled,
shown: emailPasswordShown,
heldOffByHost: emailPasswordHeldOffByHost(floorDeps),
locale,
}),
describeSignUpLiveStatus({
running: !running.disableSignUp,
shown: await settings.get('auth', 'signup_enabled', pageCtx),
forcedOff: manager.resolveDisableSignUp(false),
emailPasswordShown,
locale,
}),
]);
});
} catch (err: any) {
ctx.logger.warn(
'[auth] Setup → Authentication: the live status was NOT registered '
+ `(${String(err?.message ?? err)}), so where a saved email and password value is not what runs `
+ '(a cloud-managed environment holding it off), the page shows the switch on with nothing saying it is off.',
+ `(${String(err?.message ?? err)}), so where a saved email and password or sign-up value is not what `
+ 'runs (a cloud-managed or single-sign-on-only environment holding it off), the page shows the switch on '
+ 'with nothing saying it is off.',
);
}
}
Expand Down
Loading
Loading