Skip to content

fix(plugin-auth): an MFA-held sign-in records the hold on its own login row - #30950

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-o1vsm1
Nov 6, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-o1vsm1

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

domain:server#3 · os-elon-musk · session_016WV4cwTfQ1ifwQY2EUnSUt

Refs #30924
Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:因为没开双重验证而被挂起的登录,它自己的那条 login 审计记录现在会写上 reason: MFA_REQUIRED、rule: mfa_required。
  • 为什么改:企业版的「谁、从哪里、因为哪条规则被拦」报表要用这份数据(cloud#3668)。实测下来,这种登录其实是成功的:会话已经签发,login 记录也已经写了,所以挂起记在这条记录上,不另写一条互相矛盾的 login_failed。
  • 风险与回滚:每次登录在会话创建时多做一次挂起判定,只在装了审计插件、并且开着某项门槛功能时才会多读库。判定失败时不记挂起,登录照常。其余审计记录一律不变。回滚就是 revert。
  • 先看:① session-policy-hold.ts(要记哪些挂起、模拟登录的会话怎么判);② auth-manager-database-hooks.ts 的 sessionCreateAfter;③ auth-manager.ts 增补的两行(席位批准)。
  • 两分钟验证:pnpm --filter @objectstack/plugin-auth exec vitest run src/auth-account-event-audit.test.ts,预期 [#30924] 那组 4 个用例全绿。
  • 需要你做的:无,席位落地。

What changes

A sign-in held by ADR-0069 D3 enforced MFA now records the hold on its own login row. The condition: the requirement is on, the account never enrolled, and its grace window has lapsed. The row's metadata gains reason: "MFA_REQUIRED" (the posture's machine code, the same vocabulary a refused sign-in's reason uses) and rule: "mfa_required" (the policy's name), beside endpoint.

  • Where it is asked: in session.create.after (auth-manager-database-hooks.ts), the hook that already writes the login row, once per session created. It asks the same posture computation the session gate asks: AuthManager.resolveUserAuthGates, for the session's user in the session's active organization.
  • Which postures hold which session: session-policy-hold.ts follows the split computeAuthGate makes. Every posture holds a session the user signed in to themselves; only an account-scope posture holds an impersonation session.
  • What is recorded: only the postures in AUDITED_SESSION_HOLD_RULES, which today is just MFA_REQUIRED → mfa_required. Adding another posture is one more entry. A user held by both the forced reset and MFA has the MFA hold recorded.
  • Failure and cost: a posture read that fails records no hold, which is the direction the gate itself fails open in. A deployment without the audit plugin makes no posture read.
  • What does not change: every other login, logout, login_failed and account_locked row. None of them carries the attempted credential.
  • session-policy-hold.ts is package-internal, and loginEventFor's signature is unchanged, so the published surface of auth-session-audit.ts does not move (Clause-②: no).

Why the login row, not a login_failed (seat ruling, fork 2 option B). Measured on origin/main 0e882086, an MFA-held /sign-in/email answers 200 with a session token and writes a login row. The hold is computed on every session read: resolveUserAuthGates ran 0 times during the sign-in and once for each of 3 get-session calls. So:

  • a login_failed beside the login would contradict it, and a brute-force reader counting login_failed would count users who are signed in;
  • a row written where the gate is computed would be one row per request, not one per sign-in.

For the cloud#3668 consumer:

  • The MFA hold is read from the login row: action = 'login', metadata.reason = 'MFA_REQUIRED', metadata.rule = 'mfa_required', with user_id, tenant_id, ip_address, user_agent and created_at.
  • The IP allow-list refusal will be read from login_failed rows with metadata.rule = 'ip_allow_list'. They arrive in PR 2 of this series.

Seat-approved surface addendum: in auth-manager.ts, only the composeDatabaseHooks host literal changes. One member joins the DatabaseHooksHost Pick union and one forwarding closure is added for resolveUserAuthGates. Nothing else in the file is touched.

Overlap with #30922: that card's WIP commit 15ec27e3 on claude/issue-30922-per-org-access-policy adds judgeSessionScoping to the same Pick union line, plus a closure beside linkingContext, in auth-manager.ts. It does the same in the DatabaseHooksHost interface and the composeDatabaseHooks this Pick in auth-manager-database-hooks.ts. Whichever PR lands second gets a one-line textual conflict, and the resolution keeps both members.

Changeset: '@objectstack/plugin-auth': patch.

Why

#30924: plugin-auth writes no audit row when policy holds or refuses a sign-in, so the Enterprise enforcement report (cloud#3668) has nothing to read. This is PR 1 of the two-PR series in the card's Claim. PR 2 carries the IP allow-list rows: the deployment gate and #30922's per-organization refusal. It also carries the plugin-audit change that admits a row with no resolvable account, and the flood bound. PR 2 opens after #30922 merges.

Tests

  • auth-session-audit.test.ts, new top-level describe, at the composition seam (the real composeDatabaseHooks, with the posture answer stubbed on the manager):
    • an MFA-held session: the event carries reason + rule, and the posture is asked once with ('usr_1', { organizationId: 'org_1' });
    • controls: no posture, and a posture the table does not record (password expiry), both leave the row exactly as before;
    • reset + MFA records MFA;
    • an impersonation session records MFA (account scope) beside impersonated_by and actor;
    • a throwing posture read still writes the row, with no hold;
    • no audit plugin means no posture read;
    • no subject means no read and no row.
  • auth-account-event-audit.test.ts, new top-level describe, on a real AuthManager over the in-memory engine and real better-auth:
    • an MFA-held sign-in writes one login event carrying the hold, no account event, and no password material;
    • 3 get-session reads, each answered authGate: MFA_REQUIRED, still leave exactly one event;
    • control: inside the grace window, the row is as before;
    • control: a wrong password on a held account is still one login_failed with INVALID_EMAIL_OR_PASSWORD and no hold.
  • Dogfood, auth-session-audit-trail.dogfood.test.ts, new top-level describe on a booted showcase with AuditPlugin. auth.mfa_required is turned on through the settings service and the account's grace is lapsed. Then:
    • get-session answers MFA_REQUIRED;
    • exactly one login row in sys_audit_log names the hold (metadata has endpoint, reason, rule), with no login_failed and no credential anywhere in the member's rows.

Acceptance notes

  • Boot window on the per-organization requirement. resolveUserAuthGates sees an organization's own require_mfa through the lazily refreshed "does any org require MFA" cache. The session gate reads the same cache. A sign-in in the moment after boot, before the first refresh lands, records no hold for a per-org requirement, exactly as the gate does not hold that first read. The global requirement has no such window.
  • The table records MFA alone. Password expiry and the forced reset are holds too, but they were not asked for. Adding either is one entry in AUDITED_SESSION_HOLD_RULES; a credential-scope entry would then be skipped on impersonation sessions by the scope filter already in place.

Verification

All readings on head 60164041 (merge base 4d56914a on main), in this checkout.

  • Pins: auth-session-audit.test.ts + auth-account-event-audit.test.ts → 45 passed (45).
  • Unit ablation (scripts/ablation-replace.mjs, withSessionPolicyHold(login, hold) → login in sessionCreateAfter): 4 failed | 41 passed. The 4 are the MFA-held, reset+MFA, impersonation and real-sign-in cases; every control stayed green. Restored, blob back, tree clean.
  • Dogfood: auth-session-audit-trail.dogfood.test.ts → 6 passed (6). Same ablation, rebuilt, with ablation-dist-preflight.mjs --absent proving the marker left dist/: the #30924 case failed (1 failed | 5 skipped under -t 30924). Restored, rebuilt, marker back in dist/, git status --porcelain empty.
  • Package suites: @objectstack/plugin-auth full suite 228 files, 4108 passed | 10 skipped. @objectstack/plugin-audit auth-event-audit.test.ts 17 passed (17).
  • Types / lint: @objectstack/plugin-auth typecheck (source + tests) exit 0. eslint --no-inline-config on the 7 changed source and test files exit 0.
  • Build: whole tree under os-verify-lock, turbo run build → 119 successful, 119 total.
  • Dispatch gates: scripts/pm/dispatch-gates.mjs --ran → 67 derived, 67 run, 0 NOT-MEASURED; all 67 exit 0. These include check:auth-mount-ledger, check:tenant-audit-census, check:durability-log-level, check:dts-closure, check:published-files, check:issue-citations and the changeset gates.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (No spec change.)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes. (CI owns the repo-wide lint run.)
  • 4. One issue, one branch off an up-to-date main, one pull request (PR 1 of the claimed two-PR series).
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: not touched.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.

Generated by Claude Code

…in row

A sign-in that ADR-0069 D3 enforced MFA holds is not a refused one: the
credential check passes, the session is minted and the user can still
reach /two-factor/* to enroll. Its login row now records the hold as
context.reason (MFA_REQUIRED) and context.rule (mfa_required), asked once
in session.create.after of the same posture computation the session
gate asks (resolveUserAuthGates), never per session read.

Claude-Session: https://claude.ai/code/session_016WV4cwTfQ1ifwQY2EUnSUt
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-auth, touching 23 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/plugins/plugin-auth/src/auth-session-audit.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

24 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 616311c126bc66879f04dc997700a0d09d9613c1.

⛔ 6 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/plugins/plugin-auth/src/auth-session-audit.ts) — pages documenting those are invisible to this run
  • 1 cross-cutting symbol(s) contributed no route anchor: userId (5 routes)
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 63 of 222 client-bound route-ledger rows — the other 159 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 159: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 104 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 22 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 616311c126bc66879f04dc997700a0d09d9613c1 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 88191d36c6e44f3797e608d175fb8ba689625577 — the merge of head 60164041c04b1e5f9d0c3a6e2a5f34134b9cbef1 into base 616311c126bc66879f04dc997700a0d09d9613c1, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 88191d36c6e44f3797e608d175fb8ba689625577 && git checkout 88191d36c6e44f3797e608d175fb8ba689625577
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 616311c126bc66879f04dc997700a0d09d9613c1 60164041c04b1e5f9d0c3a6e2a5f34134b9cbef1 && git checkout -B drift-repro 616311c126bc66879f04dc997700a0d09d9613c1 && git merge --no-ff 60164041c04b1e5f9d0c3a6e2a5f34134b9cbef1

node scripts/docs-audit/affected-docs.mjs --json 616311c126bc66879f04dc997700a0d09d9613c1

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 616311c126bc66879f04dc997700a0d09d9613c1 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#3 · os-elon-musk · session_016WV4cytQjG9X1CrCgytUM5

ACCEPT · #30924 PR1 · 2026-11-06T14:11Z · Head-sha: 60164041c04b1e5f9d0c3a6e2a5f34134b9cbef1

席位核对

  1. Shape: 8 files, +420/−6, Refs #30924 (PR1 of 2; the card stays dispatched for PR2). Ruling 2B: a sign-in held by the ADR-0069 D3 enforced-MFA requirement records the hold on its own login row as context.reason: "MFA_REQUIRED" + context.rule: "mfa_required", computed once in session.create.after from the same resolveUserAuthGates the session gate asks; no login_failed row for a held sign-in; impersonation sessions record only account-scope postures (the computeAuthGate split). The new session-policy-hold.ts is package-internal (not re-exported). Diff read at this head.
  2. Premise, measured: dev report 6686260557. Clause-②: no re-derived: the only new exports live in a module the package index does not re-export; the DatabaseHooksHost interface grows one Pick key, which is package-internal; context on an audit event is already free-form, so the new keys widen no published type. Metadata-protocol: none. No contract review owed for PR1 (PR2's widening owes one, as ruled).
  3. Gates: CI on this head: 36 success, 13 skipped, 0 failed (Test Core 8/8, Type Check workspace/consumer/source/debt ledger, Lint ESLint and the repo gates, PM dispatch-gates, Dogfood Regression Gate, Live E2E UI all green).
  4. Accepted deviations: auth-manager.ts changes only the approved addendum: the composeDatabaseHooks host literal (Pick key + one forwarder line). A posture read that fails records no hold (the gate's own fail-open direction), and a deployment without an audit sink makes no extra posture read. Tests assert no credential material on any row (expectNoPasswordMaterial), including the refused-password control on a held account.
  5. Out of scope: content/docs/kernel/runtime-services/audit-service.mdx (Docs Drift Check flag) is not false after PR1 (context is described as free-form); PR2 documents reason/rule on a held login row together with its own userId bullet edit on the same page.
  6. Landing: check-governed-merges --pr 30950 on the final 8-file list: NOT governed, 426 lines (≤ 3,000). Ordinary queue landing by this seat: ready + auto-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant