Просмотр исходного кода

【修复,CI】冒烟测试按语义断言 trustedHosts 注入

Merge pull request #20 from Xidong-AI/fix/trusted-hosts-assert
PJ568 1 месяц назад
Родитель
Сommit
e75ae051db
5 измененных файлов с 78 добавлено и 19 удалено
  1. 1 1
      Dockerfile
  2. 6 6
      README.md
  3. 7 7
      README.zh.md
  4. 1 1
      docker-compose.yml
  5. 63 4
      scripts/smoke-test.sh

+ 1 - 1
Dockerfile

@@ -20,7 +20,7 @@
 # so agents can compile native modules (e.g. plugin node-pty) at runtime as a fallback.
 # See the runtime stage notes for the trade-off.
 
-ARG DSH_VERSION=0.1.5-rc.3
+ARG DSH_VERSION=0.1.7-rc.2
 
 # Caddy 官方镜像
 # 静态二进制,与平台无关

+ 6 - 6
README.md

@@ -9,7 +9,7 @@ Containerized deployment of the [DeepSeek Harness](https://github.com/deepseek-a
 ## Features
 
 - Self-contained single container: dsh (loopback only, inside the container) + Caddy pure reverse proxy (Host/Origin rewritten to loopback for the dsh anti-DNS-rebinding fence)
-- **Authentication since dsh 0.1.5-rc.3**: moved into dsh itself. On first start, dsh prints a one-time `?token=…` URL; the browser exchanges it for a persistent cookie (survives restarts). Caddy basic auth was removed in 0.1.5-rc.3+ (would have intercepted the browser's first redirect and hidden the token URL)
+- **Authentication since dsh 0.1.7-rc.2**: moved into dsh itself. On first start, dsh prints a one-time `?token=…` URL; the browser exchanges it for a persistent cookie (survives restarts). Caddy basic auth was removed in 0.1.7-rc.2+ (would have intercepted the browser's first redirect and hidden the token URL)
 - Configuration and project/session data persisted: bind mount `./data` → `/home/node` (the whole HOME: settings.yaml, API Key, profiles, sessions, storages, plus agent-installed tools under `~/.x-cmd.root`)
 - Runs as non-root (uid 1000); dsh is not exposed directly
 - Built-in health check: `docker compose ps` shows the real service health (`starting`/`healthy`/`unhealthy`), exchanging the one-time token for a cookie and probing dsh
@@ -30,14 +30,14 @@ cp .env.example .env    # edit DEEPSEEK_API_KEY (DSH_AUTH_USER/PASSWORD are now
 docker compose up -d    # pull the latest image and start
 ```
 
-> ⚠️ **升级警告 — 升级到含 dsh 0.1.5-rc.3+ 鉴权迁移的版本时,必须先 `git pull` 同步 `docker-compose.yml` / `Caddyfile` / `entrypoint.sh` / `entrypoint.sh 内的 token 抓取后台任务`,仅 `docker compose pull` 拉新 image 配旧 compose 文件会导致 healthcheck 永远 unhealthy 且 web 服务裸奔 (无鉴权)。** 具体见 PR #7 的 commit message 与 DESIGN.md §10 的版本演进记录。
+> ⚠️ **升级警告 — 升级到含 dsh 0.1.7-rc.2+ 鉴权迁移的版本时,必须先 `git pull` 同步 `docker-compose.yml` / `Caddyfile` / `entrypoint.sh` / `entrypoint.sh 内的 token 抓取后台任务`,仅 `docker compose pull` 拉新 image 配旧 compose 文件会导致 healthcheck 永远 unhealthy 且 web 服务裸奔 (无鉴权)。** 具体见 PR #7 的 commit message 与 DESIGN.md §10 的版本演进记录。
 
 ### Option 2: Build locally
 
 ```bash
 docker compose up -d --build
 # or pin a dsh version:
-docker build --build-arg DSH_VERSION=0.1.5-rc.3 -t dsh-web:latest .
+docker build --build-arg DSH_VERSION=0.1.7-rc.2 -t dsh-web:latest .
 ```
 
 After startup, **read the one-time launch URL** with one of:
@@ -56,8 +56,8 @@ Then open the printed URL (e.g. `http://<host>:3080/?token=…`) in a browser. T
 
 | Variable | Required | Default | Description |
 | --- | --- | --- | --- |
-| `DSH_AUTH_USER` | No (since 0.1.5-rc.3) | `admin` | Was: Basic Auth username. Now kept only for rollback to ≤0.1.1 series; ignored on 0.1.5-rc.3+ |
-| `DSH_AUTH_PASSWORD` | No (since 0.1.5-rc.3) | None | Was: Basic Auth plaintext password (bcrypt hash auto-generated). Now kept only for rollback to ≤0.1.1 series |
+| `DSH_AUTH_USER` | No (since 0.1.7-rc.2) | `admin` | Was: Basic Auth username. Now kept only for rollback to ≤0.1.1 series; ignored on 0.1.7-rc.2+ |
+| `DSH_AUTH_PASSWORD` | No (since 0.1.7-rc.2) | None | Was: Basic Auth plaintext password (bcrypt hash auto-generated). Now kept only for rollback to ≤0.1.1 series |
 | `DEEPSEEK_API_KEY` | Yes | None | DeepSeek API Key (referenced by the provider via apiKeyEnv) |
 | `DSH_WEB_PORT` | No | `3080` | Host port exposed to the outside (change it when it conflicts with an existing service) |
 | `DSH_TRUSTED_HOSTS` | No | Empty | Comma-separated extra trusted hosts, injected into the profile's `cordis.patch.yml` (only when the file is absent or still the empty template; user-maintained files are skipped — edit the file directly); by default Caddy rewrites Host/Origin to loopback, which covers normal access |
@@ -126,7 +126,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends <pkg> \
 
 ## Changing the Password / Resetting Auth
 
-**dsh 0.1.5-rc.3+ (current)**: dsh's persistent cookie is the auth, kept in `./data/.dsh/.credentials.yaml`. To reset after a suspected leak, you **must** rebuild the data volume — `docker compose down -v && docker compose up -d`. The next browser visit uses a new one-time token URL (`docker exec dsh-web cat /home/node/.dsh/web-launch-url.txt`).
+**dsh 0.1.7-rc.2+ (current)**: dsh's persistent cookie is the auth, kept in `./data/.dsh/.credentials.yaml`. To reset after a suspected leak, you **must** rebuild the data volume — `docker compose down -v && docker compose up -d`. The next browser visit uses a new one-time token URL (`docker exec dsh-web cat /home/node/.dsh/web-launch-url.txt`).
 
 > ⚠️ `down -v` is destructive: it also wipes `./data/.dsh/` (settings, profiles, sessions, agent-installed tools under `~/.x-cmd.root`). There is no lighter reset path — the entrypoint's token-extraction background task is one-shot (`grep -m1`), so a single-file `.credentials.yaml` delete plus container restart will NOT refresh the token URL. If you need to preserve session data, take a backup of `./data/.dsh/` before `down -v` and restore specific subpaths afterwards (e.g. `.dsh/profiles/`, `.dsh/AGENTS.md`).
 

+ 7 - 7
README.zh.md

@@ -9,7 +9,7 @@
 ## 特性
 
 - 单容器自包含:dsh(仅容器内 loopback)+ Caddy 纯反代(无鉴权,Host/Origin 改写为 loopback 配合 dsh 防 DNS rebinding 的 fence)
-- **dsh 0.1.5-rc.3+ 鉴权**:迁回 dsh 自身。dsh 启动时打印一次性 `?token=…` URL,浏览器首次访问该 URL 后 303 跳转并 Set-Cookie,cookie 持久化在数据卷(容器重启后仍有效)。Caddy basic auth 自 0.1.5-rc.3 起移除(旧版会拦截首次重定向、把 dsh 的 token URL 藏住,浏览器根本拿不到)
+- **dsh 0.1.7-rc.2+ 鉴权**:迁回 dsh 自身。dsh 启动时打印一次性 `?token=…` URL,浏览器首次访问该 URL 后 303 跳转并 Set-Cookie,cookie 持久化在数据卷(容器重启后仍有效)。Caddy basic auth 自 0.1.7-rc.2 起移除(旧版会拦截首次重定向、把 dsh 的 token URL 藏住,浏览器根本拿不到)
 - 配置与项目/会话数据持久化:bind mount `./data` → `/home/node`(整个 HOME:settings.yaml、API Key、profiles、sessions、storages,及 agent 自装工具 `~/.x-cmd.root`)
 - 非 root 运行(uid 1000),dsh 不直接对外暴露
 - 内置健康检查:`docker compose ps` 直接可见服务真实健康状态(抓 dsh 一次性 token 换 cookie 后探测 dsh 响应,`starting`/`healthy`/`unhealthy`)
@@ -26,18 +26,18 @@
 ```bash
 git clone https://github.com/Xidong-AI/deepseek-harness-web-docker
 cd deepseek-harness-web-docker
-cp .env.example .env    # 编辑 DEEPSEEK_API_KEY(DSH_AUTH_USER/PASSWORD 自 0.1.5-rc.3 起可选,仅回退到 ≤0.1.1 系列时需要)
+cp .env.example .env    # 编辑 DEEPSEEK_API_KEY(DSH_AUTH_USER/PASSWORD 自 0.1.7-rc.2 起可选,仅回退到 ≤0.1.1 系列时需要)
 docker compose up -d    # 拉取 latest 镜像并启动
 ```
 
-> ⚠️ **升级警告 — 升级到含 dsh 0.1.5-rc.3+ 鉴权迁移的版本时,必须先 `git pull` 同步 `docker-compose.yml` / `Caddyfile` / `entrypoint.sh` 内的 token 抓取后台任务,仅 `docker compose pull` 拉新 image 配旧 compose 文件会导致 healthcheck 永远 unhealthy 且 web 服务裸奔 (无鉴权)。** 具体见 PR #7 的 commit message 与 DESIGN.md §10 的版本演进记录。
+> ⚠️ **升级警告 — 升级到含 dsh 0.1.7-rc.2+ 鉴权迁移的版本时,必须先 `git pull` 同步 `docker-compose.yml` / `Caddyfile` / `entrypoint.sh` 内的 token 抓取后台任务,仅 `docker compose pull` 拉新 image 配旧 compose 文件会导致 healthcheck 永远 unhealthy 且 web 服务裸奔 (无鉴权)。** 具体见 PR #7 的 commit message 与 DESIGN.md §10 的版本演进记录。
 
 ### 方式二:本地构建
 
 ```bash
 docker compose up -d --build
 # 或指定 dsh 版本:
-docker build --build-arg DSH_VERSION=0.1.5-rc.3 -t dsh-web:latest .
+docker build --build-arg DSH_VERSION=0.1.7-rc.2 -t dsh-web:latest .
 ```
 
 启动后**先取一次性启动 URL**,任选一种方式:
@@ -56,8 +56,8 @@ docker exec dsh-web cat /home/node/.dsh/web-launch-url.txt
 
 | 变量 | 必填 | 默认 | 说明 |
 | --- | --- | --- | --- |
-| `DSH_AUTH_USER` | 否(自 0.1.5-rc.3) | `admin` | 旧版 basic auth 用户名;0.1.5-rc.3+ 已忽略,仅作回退兼容位 |
-| `DSH_AUTH_PASSWORD` | 否(自 0.1.5-rc.3) | 无 | 旧版 basic auth 明文密码(容器启动时自动生成 bcrypt 哈希);0.1.5-rc.3+ 已忽略,仅作回退兼容位 |
+| `DSH_AUTH_USER` | 否(自 0.1.7-rc.2) | `admin` | 旧版 basic auth 用户名;0.1.7-rc.2+ 已忽略,仅作回退兼容位 |
+| `DSH_AUTH_PASSWORD` | 否(自 0.1.7-rc.2) | 无 | 旧版 basic auth 明文密码(容器启动时自动生成 bcrypt 哈希);0.1.7-rc.2+ 已忽略,仅作回退兼容位 |
 | `DEEPSEEK_API_KEY` | 是 | 无 | DeepSeek API Key(provider 经 apiKeyEnv 引用) |
 | `DSH_WEB_PORT` | 否 | `3080` | 宿主机对外端口(与已有服务冲突时修改) |
 | `DSH_TRUSTED_HOSTS` | 否 | 空 | 逗号分隔的额外受信 Host,注入 profile 的 `cordis.patch.yml`(仅当该文件不存在或仍为空模板时自动注入;已维护则跳过,请直接编辑该文件);默认靠 Caddy 改写 Host/Origin 为 loopback 已覆盖常规访问 |
@@ -126,7 +126,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends <pkg> \
 
 ## 修改密码 / 重置鉴权
 
-**dsh 0.1.5-rc.3+(当前)**:dsh 持久 cookie 是鉴权载体,存于 `./data/.dsh/.credentials.yaml`。怀疑泄露需重置时,**必须**重建数据卷 — `docker compose down -v && docker compose up -d`。下次浏览器访问需用新的一次性 token URL(`docker exec dsh-web cat /home/node/.dsh/web-launch-url.txt`)。
+**dsh 0.1.7-rc.2+(当前)**:dsh 持久 cookie 是鉴权载体,存于 `./data/.dsh/.credentials.yaml`。怀疑泄露需重置时,**必须**重建数据卷 — `docker compose down -v && docker compose up -d`。下次浏览器访问需用新的一次性 token URL(`docker exec dsh-web cat /home/node/.dsh/web-launch-url.txt`)。
 
 > ⚠️ `down -v` 是破坏性操作:会同时清空 `./data/.dsh/`(settings、profiles、sessions,及 agent 自装工具 `~/.x-cmd.root`)。目前没有更轻量的重置路径 — entrypoint 的 token 抓取后台任务是单次执行(`grep -m1`),仅删 `.credentials.yaml` 后重启容器**不会**重抓 token URL。如需保留会话数据,先备份 `./data/.dsh/`,重置后按需恢复子路径(如 `.dsh/profiles/`、`.dsh/AGENTS.md`)。
 

+ 1 - 1
docker-compose.yml

@@ -13,7 +13,7 @@ services:
     build:
       context: .
       args:
-        DSH_VERSION: ${DSH_VERSION:-0.1.5-rc.3}
+        DSH_VERSION: ${DSH_VERSION:-0.1.7-rc.2}
     container_name: dsh-web
     restart: unless-stopped
     ports:

+ 63 - 4
scripts/smoke-test.sh

@@ -257,9 +257,68 @@ fi
 echo "==> trustedHosts 注入检查"
 # DSH_TRUSTED_HOSTS 在启动时注入 cordis.patch.yml(entrypoint 在 dsh 首启前预写,
 # dsh 的 initProfile 对已存在文件不覆盖);此处验证注入结果
-docker exec "$CID" sh -c 'grep -q "smoke.example.com" /home/node/.dsh/profiles/web/cordis.patch.yml' \
-  || { echo "错误:trustedHosts 未注入 cordis.patch.yml" >&2; exit 1; }
-docker exec "$CID" sh -c 'yq ". | length" /home/node/.dsh/profiles/web/cordis.patch.yml | grep -q "^1$"' \
-  || { echo "错误:cordis.patch.yml 应为 1 个条目" >&2; exit 1; }
+#
+# 断言按语义(id=connection 的条目恰好 1 条、trustedHosts 恰为 smoke.example.com),
+# 不按「顶层条目总数 == 1」:dsh 可能在用户 patch 之外自行追加条目(插件启停记录等),
+# 总条目数断言会把这种正常追加误判成注入失败。此前 #19 只留下一句「应为 1 个条目」,
+# 日志里既没有实际条目数也没有文件内容,无从定位;本次同时补上失败现场 dump
+#
+# Assert on semantics (exactly one id=connection row whose trustedHosts is
+# smoke.example.com), not on the top-level row count: dsh may legitimately append
+# rows of its own (plugin enable/disable records), and a "total == 1" assert
+# misreads that as a failed injection. Issue #19 previously left only the message
+# "should be 1 entry" — no actual count, no file content; this also adds a
+# failure-scene dump.
+PATCH_PATH=/home/node/.dsh/profiles/web/cordis.patch.yml
+dump_patch() {
+  {
+    echo "--- 诊断:$PATCH_PATH ---"
+    docker exec "$CID" sh -c 'ls -la /home/node/.dsh/profiles/web' || true
+    echo "--- 文件内容(cat -n)---"
+    docker exec "$CID" sh -c "cat -n '$PATCH_PATH'" || true
+    echo "--- yq / jq 版本与条目数 ---"
+    docker exec "$CID" sh -c "command -v yq; yq --version; jq --version; yq '. | length' '$PATCH_PATH'" || true
+    echo "--- 容器日志(末 30 行)---"
+    docker logs "$CID" 2>&1 | tail -30 || true
+  } >&2
+}
+
+if ! docker exec "$CID" sh -c "grep -q 'smoke.example.com' '$PATCH_PATH'"; then
+  echo "错误:trustedHosts 未注入 $PATCH_PATH" >&2
+  dump_patch
+  exit 1
+fi
+
+# id=connection 条目必须恰好 1 条(entrypoint 只写一条;重复=注入逻辑回归)
+#
+# Exactly one id=connection row (the entrypoint writes a single one; a duplicate means the injection regressed)
+CONN_ROWS="$(docker exec "$CID" sh -c "yq '[.[] | select(.id == \"connection\")] | length' '$PATCH_PATH'" 2>/dev/null || true)"
+if [ "$CONN_ROWS" != "1" ]; then
+  echo "错误:$PATCH_PATH 中 id=connection 的条目应为 1 条,实际 [${CONN_ROWS:-查询失败}]" >&2
+  dump_patch
+  exit 1
+fi
+
+# connection.trustedHosts 必须恰为 smoke.example.com(注入值被 Caddy/其他层覆盖也算回归)
+#
+# connection.trustedHosts must be exactly smoke.example.com (an overwrite by Caddy or another layer is a regression too)
+CONN_HOSTS="$(docker exec "$CID" sh -c "yq -r '.[] | select(.id == \"connection\") | .config.trustedHosts // [] | join(\",\")' '$PATCH_PATH'" 2>/dev/null || true)"
+if [ "$CONN_HOSTS" != "smoke.example.com" ]; then
+  echo "错误:connection.trustedHosts 应为 smoke.example.com,实际 [${CONN_HOSTS:-空/查询失败}]" >&2
+  dump_patch
+  exit 1
+fi
+# 始终打印「实际条目数 + 注入值」:条目数不是断言条件,但它是判断 dsh 是否追加过条目的关键证据
+#
+# Always print the real row count and injected value: the count is not an assert condition,
+# but it is the key evidence for whether a dsh version appended rows of its own
+PATCH_LEN="$(docker exec "$CID" sh -c "yq '. | length' '$PATCH_PATH'" 2>/dev/null || echo '?')"
+echo "    条目数 $PATCH_LEN(connection 1 条,trustedHosts=[$CONN_HOSTS])"
+# 连内容一起留证:条目数只说明「有没有多余条目」,内容才说明「多的是什么」
+# (dsh 追加的插件启停记录等);1 行紧凑 JSON,不构成日志噪音
+#
+# Keep the content as evidence too: the count only says whether extra rows exist; the content
+# says which they are (plugin enable/disable records dsh appends). One compact JSON line.
+echo "    patch 全文:$(docker exec "$CID" sh -c "yq -c '.' '$PATCH_PATH'" 2>/dev/null || echo '?')"
 
 echo "==> 冒烟测试全部通过 ✓"