Skip to content

fix(cli): make serve honor OPENCODE_SERVER_PASSWORD as documented opt-in - #46270

Closed
cd-slash wants to merge 1 commit into
anomalyco:devfrom
cd-slash:fix/serve-auth-opt-in
Closed

cd-slash wants to merge 1 commit into
anomalyco:devfrom
cd-slash:fix/serve-auth-opt-in

Conversation

@cd-slash

Copy link
Copy Markdown

Problem

opencode2 serve unconditionally resolved the daemon-managed password and served with mandatory HTTP basic auth — generating and printing a fresh password per start when OPENCODE_SERVER_PASSWORD was unset. This contradicts the documented behavior (both V1 and V2 docs describe OPENCODE_SERVER_PASSWORD as opt-in: "Set OPENCODE_SERVER_PASSWORD to protect the server with HTTP basic auth"), and it breaks headless deployments that are already gated at the edge (e.g. Cloudflare Access in front of a tunnel), which get a rotating credential they never asked for.

Repro (beta 18684)

OPENCODE_DB=/tmp/x.db opencode2 serve --port 5199   # prints "server password ..."
curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:5199/api/health   # 401 without basic auth

Change

packages/cli serve handler: pass the password to createRoutes only when OPENCODE_SERVER_PASSWORD is set; otherwise serve unsecured with the same warning that packages/opencode serve prints. Daemon (--register) flows keep the daemon-managed credential, so managed clients (TUI/desktop) are unaffected.

ServerAuth.required() and the authorization middleware already treat a missing password as "no auth", and createRoutes(password?: string) already accepted an optional password — so this only removes the forced resolution in the CLI handler.

Test

  • Built packages/cli (linux-x64) and verified: no env → warning + unauthenticated 200 /api/health; OPENCODE_SERVER_PASSWORD=secret123 → 401 unauthenticated, 200 with Basic opencode:secret123.
  • Existing suite covers the server side (httpapi-authorization.test.ts: "allows requests when server password is not configured`).

opencode2 serve unconditionally resolved the daemon-managed password and
served with mandatory HTTP basic auth (generating a fresh password per
start when OPENCODE_SERVER_PASSWORD was unset), contradicting the
documented behavior where setting OPENCODE_SERVER_PASSWORD opts in to
protection. It also made deployments that are already gated at the edge
(e.g. Cloudflare Access) pay for a rotating credential they never asked
for.

Serve unsecured with a warning when no password is configured, matching
packages/opencode serve; keep daemon (--register) flows on the daemon
credential so managed clients keep working.

Signed-off-by: cd-slash <[email protected]>
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants