Repository navigation
Conversation
|
/coder-agents-review Please limit the review to P0, P1, and P2 issues only. |
|
Chat: Review posted | View chat Review historydeep-review v0.13.0 | Round 2 | Last posted: Round 2, 5 findings (1 P1, 4 P2), APPROVE. Review Finding inventoryFinding inventory: PR #32324Findings
Contested and acknowledgedCRF-6 (P2, cli/setuptoken.go:35) - Supplied setup token ignored when an access URL is set
Round logRound 1Full panel (round 1). Netero P1 at most, so the panel ran. Law not run (effective additions 745). Panel: ging-go, ging-ts, ging-react, kurapika, nami, ryosuke, luffy, melody, pen-botter (triggered specialists), pariston, mafuuu (core), bisky (tests), gon, leorio (once-per-PR floor), zoro (wildcard). 15 reviewers, above the 9-12 target because 9 domain specialists were triggered (Go, TS, React, auth/token, frontend, Go API, new config surface, wire-format fields, docs) plus required Bisky and the Gon/Leorio floor. The author asked in IC_kwDOGkVX1s8AAAABnmgEFA to limit the review to P0, P1, and P2. Only P0-P2 findings are posted; P3 and below are recorded here as dropped for that reason, and the review body states the count. Keep-argument against withholding: the findings are valid and there is no follow-up; the author's explicit request decides. Severity decisions:
CI: Reviewed against 81a51b1..2e57b46. Round 2Fix round, not a restructure: commits since R1 (5cc3a3f rebase, 50a720c slim build tag, 9f4cd1d length check, f5a0da2 docs and hint) patch prior findings and add no files to the tree; CRF-6 closed 2/2. Fixes for CRF-1, CRF-5, CRF-7, CRF-8 verified by Netero, Nami, Bisky, Kite, Pen Botter, Leorio. New: 4 P3 (CRF-37 to CRF-40), recorded and not posted per the author's repeated P0-P2 request (IC_kwDOGkVX1s8AAAABnqCfWQ). CRF-41 out of scope. CI: About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
This PR requires a setup token to create the first user when coder server runs on a try.coder.app tunnel. Findings: 1 P1, 4 P2.
As requested, only P0 to P2 findings are posted. 30 lower-severity findings and notes were recorded and are available on request. check-build and engine also fail; their logs could not be read from this environment, so their cause is unknown.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/users.go:178: a deployment with an access URL set and no users still lets anyone who reaches it create the Owner throughPOST /api/v2/users/first, so the first-user takeover remains open outside the tunnel case.
docs/get-started/index.md:206
P2 [CRF-7] Step 3 of the quickstart still says the first user can choose Continue with GitHub, but on the tunnel this quickstart uses, the setup page hides that button and oauthLogin refuses an OAuth first user. (Pen Botter)
Step 3 also does not mention the "Setup token" field, and the welcome-create-admin-user.png screenshot shows the old form. Replace the GitHub sentence with a step to enter the token from the Setup token: line, then create the account with an email and password.
🤖
docs/install/server/cloud/compute-engine.md:42
P2 [CRF-8] The GCP Marketplace guide ends with "Use the UI to create your first user", but on its tunnel URL the UI now asks for a setup token that the guide never says how to find. (Pen Botter)
The guide says the instance redirects to a public tunnel URL, so resolveSetupToken requires a token, and a user who launched a Marketplace image never saw the coder server output. Add the step this PR adds to azure-vm.md: SSH to the VM, run journalctl -u coder.service -b, and copy the Setup token: line. Whether the Marketplace image starts without an access URL was not confirmed by launching it.
🤖
🤖 This review was automatically generated with Coder Agents.
A server published through a try.coder.app tunnel let the first visitor become Owner. The server now prints a setup token at startup when it opened a tunnel and no user exists. The first-user endpoint refuses a request without it, and an OAuth sign-in cannot create the first user until setup is complete.
The slim binary must not import coderd/rbac, and the setup token code reaches it through dbauthz. It is only used by the server command, which is already left out of slim builds. Also write the nolint directive without a leading space.
5a349b3 to
50a720c
Compare
A short --setup-token stopped the server even when an access URL was set and the token was ignored. The warning for an ignored token now names coder server create-admin-user.
The setup page hint and the install page said a matching email is enough to sign in with GitHub later. The account must also be switched under Account > Security. The quickstart and the GCP guide now say where to find the setup token.
|
Replies to the two findings in the review body, both fixed in f5a0da2. CRF-7,
CRF-8,
|
|
/coder-agents-review Please limit the review to P0, P1, and P2 issues only. |
There was a problem hiding this comment.
Re-review of the fixes for the five findings from the previous review. No new P0 to P2 findings.
The nolint directive, the GitHub sign-in hint and docs/install/index.md, quickstart Step 3, and the GCP Marketplace guide are fixed. The finding about a supplied token being ignored with an access URL is closed: the --disable-password-auth lockout in the reply holds in the code (coderd/userauth.go:598-604), the warning now names coder server create-admin-user, and CORE-891 tracks the access-URL case. As requested, 4 P3 findings from this round are recorded and not posted. The failing engine job belongs to docs-pr-preview-deploy.yaml; its log could not be read here.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/database/migrations/000643_chat_project_templates.up.sql:1: the base branch has two migrations numbered 000643, so every database-backed test fails withduplicate migration file: 000643_skill_display_name.down.sqluntil the base branch mergesmain, which renumbers it to 000644. With that rename applied locally, the setup-token tests incliandcoderdpass.
🤖 This review was automatically generated with Coder Agents.
TL;DR
When
coder serverstarts without an access URL, it publishes itself on a publictry.coder.appaddress. Until the first account exists, anyone who finds that address can open the setup page and make themselves the Owner. This PR closes that gap. On a tunnel with no users, the server now prints a setup token in its own output, and the first account can only be created by someone who enters that token. The setup page andcoder loginboth ask for it. Deployments with an access URL are not changed.Refs https://linear.app/codercom/issue/CORE-784
Note
This PR is stacked on #32283 and targets that branch, so the diff shows only this change. It will be rebased onto
mainafter #32283 merges.How to navigate this PR
codersdk/users.go: the two new API fields,setup_tokenon the first-user request andsetup_token_requiredon the auth methods response.codersdk/deployment.go: the new--setup-tokenserver option. Check that it is marked secret and has no YAML key.coderd/setuptoken.go: the comparison and the two refusal responses. This is the most important file. Check that the comparison takes the same time for any input.coderd/users.go: the check inpostFirstUser. Check its position, after the "user already exists" response and before password validation.coderd/userauth.go: the check inoauthLogin, which covers both GitHub and OIDC, and the new field inuserAuthMethods.cli/setuptoken.go:resolveSetupTokendecides whether this start needs a token and prints it. Check the four outcomes: access URL set, users exist, token supplied, token generated.cli/server.go: one call, placed directly above the "Logs will stream in below" line.cli/login.go: the new prompt and the--first-user-setup-tokenflag.site/src/pages/SetupPage/SetupPageView.tsx: the new field, the hidden GitHub button and the email hint.scripts/develop/main.go:scripts/develop.shcreates its own token, so that it can still create the admin user on a tunnel.coderd/apidoc/docs.go,coderd/apidoc/swagger.json,site/src/api/typesGenerated.ts, everything underdocs/reference/,docs/admin/setup/configuration-reference.md, and the--helpgolden files undercli/testdata/andenterprise/cli/testdata/.oauthLogin. It runs only when no user exists and a token is required.Implementation
Server
coderd/coderd.go: newOptions.SetupToken. An empty value means no token is required. It is set once at startup and never changes.coderd/setuptoken.go(new): compares SHA-256 digests of the two tokens in constant time. A missing token and a wrong token get the same response.coderd/users.go:postFirstUserreturns 403 when a token is required and the request does not carry the right one.coderd/userauth.go:oauthLoginrefuses to create the first user when a token is required.userAuthMethodsreportssetup_token_required.cli/setuptoken.go(new) andcli/server.go: the token is required only when the server opened a tunnel and the user count is 0. The token lives in memory and a new one is generated on each start.codersdk/deployment.go:--setup-tokenandCODER_SETUP_TOKENlet an operator supply the token, for scripted installs. Minimum 24 characters.Clients
cli/login.go: asks for the token before the email, so someone without it stops early.--first-user-setup-tokenandCODER_FIRST_USER_SETUP_TOKENskip the prompt.site/src/pages/SetupPage/SetupPageView.tsx: shows a "Setup token" field when the server requires one.scripts/develop/main.go: when no access URL is passed, generates a token, gives it to the server throughCODER_SETUP_TOKEN, and sends it when it creates the admin user.Docs
docs/install/index.md,docs/install/server/rpm.md,docs/install/server/cloud/azure-vm.md,docs/install/server/cloud/compute-engine.md: a few sentences each, where the tunnel URL is introduced.docs/get-started/index.md: Step 3 of the quickstart lists the setup token and no longer offers Continue with GitHub. Thewelcome-create-admin-user.pngscreenshot is not updated yet.Choices a reviewer might question
--setup-tokenis ignored, with a warning, when an access URL is set. The token is a tunnel-only protection. A silent no-op would let an operator believe the first user is protected. Requiring a supplied token with an access URL is a separate change, tracked in CORE-891, because it would also refuse an OAuth first user on deployments that have password sign-in disabled.setup_token_requiredis a field on the existing auth methods response, not a new endpoint. The setup page andcoder loginalready call it.PasswordFieldcomponent. That component sends its value to the password strength endpoint.TestDeploymentValues_HighlyConfigurableincodersdk/deployment_test.go.Expected Output
coder serverwith no access URL and no users printsSetup token: <32 letters and digits>and one line of instructions, directly above "Logs will stream in below".--setup-tokenorCODER_SETUP_TOKEN, the server uses that token and prints only that a token is needed and where it was set.--setup-token must be at least 24 characters. The length is not checked when the token is not used.coder server create-admin-user.POST /api/v2/users/firstwithout the token, or with a wrong one, returns 403 with "A setup token is required to create the first user. Find it in the output of coder server." and a validation error onsetup_token.GET /api/v2/users/authmethodsincludes"setup_token_required": trueonly when a token is required.coder loginasks "Setup token:" before the email. It does not ask when the flag or environment variable is set, or when the server requires no token.scripts/develop.shwith no--access-urlstill creates its admin user without any manual step.Testing
coderd/users_test.go,TestFirstUser/SetupToken: missing and wrong tokens are refused with 403, the right token creates the user, and the auth methods response reports the requirement.coderd/userauth_test.go,SetupTokenBlocksFirstUserunderTestUserOAuth2GithubandTestUserOIDC: the OAuth sign-in is refused and no user is created.cli/setuptoken_internal_test.go,TestResolveSetupToken: access URL set, users exist, supplied token, short token, a short token that is ignored, generated token, and two starts that produce different tokens.cli/login_test.go,InitialUserSetupTokenPromptandInitialUserSetupTokenFlag: the prompt appears and the flag skips it.scripts/develop/main_test.goandscripts/develop/password_test.go: the token reaches the server's environment and the first-user request.site/src/pages/SetupPage/SetupPage.test.tsx: the token is sent when required, and left out of the request when not.site/src/pages/SetupPage/SetupPageView.stories.tsx:SetupTokenRequiredandSetupTokenRefused.coder serveroutput, and the full flow through a realtry.coder.apptunnel. Both were checked in the manual run. See Manual Test, scenarios 2 to 11.go test ./cli/... ./coderd/ ./codersdk/ ./scripts/develop/ ./enterprise/cli/for the tests above and the help golden files,pnpm vitest run src/pages/SetupPage, theSetupPageViewstories,pnpm lint:types,pnpm check,golangci-linton the changed packages, and the docs lint.make pre-commitand the full test suite have not been run locally.Manual Test
Run on 2026-11-17, 19:57 to 22:52 UTC, against this branch at
1b79d798f1. The run built the branch in a Linux development workspace and started throwawaycoder serverprocesses there, one at a time, each with its own config directory and built-in database, on a realtry.coder.apptunnel. The browser steps were done on a laptop against the public tunnel URL, with a real GitHub account.No setup token and no password was printed during the run. The helpers read a token from the server's log into a shell variable and print only its length and a short SHA-256 fingerprint. In the output below a token is shown as
<token>, the tunnel address ashttps://<id>.pit-1.try.coder.app, and the email of the GitHub account is left out.23 of 23 scenarios passed.
coder loginasks for the token firstcoder loginwith--first-user-setup-token./scripts/develop.shon a tunnelFacts worth knowing from the run:
mainon a tunnel can be taken over by anyone who finds its URL, so none was started. Scenario 19 shows the behaviour from before this PR on a loopback address: a request with no token gets 201.main. The server keeps its tunnel key in the user's config folder (~/.config/coderv2/devtunnelon Linux), not in the directory that--global-confignames. Every server in this run got the same public URL, with a new database each time. So someone who learned the URL of an earlier trial knows the URL of the next one on the same machine before its operator opens it. That is the situation this PR is for.coder loginends on the first wrong setup token. An empty answer atSetup token:prints a sentence and asks again. A wrong answer is sent to the server, refused, and the command exits 1 (scenario 15). The operator has to run the command again. Not changed in this PR.setup_token_requiredafter the first user exists, until it restarts (scenarios 12 and 13). It has no effect. The setup page is not shown once a user exists, and three sign-ins happened while the field was still true.main. In scenario 11 the server loggedfailed to delete old API key in convert to oidcwithno authorization actor in context. The code is incoderd/userauth.goand is not part of this PR. The browser's cookie is cleared, but the old session stays in the database until it expires.main. Every start in this run printed[erro] embedded NATS pubsub is enabled but this replica has no cluster hostand went on. On a tunnel server it is the third line aboveSetup token:(scenario 2)../scripts/develop.sh --skip-setupthe token is one log line among many. develop wraps each line of the server in its own log format, and its large banner comes ten lines later (scenario 20). On a plaincoder serverthe token stands alone above the logs line.docs/images/screenshots/welcome-create-admin-user.pnghas Email as the first field. A new picture with the "Setup token" field was taken in scenario 8 and is not in this PR yet.CODER_URLandCODER_SESSION_TOKENfor its own agent, and the CLI prefers those to the config directory, so onewhoamicheck had to be run with both removed (scenario 16). Andvitestends there with three lines about a process that did not exit, which is not a test failure (scenario 22).1. Environment
The helpers used below, all defined in one file in the workspace:
srv_start NAME [flags]startscoder serverin the background with--global-config ~/core784b/cfg/NAME,--http-address 127.0.0.1:3400and telemetry off, and writes its output to a new log file.srv_waitwaits for the "Logs will stream in below" line or for the process to exit.srv_stopsends an interrupt and waits.turl NAMEprints the tunnel URL from the newest log.tok NAMEreads the setup token from the newest log, and is only ever used asT=$(tok NAME).tokinfo NAMEprints the token's length, whether it is only letters and digits, a 12-character SHA-256 fingerprint, the number of log lines that contain the value and the number ofSetup token:lines. It never prints the value.masked NAMEprints the start-up output with the token replaced.methods URLprints three fields of/api/v2/users/authmethods.hasuser URLprints the status ofGET /api/v2/users/first, which is 404 while no user exists and 200 once one does.post_first URL TOKEN [EMAIL] [PASSWORD]posts to/api/v2/users/firstand prints the body and the status. A token of-sends nosetup_tokenfield. The password defaults to the random test password in~/core784b/pw.Servers are named
t1tot5. Only one runs at a time.2. A tunnel server with no users prints a setup token
The token line is directly above the logs line, where an operator looks. It is 32 letters and digits, and the value is in exactly one line of the log. This server stayed up for scenarios 3 to 13.
3. A client that is not signed in learns that a token is needed, and not the token
The new field is a boolean. None of the six public responses contains the token, and the sizes show that the search was over real bodies.
4. A first-user request without the token is refused, from two networks
Both machines get the same body and no user exists afterwards. Before this PR this request made its sender the Owner.
5. Four wrong tokens get the same answer
One body, four times, and it is the body of scenario 4. A missing token and a wrong token cannot be told apart, and no answer contains the real token. The third value differed from the real token in one byte.
6. The token is checked before the password
The same request with the password
agets 400 where no token is required, and 403 with no word about the password where one is. A stranger without the token learns nothing about the other rules.7. GitHub sign-in before setup is refused
The callback URL sent the browser to
/login/device, which showed a one-time code. After GitHub approved, the page kept its code and link and showed this in an error box where "Checking for authentication…" had been:The browser was not signed in and no user exists. Before this PR the first OAuth sign-in on a server with no users created the Owner. The 403 status of the refused request was not captured in the browser.
TestUserOAuth2Github/SetupTokenBlocksFirstUserchecks it (scenario 22).8. The setup page asks for the token and hides the GitHub button
Browser: open the tunnel URL. It lands on
/setup. Read from the page:"Setup token" is the first field and hides what is typed. The only button is Continue. There is no GitHub button and no "or" divider, so the page does not lead into the refusal of scenario 7. The word GitHub appears once, in the Email hint.
9. A wrong token on the setup page
Browser: type
not-the-tokenin Setup token, the primary email of the GitHub account in Email, the test password in Password, and select Continue.The form shows the server's message, marks the token field, and keeps the other fields. The alert is at the bottom of the form by the Continue button and the marked field is at the top, so on a short window they are a screen apart.
10. The right token on the setup page creates the Owner
The email, the password and the browser session were the same as in scenario 9. Only the token changed. The server had been public with no users for 32 minutes, and every first-user attempt in that time was refused.
11. The first account switches to GitHub sign-in and signs in with it
Browser, by selecting only: the user menu, then Account, then Security. No address was typed.
Then: select GitHub, confirm with the password, complete the device flow on GitHub.
Then: select GitHub on the sign-in page and complete the device flow.
The user id is the one the audit log gave the first user in scenario 10, and the deployment still has one user. So GitHub signed in to the existing account and created no second one, and the account is still Owner. A sign-in with the email and the old password was then refused with "Incorrect email or password."
The server also logged one warning during the switch. See fact 8.
12. After setup the token does nothing
The right token, no token and a wrong token all get the same 409. A token that leaks after setup cannot create a second Owner, and the answer does not say whether it was right. The last line is fact 7.
13. A restart with a user prints no token and requires none
The second start prints no token, and the
setup_token_requiredkey is gone from the answer, which is then the same JSON as before this PR.14. A restart before setup gives a new token
Two starts of one config directory give two tokens, and the first is refused by the second start. Neither is in any of the 2936 files of the config directory, so the token is not stored.
t2had the same public URL ast1. See fact 4.15. coder login asks for the token first
coder loginneeds a terminal for its prompt. A short script ran it in a pseudo-terminal, waited for the prompt, sent an empty line, waited for the prompt again, and sentnot-the-token-not-the-token.The token is the first and only question, since the email and password come by flag. An empty answer is not sent. A wrong answer ends the command with the server's message. The same command run by hand in a terminal ended with the same five error lines and
exit 1. See fact 5.16. coder login with --first-user-setup-token
No prompt, and the output does not contain the token. The two
whoamilines were run after a restart oft2, with the workspace's ownCODER_URLandCODER_SESSION_TOKENremoved. See fact 12.17. A supplied token that is too short stops a tunnel server
The server stops before it serves the API. The error names the option and not the value.
18. A supplied token is used and is not shown
The server says a token was supplied and does not print it. The supplied value creates the first user and a request without it is refused. The value is in 0 lines of the log and is hidden in the 163 KB deployment settings response, the same way the database URL is. The option has no YAML key.
19. With an access URL nothing changes
No tunnel, no token printed, none required, and a request with no token creates the first user, as before this PR. A supplied token is ignored with a warning that says what to do, and its length is not checked when it is ignored. The same 23 characters stopped the tunnel server in scenario 17.
20. ./scripts/develop.sh on a tunnel
With setup, develop reached its banner in 55 seconds with no manual step. The server required a token and a user existed five seconds after the server was ready, and only develop held the token. The token was in the server's environment and on no command line. With
--skip-setup, develop supplies no token, the server prints its own, and that token finishes setup by hand.21. Docs and reference
All five install pages say where the token is. The words agree with the run: the line starts with
Setup token:(scenario 2),coder loginasks for it (scenario 15), and the switch is under Account, then Security (scenario 11). Of the six pages that name the tunnel, three are among the five, two are generated reference, and one has a tunnel address only inside an example message. Step 3 of the quickstart lists Setup token, Email, Password, in the order of the form.22. Unit tests on Linux
A second run with
-vlisted the tests by name, since a pattern that matches nothing also printsok. All of these passed:TestFirstUser/SetupToken,TestUserOAuth2Github/SetupTokenBlocksFirstUser,TestUserOIDC/SetupTokenBlocksFirstUser, the nine subtests ofTestResolveSetupToken,TestDevConfigServerCmdSetupTokenandTestSetupFirstUser/SendsSetupToken. The threecoderdgroups had 83 results, none failed and none was skipped. The OIDC test covers the path this run had no provider for.23. Cleanup