Skip to content

feat: require a setup token to create the first user on a tunnel (#32324) - #32514

Merged
BobbyHo merged 2 commits into
release/2.37from
backport/32324-to-2.37
Nov 20, 2026
Merged

BobbyHo merged 2 commits into
release/2.37from
backport/32324-to-2.37

Conversation

@coder-backporter-app

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

Copy link
Copy Markdown

Backport of #32324

Original PR: #32324 — feat: require a setup token to create the first user on a tunnel
Merge commit: 88d3494
Requested by: @BobbyHo

The automatic cherry-pick had conflicts. They are resolved by hand; the server and CLI changes are the same as in #32324.

Differences from #32324
  • scripts/develop: keeps this branch's password handling and adds only the setup token. password_test.go is left out because it comes from fix: generate per-instance dev passwords and remove the shared default #32283, which is not on this branch.
  • Docs: the quickstart, Azure and Compute Engine wording is applied to this branch's page layout. The sentences for docs/install/index.md and the RPM page are left out because those pages do not mention the tunnel here.
  • Generated API docs, CLI docs and the configuration reference are regenerated with this branch's generators.
  • coderdtest.Options and the codersdk option test keep this branch's fields and add the setup token entries.

@coder-backporter-app coder-backporter-app Bot added the backport/v2.37 Backport PR targeting release/2.37 label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @coder-backporter-app[bot]!

This PR is targeting the release/2.37 release branch, but its title does not start with fix: or fix(scope):.

Only bug fixes should be cherry-picked to release branches. If this is a bug fix, please update the PR title to match the conventional commit format:

fix: description of the bug fix
fix(scope): description of the bug fix

If this is not a bug fix, it likely should not target a release branch.

)

fix(security): require setup token for first user on tunnels

Prevent unauthorized users from claiming Owner access on public `try.coder.app` tunnels before initial setup.

- Generate a setup token at startup when using a tunnel with no existing users.
- Require the token for first-user creation via the API, web UI, and CLI.
- Block GitHub/OIDC first-user signup until setup is complete.
- Support custom tokens via `--setup-token` / `CODER_SETUP_TOKEN` and non-interactive CLI setup.
- Update development scripts, documentation, and tests.
- Preserve existing behavior for deployments with an access URL or existing users.

Validated with automated tests and 23/23 manual scenarios using a real tunnel.

Refs CORE-784

(cherry picked from commit 88d3494)
@BobbyHo
BobbyHo force-pushed the backport/32324-to-2.37 branch from b7fc77e to 3f6ab7f Compare November 20, 2026 16:19
@BobbyHo BobbyHo changed the title feat: require a setup token to create the first user on a tunnel (#32324) (conflicts) feat: require a setup token to create the first user on a tunnel (#32324) Nov 20, 2026
@BobbyHo

BobbyHo commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@coder-agents-review

coder-agents-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-11-20 18:34 UTC by @BobbyHo
Spend: $11.14 / $100.00

Review history
  • R1 (2026-11-20): 15 reviewers, COMMENT. Review

deep-review v0.13.0 | Round 1 | 3e5fbd7..4836b66

Last posted: Round 1, no findings, COMMENT. Review

Finding inventory

Finding inventory: PR #32514

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Dropped by orchestrator (below P0-P2 scope requested on PR) SetupPageView.stories.tsx:49 SetupTokenRefused play asserts nothing; SetupTokenRequired has no play R1 Netero No
CRF-2 P4 Dropped by orchestrator (below P0-P2 scope requested on PR) scripts/develop/main.go:937 No test that setupFirstUser sends cfg.setupToken on this branch R1 Netero No
CRF-3 Nit Dropped by orchestrator (below P0-P2 scope requested on PR) cli/setuptoken_internal_test.go:149 ptrInt64 duplicates ptr.Ref R1 Netero No
CRF-4 P3 Dropped by orchestrator (below P0-P2 scope requested on PR) cli/login.go:259 Non-interactive coder login on a tunnel without the token flag fails with bare EOF R1 Pen Botter P2 No
CRF-5 P3 Dropped by orchestrator (below P0-P2 scope requested on PR) SetupPageView.tsx:80 Failed authMethods query hides token field; every submit gets 403 R1 Nami P3, Melody Note No
CRF-6 P3 Dropped by orchestrator (below P0-P2 scope requested on PR) docs/install/cloud/compute-engine.md:51 Docs and 403 message do not say each restart prints a new token R1 Leorio No
CRF-7 P3 Dropped by orchestrator (below P0-P2 scope requested on PR) codersdk/deployment.go:3917 Help text hardcodes 24, duplicating setupTokenMinLength R1 Gon No
CRF-8 P4 Dropped by orchestrator (below P0-P2 scope requested on PR) cli/setuptoken.go:64 Generated token length 32 is an unnamed literal R1 Gon No
CRF-9 Nit Dropped by orchestrator (below P0-P2 scope requested on PR) SetupPageView.tsx:105 Comment "stays as it was" describes the pre-PR request R1 Gon P2 No
CRF-10 Nit Dropped by orchestrator (below P0-P2 scope requested on PR) coderd/setuptoken.go:39 errSetupNotComplete is a function with a sentinel-variable name R1 Gon No
CRF-11 Nit Dropped by orchestrator (below P0-P2 scope requested on PR) cli/setuptoken.go:57 Length error names only --setup-token, not CODER_SETUP_TOKEN R1 Leorio No
CRF-12 Nit Dropped by orchestrator (below P0-P2 scope requested on PR) docs/install/cloud/azure-vm.md:93 Rewritten line keeps typo "save use email and password" R1 Leorio No
CRF-13 P4 Dropped by orchestrator (below P0-P2 scope requested on PR) codersdk/users.go:460 AuthMethods.SetupTokenRequired stays true after first user exists; contradicts doc comment R1 Nami, Ryosuke, Pariston, Mafuuu, Gon (Note) No
CRF-14 P4 Dropped by orchestrator (below P0-P2 scope requested on PR) cli/server.go:1030 No test checks tunnel != nil reaches resolveSetupToken and Options.SetupToken R1 Bisky (Note) No
CRF-15 Note Note (body) coderd/users.go:205 feat: change on release/2.37 makes POST /users/first on tunnels return 403 without the token; release notes and cherry-pick policy need a human decision R1 Ryosuke No
CRF-16 OOS Out of scope (body) coderd/users.go:188 postFirstUser user-count check is outside a transaction; concurrent requests can both create owners R1 Kurapika No
CRF-17 OOS Out of scope (body) docs/admin/setup/index.md:20 Tunnel section does not mention the setup token R1 Netero No
CRF-18 OOS Out of scope (body) docs/install/docker.md:159 Points PoC users to the tunnel without mentioning the setup token R1 Netero No

Contested and acknowledged

Cross-check notes

  • CRF-4: keep-argument for P2: existing scripts that log in against a tunnel break on a patch upgrade with only "EOF", which does not name the missing flag. Downgrade reason: the cited scripts (examples/lima, scaletest/lib/coder_init.sh) set an access URL and never open a tunnel; the email and password prompts already fail with EOF the same way when their flags are missing; the server prints the token and the flag is documented. Failure is intended, only the message is unclear. P3.
  • CRF-9: keep-argument for P2: a history-relative comment misleads future readers. Downgrade reason: no behavior consequence; wording only. Nit.
  • Every finding below P2 is withheld from posting because the backport requester asked on the PR (IC_kwDOGkVX1s8AAAABpBFfdQ) to limit the review to P0, P1, and P2.
  • Production code verified identical to merge commit 88d3494 by Netero (range-diff), Ryosuke, Luffy, and Zoro, except scripts/develop/main.go cfg.password.

Round log

Round 1

Full panel (round 1). Netero first pass: 1 P3, 1 P4, 1 Nit, 1 Note; no P0, panel proceeded. Law not run (effective additions 771 < 1000). Panel of 15: specialists ging-go, ging-ts, ging-react, kurapika, nami, ryosuke, luffy (new config flags), pen-botter (docs), melody (JSON fields across Go/TS); core pariston, mafuuu; pool bisky (tests), gon, leorio (once-per-PR floor); wildcard zoro (shuf). Exceeds the 9-12 target because nine specialists triggered. Result: no P0-P2 after cross-check. 5 P3, 4 P4, 5 Nit withheld per requester scope. Reviewed against 3e5fbd7..4836b66.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This backport requires a setup token to create the first user on a try.coder.app tunnel, through POST /users/first, GitHub and OIDC sign-up, the setup page, and coder login. No P0, P1, or P2 findings. The server, CLI, and frontend changes match #32324 line for line except cfg.password in scripts/develop/main.go, and the new Go and frontend tests pass at this head. As requested, 14 findings at P3 and below are not posted.

Out of scope (needs a ticket or explicit acceptance by a human):

  • coderd/users.go:188: postFirstUser reads the user count outside a transaction, so two concurrent requests that both pass the check can each create an owner. On a tunnel, both requests now need the setup token.
  • docs/admin/setup/index.md:20: the Tunnel section does not say that the first user needs the setup token printed at startup, so a reader who starts there gets a 403 on the setup page without knowing why.
  • docs/install/docker.md:159: this page points proof-of-concept users to the tunnel and does not mention the setup token, with the same result.

Notes:

  • This is a feat: change on release/2.37. In a patch release, a script that calls POST /users/first against a tunnel deployment now gets 403 until it sends the token. A human needs to accept the cherry-pick under the release-branch policy and add a release note that names CODER_SETUP_TOKEN.

🤖 This review was automatically generated with Coder Agents.

@BobbyHo
BobbyHo merged commit fd4197f into release/2.37 Nov 20, 2026
32 of 33 checks passed
@BobbyHo
BobbyHo deleted the backport/32324-to-2.37 branch November 20, 2026 21:25

This branch had an error being deployed

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

Labels

backport/v2.37 Backport PR targeting release/2.37

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants