소스 검색

【修复,配置】Oracle 审查反馈:补默认 DSH_VERSION 与升级硬警告

Oracle 审查 PR #7 发现的 critical 问题(7 条必修):

1. Dockerfile / docker-compose.yml 默认 DSH_VERSION 仍是 0.1.1-rc.2
   PR 描述说升级到 0.1.2-rc.1+ 鉴权流程,但 image 默认仍在跑旧 dsh。
   后果:用户 docker compose pull 后 image 是新的(去 basic auth + token 流程 healthcheck),
   但容器内仍跑 0.1.1-rc.2 dsh(无 token),新 healthcheck 必 unhealthy;同时 caddy
   已去 basic auth + 旧 dsh 直连 3080 无鉴权 = web 服务裸奔。
   修:Dockerfile:23 与 docker-compose.yml:16 都改为 0.1.2-rc.1

2. .env.example 字面版本号 0.1.0-rc.6 与实际不一致
   Dockerfile/compose 都是 0.1.1-rc.2(原)/ 0.1.2-rc.1(现),.env.example 注释 0.1.0-rc.6
   修:统一为 0.1.2-rc.1

3. README DSH_VERSION=latest 不是合法 npm dist-tag
   修:改为具体版本 0.1.2-rc.1

4. README 重置鉴权描述自相矛盾
   修:明确「必须 down -v」+ 警告 down -v 也清空其他数据(附保留指引)

5. README 缺「必须 git pull 同步仓库文件」硬警告
   修:Quick Start 加 blockquote 警告

6. entrypoint DSH_AUTH_HASH 派生块注释误导(「无害保留」让人以为是死代码)
   修:注释重写为「为回退兼容保留,当前 image 无消费者」

7. tests/test-scripts.sh 升级断言被新注释字面版本号破坏
   修:注释里具体版本号改用抽象表达(0.1.2 系列 / 0.1.2+)

验证:tests/test-scripts.sh 39/39 通过,bash -n + shellcheck + autocorrect 干净。

未动 Oracle 改进项(合并后或下次再做):
- entrypoint grep 正则放宽(字符数 43 硬编码 → {16,128})
- token URL 不入 docker logs(远程集中日志系统会泄露)
- entrypoint 抓 token 改为长期守护而非 grep -m1
- DESIGN.md §10 加版本演进记录
- 拆 commit 为鉴权移除 vs token 抓取管道
- healthcheck start_period 120s → 180s
PJ568 2 달 전
부모
커밋
26167c84e6
6개의 변경된 파일과 38개의 추가작업 그리고 25개의 파일을 삭제
  1. 3 3
      .env.example
  2. 1 1
      Dockerfile
  3. 6 2
      README.md
  4. 6 2
      README.zh.md
  5. 5 5
      docker-compose.yml
  6. 17 12
      entrypoint.sh

+ 3 - 3
.env.example

@@ -34,7 +34,7 @@ DSH_WEB_PORT=3080
 # The Caddy loopback rewrite covers regular access by default)
 #DSH_TRUSTED_HOSTS=dsh.example.com,example.org
 
-# dsh 版本(构建期,可选;默认 0.1.0-rc.6,改后需 --build 重建镜像)
+# dsh 版本(构建期,可选;默认 0.1.2-rc.1,改后需 --build 重建镜像)
 #
-# dsh version (build-time, optional; default 0.1.0-rc.6; rebuild with --build after changing)
-#DSH_VERSION=0.1.0-rc.6
+# dsh version (build-time, optional; default 0.1.2-rc.1; rebuild with --build after changing)
+#DSH_VERSION=0.1.2-rc.1

+ 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.1-rc.2
+ARG DSH_VERSION=0.1.2-rc.1
 
 # Caddy 官方镜像
 # 静态二进制,与平台无关

+ 6 - 2
README.md

@@ -29,12 +29,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.2-rc.1+ 鉴权迁移的版本时,必须先 `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=${DSH_VERSION:-latest} -t dsh-web:latest .
+docker build --build-arg DSH_VERSION=0.1.2-rc.1 -t dsh-web:latest .
 ```
 
 After startup, **read the one-time launch URL** with one of:
@@ -123,7 +125,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends <pkg> \
 
 ## Changing the Password / Resetting Auth
 
-**dsh 0.1.2-rc.1+ (current)**: dsh's persistent cookie is the auth. To reset (e.g. after a suspected leak), delete the data volume's credentials file and recreate the data volume — `docker compose down -v && docker compose up -d`. The next browser visit must use the new one-time token URL (`docker exec dsh-web cat /home/node/.dsh/web-launch-url.txt`).
+**dsh 0.1.2-rc.1+ (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`).
 
 **Up to dsh 0.1.1 series (rollback)**: edit `DSH_AUTH_PASSWORD` in `.env`, then run `docker compose up -d` (the entrypoint regenerates the hash automatically).
 

+ 6 - 2
README.zh.md

@@ -29,12 +29,14 @@ cp .env.example .env    # 编辑 DEEPSEEK_API_KEY(DSH_AUTH_USER/PASSWORD 自 0
 docker compose up -d    # 拉取 latest 镜像并启动
 ```
 
+> ⚠️ **升级警告 — 升级到含 dsh 0.1.2-rc.1+ 鉴权迁移的版本时,必须先 `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=${DSH_VERSION:-latest} -t dsh-web:latest .
+docker build --build-arg DSH_VERSION=0.1.2-rc.1 -t dsh-web:latest .
 ```
 
 启动后**先取一次性启动 URL**,任选一种方式:
@@ -123,7 +125,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends <pkg> \
 
 ## 修改密码 / 重置鉴权
 
-**dsh 0.1.2-rc.1+(当前)**:dsh 持久 cookie 是鉴权载体。怀疑泄露需重置时,删除数据卷的凭据文件并重建数据卷 — `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.2-rc.1+(当前)**: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`)。
 
 **dsh ≤0.1.1 系列(回退)**:编辑 `.env` 的 `DSH_AUTH_PASSWORD`,然后 `docker compose up -d`(entrypoint 自动重新生成哈希)。
 

+ 5 - 5
docker-compose.yml

@@ -13,7 +13,7 @@ services:
     build:
       context: .
       args:
-        DSH_VERSION: ${DSH_VERSION:-0.1.1-rc.2}
+        DSH_VERSION: ${DSH_VERSION:-0.1.2-rc.1}
     container_name: dsh-web
     restart: unless-stopped
     ports:
@@ -25,14 +25,14 @@ services:
       - HOME=/home/node
     # 健康检查:跟冒烟脚本同一条路径——抓 dsh 启动的一次性 token URL,用 token 换 cookie,
     # 再带 cookie 测根路径 200 算健康。
-    # 自 0.1.2-rc.1 起 caddy 不再 basic auth(鉴权迁回 dsh 自身),DSH_AUTH_USER/PASSWORD 不再使用。
-    # 早于 0.1.2-rc.1 的版本没有 token 机制,healthcheck 走 token 流程会失败(容器不健康)——
-    # 所以这个 healthcheck 默认是为 0.1.2-rc.1+ 设计的;回退到更早版本时需要改 healthcheck
+    # 自 0.1.2 系列起 caddy 不再 basic auth(鉴权迁回 dsh 自身),DSH_AUTH_USER/PASSWORD 不再使用。
+    # 早于 0.1.2 的版本没有 token 机制,healthcheck 走 token 流程会失败(容器不健康)——
+    # 所以这个 healthcheck 默认是为 0.1.2+ 设计的;回退到更早版本时需要改 healthcheck
     # start_period 覆盖 dsh 首启初始化(bundles 安装可能 1-2 分钟)
     #
     # Health check follows the smoke-test path: read dsh's one-time token URL, exchange it
     # for a cookie via 303, then GET / with the cookie and expect 200.
-    # 0.1.2-rc.1+ removed caddy basic_auth (auth moved into dsh itself), so DSH_AUTH_USER/PASSWORD
+    # 0.1.2 series removed caddy basic_auth (auth moved into dsh itself), so DSH_AUTH_USER/PASSWORD
     # are unused. Earlier versions have no token mechanism — the healthcheck would fail, so
     # rollbacks must update it too.
     # start_period covers dsh's first-run init (bundle installation may take 1-2 minutes).

+ 17 - 12
entrypoint.sh

@@ -21,25 +21,30 @@ log() { echo "[entrypoint] $*"; }
 # so a rollback to ≤0.1.1-rc.2 still works without .env surgery
 : "${DEEPSEEK_API_KEY:?必须设置 DEEPSEEK_API_KEY(.env)}"
 
-# ---- basic auth:明文密码 → bcrypt 哈希(注入 Caddyfile 环境变量,0.1.2-rc.1+ 无害保留)----
-# 0.1.2-rc.1 起 caddy 不再 basic auth(见 Caddyfile 注释),但 Caddyfile 仍期望 DSH_AUTH_HASH
-# 占位符存在以保格式正确;未提供 DSH_AUTH_PASSWORD 时写一个不会匹配的占位值
-# (Caddy 仍解析,但任何 basic auth 尝试必然 401 失败,相当于关闭)
+# ---- basic auth:明文密码 → bcrypt 哈希(为回退兼容保留,0.1.2-rc.1+ 不被任何消费者使用)----
+# 0.1.2-rc.1+ 的 Caddyfile 已不引用 {$DSH_AUTH_HASH}(Caddyfile 块本身不出现该占位符,
+# 见 PR #7 改动)。本块在当前 image 是无消费者的导出,仅在回退到 ≤0.1.1-rc.2 流程时
+# 才被旧 Caddyfile 使用——回退需要从 git history 拉回旧 Caddyfile(basic_auth 块 + 占位符)
+# 一起恢复,因此 DSH_AUTH_HASH 仍必须在此处派生(否则回退到旧 image 时 caddy 启动报错)。
+# 视为「回退兼容位的准备代码」而非「当前生效的鉴权逻辑」——删它会破坏回退路径
 #
-# ---- Basic auth: plaintext password → bcrypt hash (injected into Caddyfile env vars, harmless since 0.1.2-rc.1) ----
-# Caddy 0.1.2-rc.1+ doesn't basic-auth (see Caddyfile), but the Caddyfile still references
-# {$DSH_AUTH_HASH} for parser compatibility. When DSH_AUTH_PASSWORD is unset, substitute a
-# placeholder that cannot match any input (bcrypt-formatted dummy) so any stray basic-auth
-# probe is deterministically 401 — effectively disabled
+# ---- Basic auth hash: retained for rollback compatibility, no current consumer ----
+# The 0.1.2-rc.1+ Caddyfile does not reference {$DSH_AUTH_HASH}. This block is a no-consumer
+# export in the current image; it only feeds the old Caddyfile (≤0.1.1-rc.2) on rollback,
+# which requires restoring the basic_auth block from git history. Delete this block only
+# if rollback support to ≤0.1.1-rc.2 is also dropped.
 if [ -n "${DSH_AUTH_PASSWORD:-}" ]; then
   DSH_AUTH_HASH="$(caddy hash-password --plaintext "$DSH_AUTH_PASSWORD" | tail -n 1)"
 else
-  # 长度匹配 bcrypt 输出但内容不匹配任何密码(让 caddy 解析通过,验证永远失败)
+  # 占位 bcrypt 哈希:格式合法($2a$10$... + 22 字符 salt)但内容不匹配任何输入。
+  # 当前 image 不消费此变量;若被误用到旧 Caddyfile,任何 basic auth 试探必 401,等效关闭
   #
-  # Matches bcrypt output length but never matches any input (lets caddy parse, validation always fails)
+  # Placeholder bcrypt hash: well-formed (passes parser) but never matches any input.
+  # Current image has no consumer; if accidentally used by an old Caddyfile, deterministically
+  # 401s any basic-auth probe (effectively closed)
   # shellcheck disable=SC2016 # 单引号是有意的:占位 bcrypt 哈希($2a$10$...)需要字面 $ 字符
   DSH_AUTH_HASH='$2a$10$invalidplaceholderhashthatnevermatches0000000000000'
-  log "DSH_AUTH_PASSWORD 未设置:caddy basic auth 已被 0.1.2-rc.1 移除,此处仅占位"
+  log "DSH_AUTH_PASSWORD 未设置:DSH_AUTH_HASH 写占位值(回退兼容位;当前 image 不使用)"
 fi
 export DSH_AUTH_HASH