Skip to content
Draft
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
22 changes: 22 additions & 0 deletions .changeset/managed-email-password-held-off.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@objectstack/plugin-auth': patch
---

fix(plugin-auth)!: a cloud-managed runtime keeps email and password sign-in off when its deployment declares it off

Clause-②: yes (narrowing) — narrowed: on a cloud-managed runtime (`OS_CLOUD_MANAGED=1`) whose deployment declares `emailAndPassword.enabled: false`, an auth settings save (`PUT /api/settings/auth`, `SettingsService.setMany('auth', …)`) that changes `email_password_enabled` to a value that reads on answers `400 SETTINGS_VALIDATION` (`invalid_value` at the key) and saves nothing in the batch, where it saved; a stored `email_password_enabled` that reads on is no longer applied there, so `GET /api/v1/auth/config` keeps answering `emailPassword.enabled: false`; and there a Google change no longer counts email and password as a way in, whatever the same save sets it to. Widened: on that runtime, a save that turns `email_password_enabled` off or clears it answers `200` and saves, where the sign-in method floor refused it `400 SETTINGS_VALIDATION`, because the host holds email and password off either way; the field error at that key can carry `constraint: { cloudManaged: true, declaredEmailPassword: false }`; a `managedEmailPassword` key on the sign-in floor copy, in all 11 locales; a module export (not on the package entry) `emailPasswordHeldOffByHost`.
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches the auth settings save or the email and password switch; `content/docs/deployment/self-hosting.mdx` and `content/docs/permissions/sso.mdx` gain the cloud-managed case 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: `auth.email_password_enabled` is a settings value, runtime state, not authorable metadata. The moved answers are a runtime refusal of one settings save, and one stored value not applied, on a cloud-managed runtime whose deployment declares email and password off; stored rows are left in place, so there is nothing for `objectstack migrate meta` to rewrite and no tombstone. -->

**BREAKING** for a cloud-managed runtime whose deployment declares email and password off: saving the auth settings with `email_password_enabled` changed to on is refused `400 SETTINGS_VALIDATION` and nothing in that save is written, and a value stored on earlier no longer turns email and password sign-in on. Self-hosted deployments, and cloud-managed ones whose deployment declares email and password on, are unchanged.

On a cloud-managed runtime (`OS_CLOUD_MANAGED=1`) the host refuses every password door. When such a runtime's deployment declared `emailAndPassword.enabled: false`, a stored `auth.email_password_enabled` that read on still overrode the declaration: `GET /api/v1/auth/config` answered `emailPassword.enabled: true`, and the sign-in page drew an email and password form whose every submit was refused.

- **The settings pass.** On such a runtime a stored `auth.email_password_enabled` that reads on is not applied, and the server says so once at `error`, with the remedy: clear the setting (or set it off) in the settings console. An `OS_AUTH_EMAIL_PASSWORD_ENABLED` value is the deployment's own declaration and still applies.
- **The save door.** A save that turns `auth.email_password_enabled` on there is refused with `400 SETTINGS_VALIDATION` and an `invalid_value` field error at the key, in the caller's language. Turning it off or clearing it is accepted there: the host holds it off either way, so the sign-in method floor no longer refuses that save.

Self-hosted deployments, and cloud-managed ones whose deployment declares email and password on, keep the toggle exactly as before.

What to do: nothing to migrate. On such a runtime, clear `auth.email_password_enabled` (or set it off) in the settings console if the server reports it stored on and not applied.
11 changes: 11 additions & 0 deletions content/docs/deployment/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,17 @@ wins over a stored `auth.email_password_enabled = false` and over the stack
config, and email and password sign-in comes back. Or restore the sign-in
method the configuration no longer declares.

A cloud-managed runtime (`OS_CLOUD_MANAGED=1`) whose deployment declares email
and password off is the exception. The host refuses every password sign-in
there, so the settings never turn it back on: a save of
`auth.email_password_enabled` that reads on is refused
`400 SETTINGS_VALIDATION` at the field, a value stored on earlier is not
applied (the server says so once at **error**), and `GET /api/v1/auth/config`
keeps answering `emailPassword.enabled: false`. Turning the switch off or
clearing it is accepted there without the checks above, because it removes no
way in. `OS_AUTH_EMAIL_PASSWORD_ENABLED` is the deployment's own declaration
and still applies.

## Who may sign up — and what each posture tells a stranger

`auth.audience.posture` is the one declaration answering who may become a user
Expand Down
7 changes: 7 additions & 0 deletions content/docs/permissions/sso.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,13 @@ Recover by setting `OS_AUTH_DIRECT_SIGN_IN_LOCAL_PATH=hidden`, and
`OS_AUTH_EMAIL_PASSWORD_ENABLED=true` too when email and password sign-in is
off, then restarting.

On a cloud-managed runtime whose deployment declares email and password off,
the email and password switch is judged before these checks, under `off` or
not: a save that turns it on is refused `400 SETTINGS_VALIDATION`, a value
stored on earlier is not applied, and email and password does not count as a
way in for a Google change in the same save
([Self-hosting](/docs/deployment/self-hosting)).

**What a visit does.** The Console sign-in page reads `features.directSignIn`
from `GET /api/v1/auth/config`. That is `true` only while a provider can be
started, and only when this server mounted the door: a setting turned on
Expand Down
33 changes: 30 additions & 3 deletions packages/plugins/plugin-auth/src/auth-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ import {
type SignInPathConfigView,
} from './boot-sign-in-reachability.js';
import {
emailPasswordHeldOffByHost,
providerCredentialIndex,
providerCredentialsFrom,
registerSignInMethodFloor,
Expand Down Expand Up @@ -704,6 +705,8 @@ export class AuthPlugin implements Plugin {
private allowListUndeterminedWarned = false;
/** Set once the settings pass has said that `auth.mfa_required` reads a toggle spelling. */
private legacyMfaRequiredNoted = false;
/** Whether the not-applied stored `email_password_enabled` was said (see `bindAuthSettings`). */
private heldOffEmailPasswordNoted = false;
private allowListUntrustedHeaderWarned = false;
/** The applied allow-list value whose unreadable value or entries were last reported, so one is reported once. */
private allowListUnreadableReportedFor: string | undefined;
Expand Down Expand Up @@ -2430,6 +2433,7 @@ export class AuthPlugin implements Plugin {
env: () => ((globalThis as any)?.process?.env ?? {}) as Record<string, string | undefined>,
// [#30312] A cleared toggle returns to the declaration: judge it there.
declaredEmailPasswordEnabled: () => this.declaredAuthOptions.emailAndPassword?.enabled !== false,
cloudManaged: () => isCloudManaged(),
};
}

Expand Down Expand Up @@ -2582,10 +2586,33 @@ export class AuthPlugin implements Plugin {
options,
});
};
// A cloud-managed runtime whose deployment declared email and password
// off keeps it off: the host refuses every password door there, so a
// stored value that reads on would only advertise a form that signs
// nobody in. The save door refuses turning it on (sign-in-method-floor.ts);
// a row stored before that check, or a re-save of the manifest default
// the save door is never asked about, is not applied. An
// `OS_AUTH_EMAIL_PASSWORD_ENABLED` value is the deployment's own
// declaration and still applies.
let emailPasswordHeldOff = false;
if (isExplicit('email_password_enabled')) {
emailAndPasswordField('email_password_enabled', {
enabled: asBoolean(values.email_password_enabled, true),
});
const enabled = asBoolean(values.email_password_enabled, true);
emailPasswordHeldOff = enabled && sources.email_password_enabled !== 'env'
&& emailPasswordHeldOffByHost(this.signInMethodFloorDeps(ctx, authManager));
if (!emailPasswordHeldOff) emailAndPasswordField('email_password_enabled', { enabled });
}
if (emailPasswordHeldOff && !this.heldOffEmailPasswordNoted) {
this.heldOffEmailPasswordNoted = true;
// `error`, as for the audience settings below: the console shows the
// stored value as saved while the runtime does not apply it.
ctx.logger.error(
'[auth] auth.email_password_enabled is stored on, and NOT APPLIED: this environment is cloud-managed and its '
+ 'deployment turns email and password sign-in off, so people sign in through the hosting organisation\'s '
+ 'identity provider and the sign-in page offers no email and password form. Clear '
+ 'auth.email_password_enabled (or set it off) in the settings console so the page matches what runs.',
);
} else if (!emailPasswordHeldOff) {
this.heldOffEmailPasswordNoted = false;
}
if (isExplicit('signup_enabled')) {
emailAndPasswordField('signup_enabled', {
Expand Down
20 changes: 20 additions & 0 deletions packages/plugins/plugin-auth/src/cloud-managed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,26 @@ describe('[#25083] the password doors on a cloud-managed environment', () => {
expect(s.credentialOf(s.ids.member)?.password).not.toBe(before);
}, 120_000);

it('admin update-user takes no password: data.password is refused and no credential is written or moved', async () => {
// better-auth's own admin route refuses the key on every deployment
// (`PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER`); pinned here so a vendor
// upgrade that starts accepting it cannot open a password door on a
// managed runtime unnoticed.
const s = await stage();
setManaged(true);
const before = s.credentialOf(s.ids.member)?.password;
expect(before).toBeDefined();
for (const userId of [s.ids.member, s.ids.idp]) {
const v = await verdict(
await s.fire('/admin/update-user', { userId, data: { password: NEW_PASSWORD } }, s.bearers.admin),
);
expect(v.status, v.text).toBe(400);
expect(v.code, v.text).toBe('PASSWORD_CANNOT_BE_UPDATED_VIA_UPDATE_USER');
}
expect(s.credentialOf(s.ids.member)?.password).toBe(before);
expect(s.credentialOf(s.ids.idp)).toBeUndefined();
}, 120_000);

it('set-initial-password refuses a caller without platform-admin standing with 409 and writes no credential', async () => {
const s = await stage();
setManaged(true);
Expand Down
Loading
Loading