Skip to content

fix(docker): 统一认证并锁定 OpenCode 构建与运行版本 - #190

Closed
ql0202cocou wants to merge 5 commits into
lehhair:devfrom
ql0202cocou:codex/docker-auth-release-pinning
Closed

ql0202cocou wants to merge 5 commits into
lehhair:devfrom
ql0202cocou:codex/docker-auth-release-pinning

Conversation

@ql0202cocou

@ql0202cocou ql0202cocou commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

仅设置 OPENCODE_PASSWORD 时,后端启用认证,但网关仍读取旧变量,导致预览管理接口按空密码放行。本 PR 统一两端认证,并固定 OpenCode 的构建及运行版本。

  • 网关和后端优先使用非空的 OPENCODE_PASSWORD,否则回退 OPENCODE_SERVER_PASSWORD,完整 Compose 部署的用户名统一为 opencode。两种密码均为空时,网关和后端容器拒绝启动。
  • Compose 使用兼容 v2/v5 的默认值回退,避免 v2 提前计算嵌套必填表达式,导致只设置新密码也报旧密码缺失。docker compose config 仅展开变量,空密码由容器入口和独立路由进程拒绝;独立网关/路由进程同时拒绝空用户名,认证检查也拒绝空凭据。
  • CI 只读取一次发行清单,将版本、各架构下载地址与摘要一起传入构建,避免上游切换 latest 时两次取值不一致;安装时校验摘要和完整二进制版本。
  • 服务使用镜像内的绝对路径,运行时补装使用镜像保存的同一份清单,避免持久化 PATH 中的旧程序或重新读取 latest 改变运行版本。
  • 新增配置、安装及真实容器认证回归测试,并接入 Docker Validation 工作流;CI 输出 Compose 版本,失败时显示子进程 stderr。

部署时必须设置非空密码;旧密码变量仍兼容,完整 Compose 部署不再使用旧的自定义用户名。独立运行 gateway 或路由进程时,必须提供非空的 ROUTER_USERNAME 和 ROUTER_PASSWORD。升级 OpenCode 需更新后端镜像。README 和环境变量示例已同步。

验证:

  • Compose 2.38.2(失败 runner 的版本)和 5.6.1 各通过 9 项配置和安装回归测试,覆盖新/旧密码、同时设置、空新值回退、双架构清单复用、校验失败及运行时补装。
  • 3 项 ARM64 真实容器集成测试通过,使用 Compose 2.38.2 展开配置,覆盖空密码拒绝启动、缺失/空路由用户名拒绝启动、四组密码配置、后端与预览接口认证、空用户名请求拒绝、错误认证不改变端口,以及服务/二进制/清单版本一致。
  • Rust cargo check --locked --offline、cargo fmt --check、Shell 语法、actionlint 和 git diff --check 通过。
  • GitHub Actions 当前提交的 Docker Validation 和 Build Validation 均通过;Docker 工作流在 Ubuntu amd64 上完成配置和安装回归、双镜像构建及 3 项真实容器集成测试。

Copilot AI balanced review requested due to automatic review settings November 9, 2026 16:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

A critical active finding remains because startup enforces a non-empty ROUTER_PASSWORD while allowing an empty ROUTER_USERNAME default in src-router/src/main.rs, potentially enabling Basic Auth with an empty username and causing misconfigured, unexpectedly accessible deployments.

1 open issue
What changed in this PR

This pull request fixes a Docker deployment authentication mismatch between the gateway/router and backend by standardizing credential precedence and enforcing non-empty credentials, and it pins the OpenCode CLI build/runtime versions using a single resolved release manifest to avoid latest drift.

Changes:

  • Unify gateway/router/backend auth configuration (prefer OPENCODE_PASSWORD, fallback to OPENCODE_SERVER_PASSWORD, fixed username opencode) and fail fast when passwords are empty.
  • Resolve the OpenCode release manifest once for builds, pass it into the image, and verify checksums + binary version for deterministic installs.
  • Add Docker regression/integration tests and CI workflows to validate Compose wiring, pinned installs, and real-container auth behavior.

This pull request requires changes.

File Summary
src-router/​src/​router.rs Tightens Basic Auth behavior to reject insecure/empty-password configurations.
src-router/​src/​main.rs Fails fast on startup if ROUTER_PASSWORD is unset/empty to prevent insecure operation.
scripts/​test-docker.py Adds Docker regression + integration tests for Compose auth wiring and pinned OpenCode release behavior.
README.md Updates Docker deployment instructions and environment variable guidance for the unified auth model and version pinning.
README_EN.md Mirrors README updates in English for the new auth requirement and pinned OpenCode behavior.
docker/​resolve-opencode-release.sh Resolves OpenCode release once and emits version + base64 manifest for CI/build args.
docker/​opencode-release.sh Shared helpers for manifest parsing, download + checksum validation, and binary version verification.
docker/​entrypoint-gateway.sh Enforces non-empty router password at gateway container startup before launching services.
docker/​Dockerfile.backend Saves the resolved manifest into the image and installs a verified/pinned CLI; uses absolute binary path.
docker/​backend-entrypoint.sh Reuses the saved manifest for runtime repair and normalizes env selection for opencode serve.
docker-compose.yml Unifies gateway/backend credential precedence and rejects startup when both password vars are empty; fixes router username to opencode.
docker-compose.build.yml Adds OPENCODE_MANIFEST_BASE64 build-arg passthrough for local/CI builds.
.github/​workflows/​docker-tests.yml Adds a Docker validation workflow to run regressions and real-container auth checks.
.github/​workflows/​docker-backend.yml Updates backend image workflow to resolve the release once and pass the pinned manifest into the build.
.env.example Updates the env template to reflect required password configuration and the new/legacy precedence.

Review effort: Balanced

Comment thread src-router/src/main.rs
Comment on lines 16 to +20
let config = Arc::new(Config::from_env());
if config.router_password().is_empty() {
log::error!("ROUTER_PASSWORD must be set to a non-empty password");
std::process::exit(1);
}
@ql0202cocou

Copy link
Copy Markdown
Contributor Author

本 PR 因 fork 仓库曾被删除而无法重开,已由 #195 取代:分支已 rebase 到最新 dev(v0.7.30,无冲突),rebase 后 9 项回归测试复跑通过,内容与本 PR 一致。后续评审请移步 #195。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants