Repository navigation
fix(auth): allow-list the setup admin's email so emailed-code sign-in works (#4693) - #4694
Merged
Merged
Conversation
… works (#4693) First-run setup stored the admin's email on the admin row but never added it to the email allow-list, so POST /api/auth/email/request answered its generic 200 and minted nothing for the instance's own admin. The rule sits at the writers of the admin's email, not at the request route: setup (password form and emailed-link form), the admin's own email change, and a boot-time idempotent backfill for installs set up before this fix. The request route and the #2381 redeemer re-check are unchanged. The row's default_role is 'user', used only if the address ever creates a new account after the admin moves to another address. The sign-in page now says a code is on its way if the address is registered, instead of claiming one was sent. Red before the fix: test_password_setup_with_email_then_code_request_mints_and_sends and test_email_link_setup_then_code_request_mints_and_sends (no code minted). Fixes #4693 Co-Authored-By: Claude Opus 5.5 <[email protected]>
trinity-ability
commented
Nov 20, 2026
trinity-ability
left a comment
Contributor
Author
There was a problem hiding this comment.
/validate-pr — #4694 at d43be2149 (Lane B, fresh detached checkout)
Recommendation: REQUEST CHANGES (one item; everything else checks out)
What was checked
- Sign-in as the admin by emailed code. The verify route resolves the account by the email column, so a code for the setup admin's address now lands an admin session. That is what the issue asks for. The #2381 re-check is still in place at verify and nothing was loosened. Only three things write a row: setup (run by whoever is creating the admin, and refused once an admin exists),
PUT /me/email(require_interactive, and only when the caller is the setup admin), and the boot backfill (reads the admin row's own email). No other address can reach the list this way.default_role='user'is right for the stale row left behind when the admin moves to a new address. - Boot backfill. It runs in every worker and isn't leader-gated. That is safe: there is a check before the insert and the
emailcolumn is UNIQUE, so the worker that loses the race hits theexceptand logs only the exception type. It never raises and never logs the address. - Request route.
routers/auth.pyis not in the diff, so the anti-enumeration contract is byte-for-byte unchanged. The Login.vue wording ("If X is registered…") is more honest than before. - Production wiring is pinned. I deleted each call one at a time and re-ran the suite:
- setup call removed → 2 failed
- boot call removed → 1 failed
/me/emailcall removed → 1 failed
Critical (must fix)
- The boot backfill re-adds the admin's address after an operator removes it.
DELETE /api/settings/email-whitelist/{email}works on this row. The backfill runs on every boot wheresetup_completedis set, so the next restart puts the row back and email-code sign-in for the admin comes back with it. The PR's own argument against the alternative fix was that it "would let an account that was removed from the allow-list sign in again". This does that for the admin account. Suggested fix: make the backfill run once, using asystem_settingsmarker that is set after the first pass whether or not a row was written. Then add a test that removes the row and runs the backfill a second time.
Warnings
- Both conditions are unpinned. Replacing
if current_user.username == admin_username():inupdate_my_emailwithif True:stays green. So does inverting thesetup_completedbranch inmain.py. The AST pins only check that the call exists. One test that runsupdate_my_emailas a non-admin and asserts no row would cover the first. - An unverified address now grants something it didn't before. Setup binds the email without verifying it, and so does the console-provider
/me/emailpath. Before this PR, a mistyped address gave nothing without the password. Now whoever owns that inbox can request a code and sign in as the admin. This follows from the issue, so it isn't blocking, but it is worth one line in the operator docs. - Nothing runs the helper against a real DB: every test uses
FakeDB. A real-engine case would prove the UNIQUE-race path.
Suggestions
- Test fixtures use
acme.com. Repo convention isexample.com.
Gates
- Closing keyword
Fixes #4693✅ - Journey Impact
extends: J01✅ (CI pass) - §4.1–4.3 clean (198.51.100.7 is a documentation range)
- No env, mode or host-path changes
- §5.5:
users.pycarries# mcp: none — …;setup.pyis excluded - The
/me/emailwrite is already audited - Local:
test_4693_*8 passed - CI on tip: required contexts pass.
pytest (head, seed 12345)was still pending when this was written, so Tier 1 is not yet complete.
The boot backfill now runs once, on a completed setup, behind a stored marker that setup also sets, so removing the admin's address from the allow-list survives a restart. The marker is set even when nothing was written. Tests drive the /me/email admin condition and the setup_completed condition through the real code; fixtures use example.com. Mutations recorded red: marker check removed (3), marker write removed (2), setup marker removed (1), setup_completed check removed (1), /me/email condition replaced by True (1). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
trinity-ability
commented
Nov 20, 2026
trinity-ability
left a comment
Contributor
Author
There was a problem hiding this comment.
/validate-pr re-check — #4694 at 5dd8dd277 (fresh detached checkout)
Decision: PASS. The Critical item and both warnings are fixed. CI on this tip was still pending when this was posted.
Fixed
- The backfill now runs once per install.
backfill_admin_email_once()runs only when setup has completed, and it is gated on a storedsystem_settingsmarker. The marker is set even when there was nothing to write. Setup sets the marker too, so the first boot after setup cannot re-add an address the operator removed in between. Tests: remove the row and run again, the row stays gone; marker set when nothing was written; nothing written and no marker on an unfinished setup; removal right after setup survives the next boot. - Both conditions now have tests that run the code.
PUT /me/emailruns through the real handler: the setup admin's new address is added, and another account's change adds nothing (that account is an admin in the test). Thesetup_completedcheck now lives in the service and is executed by a test. The AST pin inmain.pycovers only that the call is there. - Test fixtures now use
example.com. - Docs:
getting-started/setup.mdnow says the admin email can also sign in by emailed code, so use an address you control.
Mutations (each reverted afterwards, file restored byte-identical)
| Mutation | Result |
|---|---|
| marker check removed | 3 failed |
| marker write removed | 2 failed |
| setup's marker write removed | 1 failed |
setup_completed check removed |
1 failed |
/me/email condition replaced by True |
1 failed |
Tests at 5dd8dd277
test_4693_*: 13 passed- auth/setup neighbours (lifespan phases, 2381 ×2, 3004, 3237, 3455, 3676, 837, admin_email_login, ent1201, ent1253, ent127, 1310 ×2) plus the new tests: 341 passed
- ent1312 setup link claim, ent720 email binding, setup operator profile: 85 passed
Still open, not blocking: nothing runs the helper against a real DB engine yet.
1 of 2 tasks
vybe
pushed a commit
that referenced
this pull request
Nov 21, 2026
…4679/#4677 (#4680) Accepted growth, ruled at merge-train Gate 2 (2026-11-21): - routers/setup.py 6 -> 9 (ent#1329 setup terms, #4683/#4694/#4698) - client_portal/work/service.py 8 -> 10, agent_service/autonomy.py 12 -> 14 (#4679's batch prefetch reads: fewer queries, more call sites) Co-Authored-By: Claude Opus 5.5 <[email protected]>
vybe
pushed a commit
that referenced
this pull request
Nov 23, 2026
) * test(backend): ratchet on blocking calls inside async def (#4674) A sync db, Docker, HTTP or sleep call written directly inside an `async def` runs on the event loop and blocks the whole worker. scripts/ci/check_sync_on_loop.py counts them per file by parsing (never importing) and compares with scripts/ci/sync_on_loop_baseline.json: - a file's count may not exceed its entry; - a file with no entry starts at zero; - an entry above reality fails too, so a paydown lowers the baseline. Today: 1,911 call sites in 831 async functions across 194 files (db 1,363; through a module's own sync function 386; Docker 161). Counted: db / core_db / _db / *.db method calls, get_agent_container, list_all_agents_fast, agent_container_states, time.sleep, subprocess.run, requests.*, and calls to the same module's plain defs that make one. Not counted: plain def handlers, nested defs, and the arguments of to_thread / run_in_executor / run_in_threadpool. The ratchet runs in the unit suite (test_4674_sync_on_loop_ratchet.py). The helper list is one constant, for trinity-dev#82 to share. Related to #4674 Co-Authored-By: Claude Fable 5.2 <[email protected]> * test(backend): the ratchet does not pin the offenders it exists to remove (#4674) Review finding. One test asserted that heartbeat_service's watch loop and dependencies.py are in the scan. Those are exactly what #4674 goes on to fix, so the test would have failed on the fix. It now asserts only that the live scan sees both families. The backend is parsed once per module instead of once per test. Related to #4674 Co-Authored-By: Claude Fable 5.2 <[email protected]> * test(backend): regenerate the sync-on-loop baseline on current dev (#4674) dev moved under the branch and changed two files' counts, which is the ratchet doing its job on its own PR. Related to #4674 Co-Authored-By: Claude Fable 5.2 <[email protected]> * merge-train: regenerate the sync-on-loop baseline on dev after #4676/#4679/#4677 (#4680) Accepted growth, ruled at merge-train Gate 2 (2026-11-21): - routers/setup.py 6 -> 9 (ent#1329 setup terms, #4683/#4694/#4698) - client_portal/work/service.py 8 -> 10, agent_service/autonomy.py 12 -> 14 (#4679's batch prefetch reads: fewer queries, more call sites) Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(backend): --write refuses to absorb growth into the baseline (#4674) Regenerating the baseline wrote whatever the scan found, so a regeneration could wave new blocking calls through and only the JSON diff showed it. --write now prints each file whose count grew and writes nothing unless --allow-growth is passed; a paydown is written as before. Also: main() reads and writes the baseline path it names (the helpers' default argument was bound at import), and the docstring no longer claims a /code-health consumer that does not exist. Co-Authored-By: Claude Fable 5.2 <[email protected]> --------- Co-authored-by: Claude Fable 5.2 <[email protected]> Co-authored-by: trinity-ability <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4693
Journey Impact: extends: J01
Problem
First-run setup saved the admin's email on the admin account but did not add it to the email allow-list.
POST /api/auth/email/requestonly creates a code for an address on that list, so the admin who used "Send Verification Code" got the generic 200, and no code was created or sent.Where the rule lives: allow-list at the writers of the admin's email
The address goes on the allow-list wherever the admin's email is written. The request route is not changed. Reasons:
/email/verifyand/email/handoff. It would let an account that was removed from the allow-list sign in again, and it would bring back the bug(security): fresh install leaves setup_completed=false with a real admin — unauthenticated /api/setup/admin-password overwrites the admin password #2381 path from "an address bound to the admin row" to an admin session.Covered writers:
email_registeredand then callallow_list_admin_email.PUT /api/users/me/emailby the setup admin account adds the new address too.The new row uses
default_role='user'. The admin's address resolves to the existing admin row, so that role is only used if the old address ever creates a new account after the admin moves to another address. That account must not be an admin.Nothing changes when
email_auth_enabledis off or a login policy turns email codes off.Sign-in page
Before: "We sent a 6-digit code to X". After: "If X is registered, a 6-digit code is on its way."
Tests
tests/unit/test_4693_admin_email_code_login.pyruns the real setup route and then the real request route over one in-memory DB, for both setup forms:Red before the fix: I reverted the setup call and
test_password_setup_with_email_then_code_request_mints_and_sendsandtest_email_link_setup_then_code_request_mints_and_sendsfailed. Restoring it made them pass.2411 passed, 7 skippedloginNoEmailProvider.spec.jswas updated first and failed (2 failed), then the wording change made it pass. Login specs + raw-color/source-text ratchets:110 passed.Out of scope (noted)
A non-admin user who changes their own email through
/me/emailis also not added to the allow-list. That is the same class of bug for other accounts. It is not changed here.🤖 Generated with Claude Code