Repository navigation
fix(docker): 统一认证并锁定 OpenCode 构建与运行版本 - #190
ql0202cocou wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
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 toOPENCODE_SERVER_PASSWORD, fixed usernameopencode) 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
| 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); | ||
| } |

仅设置
OPENCODE_PASSWORD时,后端启用认证,但网关仍读取旧变量,导致预览管理接口按空密码放行。本 PR 统一两端认证,并固定 OpenCode 的构建及运行版本。OPENCODE_PASSWORD,否则回退OPENCODE_SERVER_PASSWORD,完整 Compose 部署的用户名统一为opencode。两种密码均为空时,网关和后端容器拒绝启动。docker compose config仅展开变量,空密码由容器入口和独立路由进程拒绝;独立网关/路由进程同时拒绝空用户名,认证检查也拒绝空凭据。部署时必须设置非空密码;旧密码变量仍兼容,完整 Compose 部署不再使用旧的自定义用户名。独立运行 gateway 或路由进程时,必须提供非空的
ROUTER_USERNAME和ROUTER_PASSWORD。升级 OpenCode 需更新后端镜像。README 和环境变量示例已同步。验证:
cargo check --locked --offline、cargo fmt --check、Shell 语法、actionlint 和git diff --check通过。