Skip to content

fix(coderd): let only one request create the first user (#32417) - #32539

Merged
BobbyHo merged 3 commits into
release/2.29from
backport/32417-to-2.29
Nov 23, 2026
Merged

BobbyHo merged 3 commits into
release/2.29from
backport/32417-to-2.29

Conversation

@coder-backporter-app

@coder-backporter-app coder-backporter-app Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Backport of #32417

Original PR: #32417 — fix(coderd): let only one request create the first user
Merge commit: cf68914
Requested by: @BobbyHo

The automatic cherry-pick had conflicts. They are resolved by hand; the fix is the same as in #32417.

Differences from #32417
  • coderd/database/lock.go: adds only LockIDFirstUserSetup. The conflict came from nearby chat lock IDs that are not on this branch.
  • coderd/users.go: keeps this branch's ptr.Ref(codersdk.UserStatusActive) where fix(coderd): let only one request create the first user #32417 has new(codersdk.UserStatusActive).
  • coderd/firstusersetup_test.go: the GitHub callback helper does not send the PKCE verifier cookie. This branch has no PKCE on the OAuth callback.

The automatic cherry-pick of cf68914 to release/2.29 had conflicts.
Please cherry-pick manually:

    git cherry-pick -x -m1 cf68914
@coder-backporter-app coder-backporter-app Bot added the backport/v2.29 Backport PR targeting release/2.29 label Nov 20, 2026
Prevent multiple Owner accounts from being created during concurrent first-user setup requests.

Refs https://linear.app/codercom/issue/CORE-853

Use a transaction-scoped PostgreSQL advisory lock shared by password setup and GitHub/OIDC first sign-ins. Recheck the user count under the lock to ensure only one account receives the Owner role, while preserving existing responses for subsequent requests.

- Add a stable, backport-safe lock ID and shared first-user setup helper.
- Apply locking only when no users exist, leaving normal sign-ins unaffected.
- Use `READ COMMITTED` isolation to ensure accurate counts regardless of database defaults.
- Keep validation and trial licence requests outside the lock.
- Preserve existing API responses, status codes, and telemetry behavior.

**Testing**
- Add concurrent password, OAuth, and mixed-path tests verifying exactly one Owner.
- Cover lock contention, cancellation, isolation levels, telemetry, and lock bypass.
- Verify tests fail when locking is removed.
- Pass targeted race tests, 124 related tests, lint, and `intxcheck`.

**Known limitation:** A burst of concurrent OAuth sign-ins on an empty deployment could exhaust the database connection pool while waiting for the lock. This remains unverified and is outside the scope of this fix.

**Note:** Stacked on #32324; will be rebased onto `main` after it merges.

(cherry picked from commit cf68914)
@BobbyHo BobbyHo changed the title fix(coderd): let only one request create the first user (#32417) (conflicts) fix(coderd): let only one request create the first user (#32417) Nov 21, 2026
@BobbyHo
BobbyHo requested a review from denisra November 21, 2026 16:59
@BobbyHo
BobbyHo merged commit 93de8df into release/2.29 Nov 23, 2026
34 checks passed
@BobbyHo
BobbyHo deleted the backport/32417-to-2.29 branch November 23, 2026 17:17

This branch had an error being deployed

1 failed deployment
docs-preview — c7ab409a Deployed Nov 23, 2026 by BobbyHo via cleanup #356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v2.29 Backport PR targeting release/2.29

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants