fix(sandbox): 将 outbox 移出 home overlay#403
Open
DeepColds wants to merge 6 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
<dataDir>/sandboxes/<sid>/outbox移到/var/tmp/botmux-sbx-<uid>/<sid>/outbox。prepareSandbox()中BOTMUX_SEND_RELAY和 bwrap outbox bind 都使用新路径。/var/tmp下的 sandbox root 改为按 Unix uid 隔离,避免共享 Linux 机器上第一个用户创建全局0700目录后阻塞其他用户。/var/tmp/botmux-sbx-<uid>、<sid>、outbox创建/reattach 时显式收紧到0700;relay 内容、附件、视频、视频封面、请求、响应文件显式写成0600。ensurePrivateDir()加固为 fail-closed:拒绝 symlink / 非目录,校验 owner 是当前 daemon uid,再收紧并检查 mode。.req.jsonrelay 请求文件改为安全读取:O_NOFOLLOW | O_NONBLOCK打开,fstat().isFile()校验 regular file,64KB 上限读取后再JSON.parse,避免 FIFO/symlink/special file/超大文件卡住 worker 或越界读取。videos/videoCovers,并保持 master 的--videos/--video-covers语义,同时对这些 outbox 文件应用0600权限硬化。attachSandboxOutbox()优先 reattach 新 outbox,并兼容 fallback 到旧的/var/tmp/botmux-sbx/<sid>/outbox和<dataDir>/sandboxes/<sid>/outbox,避免升级时已有 sandbox session 失联。sandboxedClaudeDataDir()对升级前已在运行的 persistent sandbox 增加 legacy HOME upper fallback:当旧/var/tmp/botmux-sbx/<sid>/home-upper存在且新路径不存在时,Claude bridge 继续指向旧 upper。/var/tmp/botmux-sbx/<sid>residue 残留。docs/file-sandbox.md:同步 overlay 模型、/var/tmp/botmux-sbx-<uid>/<sid>/outbox、权限策略、legacy fallback 规则,并修正凭据说明:relay 不注入发送凭据;磁盘上的 botmux 配置/密钥如需隐藏需配置sandboxHidePaths/ read isolation。.req.jsonFIFO/symlink/超限拒绝、watcher 对非法 request 写 rejected res、BOTMUX_SEND_RELAY/bwrap bind 路径、relay payload 文件 mode,以及视频/视频封面 relay 校验。为什么
在部分 DevBox 上,sandbox 当前布局会先把整个 HOME 做 overlay 后挂回 HOME,再把 outbox bind 到 HOME 内部:
当
<dataDir>位于 HOME 下时,这会形成 “HOME overlay 内部再 bind 子目录” 的嵌套挂载组合。实测该组合会导致bwrap卡在挂载阶段,表现为进程树只有bwrap -> bwrap,没有真正 exec 到 Traex/node;将最终命令替换成/bin/true也仍然超时。把 outbox 放到
/var/tmp/botmux-sbx-<uid>/<sid>/outbox后,它不再位于 HOME overlay 内部,可以避免该嵌套 bind 卡死。由于/var/tmp是共享多用户路径,本 PR 同时做多层处理:root 按 uid 拆分,避免多用户争抢一个全局0700目录;每个用户自己的 root/session/outbox 继续收紧为0700,relay 文件为0600;对已存在目录校验 symlink 和 owner;对 outbox 内的 request/content/attachment 都按 sandbox 不可信输入做 no-follow、non-blocking、regular-file 校验。影响面
<dataDir>/sandboxes/<sid>/proj-upper。/var/tmp下的 upper/work,但路径从全局/var/tmp/botmux-sbx/<sid>/home-upper调整为 per-user/var/tmp/botmux-sbx-<uid>/<sid>/home-upper。botmux send仍只写 outbox,宿主 watcher 代发;relay 链路不通过 env/argv/IPC 给沙盒注入发送凭据。--videos/--video-covers),relay 请求中同时保留attachments、videos、videoCovers、flags,且所有 relay 文件均为0600。sessionRoot、新 per-uid vartmp sid 目录和旧全局 vartmp sid 目录。测试验证