Ver código fonte

【修复,构建】修复首启日志属主导致的 token 提取失败

entrypoint 以 root 预创建 web-server.log 后未改属主,supervisord 中 dsh 以 node 运行 tee 追加时 EACCES,启动日志(含 ?token= URL)写不进文件,后台 tail 抓不到 token,冒烟测试 60s 超时。touch 后 chown node:node 修正。

冒烟脚本 SMOKE_HOME 由 mktemp 默认 0700,容器首启 chown 到 node(uid 1000) 后权限位不变,runner(uid 1001) 无法 traverse,即使 web-launch-url.txt 已生成也读不到。改为 chmod 755。

关联 #4
xidongbot 2 meses atrás
pai
commit
8a4939a85a
2 arquivos alterados com 24 adições e 1 exclusões
  1. 13 1
      entrypoint.sh
  2. 11 0
      scripts/smoke-test.sh

+ 13 - 1
entrypoint.sh

@@ -199,7 +199,19 @@ fi
 # 0.1.1-rc.2 doesn't print this URL, so on older dsh the file stays empty — harmless.
 WEB_LOG="$DHS_HOME/web-server.log"
 WEB_URL_FILE="$DHS_HOME/web-launch-url.txt"
-touch "$WEB_LOG"  # 让 tail -F 立即可订阅(dsh 启动后追加)
+# 预创建必须让 node 可写:entrypoint 以 root 运行,裸 touch 会留下 root:root 0644,
+# supervisord 中 dsh 以 user=node 执行 `tee -a` 追加时 EACCES,启动日志(含 ?token= URL)
+# 永远写不进文件,后台 tail 也就抓不到 token。故创建后立即把属主交给 node。
+# 仅首启会触发:文件已存在且属主正确时 touch 不改属主,二次启动天然正常。
+#
+# Pre-creation must leave the file writable by node: the entrypoint runs as root, so a bare
+# touch leaves root:root 0644 and dsh's `tee -a` under user=node fails with EACCES — the
+# startup log (including the ?token= URL) never reaches the file, so the background tail
+# cannot extract the token. Hand ownership to node right after creation.
+# First run only: when the file already exists with the right owner, touch keeps it,
+# so subsequent starts are fine.
+touch "$WEB_LOG"
+chown node:node "$WEB_LOG"
 (
   # 在子 shell 中等 + 抓 + 写 + 退出;不影响 entrypoint 主体
   #

+ 11 - 0
scripts/smoke-test.sh

@@ -70,6 +70,17 @@ echo "==> 启动容器冒烟"
 SMOKE_PARENT="${RUNNER_TEMP:-${TMPDIR:-$HOME}}"
 mkdir -p "$SMOKE_PARENT"
 SMOKE_HOME="$(mktemp -d -p "$SMOKE_PARENT" smoke-XXXXXX)"
+# mktemp 默认 0700。容器首启会把 bind mount 根 chown 成 node(uid 1000),但权限位不变:
+# runner(GitHub Actions 上是 uid 1001)便无法 traverse,即使 web-launch-url.txt 已生成
+# 也读不到(表现为 60s 超时 + `tail: Permission denied`)。放宽目录到 755 让 runner 能进入,
+# 文件本身仍是 0644(只读)。本地跑时 runner uid 恰好也是 1000,不触发,故 CI 才暴露。
+#
+# mktemp defaults to 0700. The container's first-run chowns the bind-mount root to
+# node (uid 1000) without changing mode bits, so the runner (uid 1001 on GitHub Actions)
+# cannot traverse it and cannot read web-launch-url.txt even once it exists (symptom:
+# 60 s timeout + `tail: Permission denied`). Loosen the directory to 755 so the runner
+# can enter; files stay 0644 (read-only). Local runs use uid 1000, so only CI exposes this.
+chmod 755 "$SMOKE_HOME"
 mkdir -p "$SMOKE_HOME/.x-cmd.root/bin"
 printf '#!/bin/sh\nexit 0\n' > "$SMOKE_HOME/.x-cmd.root/bin/x"
 docker run -d --name "$CID" \