Repository navigation
fix(auth): enforce signup policy before account commit - #2716
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
There was a problem hiding this comment.
Review of 1f533168e. The fix is right: the in-transaction read runs after the settings advisory lock that every server_settings writer takes, so a disable that commits first refuses the signup, and one that comes later waits for the signup's commit. The new tests fail on the base CreateInvited (an account, a profile and a spent invite after the disable) and pass on this head, including under -race.
One finding, in the CI wiring. I'm fixing it in a commit on this branch, so there's no need to change it yourself.
A cross-provider round (Codex, gpt-6.1-sol) raised that the recheck assumes READ COMMITTED: under a database-wide default_transaction_isolation = 'repeatable read', the snapshot would predate the lock wait. I'm not treating that as a finding for this PR. The local-password guard in the same transaction, and the settings mutation path that reads current values after taking the same lock, already rely on PostgreSQL's default isolation, so pinning it here alone wouldn't make this path safe under a different database default.
AI disclosure: this review was run by Claude Code (claude-opus-5-5) with a Codex gpt-6.1-sol cross-provider round, on behalf of the PR author.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
/silo review summaryReviewed Verification. On a throwaway, migrated PostgreSQL database: Addressed
Considered and not changed
Remaining issues: none. Validated features: the board check could not run because the token lacks User manual: unaffected. The fix makes signup follow the admin setting; the manual does not describe this race. Apple and Android: no follow-up needed. Both apps already handle CI on Fit: 9/10 · Readiness: 8/10 — conditional (assuming CI is green)
AI disclosure: Claude Code ( |
|
The four cases in #1196 (C1–C2) and #1197 (C1–C2) are unaffected. Their access-group checks and group-assigned invitations use the admin invitation flow ( The current
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
8f8a72b to
f374297
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
Serialize the signup decision with settings mutations before redeeming an invite. Keep account/profile writes and invite accounting atomic, and run the policy ordering and API mapping database contracts in CI. Co-authored-by: Codex <[email protected]>
TestSignupRechecksLocalPolicyBeforeSpendingInviteDB turns the global auth.local_password_login row off for part of its run. In the database contract run every listed package shares one database and runs in parallel, so invitation and Jellyfin login contract tests could fail with "local password sign-in is turned off" while it ran. Run it in the go-db-auth job, beside TestSignupRefusedWhileLocalLoginIsOffDB, where these tests run one at a time in a fresh database. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2817 deleted local_signup_policy_db_test.go because no CI job ran it. This branch now runs TestSignupRechecksLocalPolicyBeforeSpendingInviteDB in the serial auth DB job, and signup_policy_db_test.go uses its paused repository helper, so restore the file unchanged. #2817 also deleted TestInvitedAccountAtomicDB and TestInvitedAccountWrappedPostgresDB; drop them from the DB contract list, which fails on listed tests that do not exist. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Codex (gpt-6-astra) <[email protected]>
8cd89b8 to
e7ec62e
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Closes #2714
Related issue: N/A
Validation tasks: unavailable (missing
read:project; inspected #1196 C1/C2 and #1197 C1/C2 are unaffected).An invited signup could pass its initial policy check, then create an account after an administrator disabled public signup. Recheck the policy inside the account transaction so a disabling mutation that commits first prevents account creation and invite consumption.
Approach
Use the existing settings mutation lock already held by the local-password guard. Preserve local-password enforcement, invite validation and atomic account/profile/use accounting. Add deterministic two-service PostgreSQL coverage and both native API error mappings. CI now runs the new and newly enabled tests. The local-password recheck test turns the global local-password setting off, so it runs in the serial external-auth database job; the others are database contracts.
Apple and Android already handle these errors. Jellyfin has no invite-code signup path. Admin invitations and initial setup use separate transactions. The accounts manual remains accurate.
Validation
mainand then from this branch. An administrator turns public signup off while an invitedPOST /api/v2/auth/signupwaits on the settings lock behind that change; a database session holds the lock briefly so the two requests run in that order. Onmainthe signup returns 201, creates the account and spends an invite use. On this branch it returns 403permission_denied, creates no account and leaves the invite unspent. An ordinary invited signup on this branch still returns 201.365e3d436.local_signup_policy_db_test.gois restored unchanged: it holds the local-password recheck test that this branch runs in the external-auth job, and the helper the serialization test uses.TestInvitedAccountAtomicDBandTestInvitedAccountWrappedPostgresDBstay deleted and are off the contract list.mainat2d5f22e7d. The only conflict was inscripts/ci/db-contracts.txt, where both sides added lines; both are kept. After the rebase,TestSignupPolicySerializationDBandTestSignupCommitPolicyErrorsDBfail onmain. On this branch they pass under-raceagainst PostgreSQL 18, together with the other signup and external sign-in database tests this branch touches. Build, vet, formatting,make lint-changedand theinternal/auth,internal/apiv2andinternal/api/handlersunit tests pass. The full Go suite was not rerun after this rebase.read:project. Saved public passed cases listed above trace to unchanged paths.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2716/
Risks
One additional settings read per invited signup. No migration, new setting, default or API contract change.
Checklist
AI Disclosure
gpt-6.1-solatxhighfor implementation and code reviews;claude-opus-5-5athighfor plan and adversarial review.1f533168ebb4742c601adce92f509eb306600620, checking settings writers, transaction ordering, rollback, callers and error mappings; it found no defects and posted no review. A later/siloreview (Claude Code,claude-opus-5-5, with a Codexgpt-6.1-solround) found the local-password recheck test could fail unrelated contract tests that share its database, and moved it to the external-auth job in8f8a72b74.claude-opus-5-5) rebased the branch, restored the deleted test file and updated the contract list.Note
Recheck signup policy inside
UserRepository.CreateInvitedtransactionFixes a race where signup could succeed after
signup.enabledwas disabled, because the policy was only checked before the invite transaction started.CreateInvitedin repository.go now readssignup.enabledwithin the transaction, after the local-password-login guard, and returnsErrSignupDisabledbefore redeeming the invite or creating the account and profile.signup.enabledat commit now returnErrSignupDisabled; check callers ofCreateInvitedfor handling of this error.Macroscope summarized e7ec62e.