Repository navigation
fix(sandbox): Linux bwrap 稳健性:仅凭证隔离补 /dev、优先系统 bwrap、软链基线目录、namespace 诊断 - #2543
Merged
Merged
Conversation
… 报错诊断 - 仅凭证隔离加 `--dev /dev`,预检真实读写 /dev/null、/dev/urandom - 新增 core/system-bwrap:所有沙盒形态优先 /usr/bin/bwrap、/bin/bwrap, 只找到 PATH 上的 bwrap 时警告(识别 Codex 定制版时点名),不拒绝启动 - 基线目录是软链时在沙盒内重建软链并 bind 真实路径 - 识别 Can't mount proc / 不能建 user namespace,启动失败与崩溃提示附说明和文档链接;不改降级策略 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 29, 2026 18:49
Comment on lines
+226
to
+230
| const runtime = spawnSync(launch.bin, launch.args, { | ||
| stdio: ['ignore', 'ignore', 'pipe'], | ||
| encoding: 'utf8', | ||
| timeout: 5_000, | ||
| }); |
| cliArgs: ['-c', `printf x >/dev/null && head -c 8 /dev/urandom | wc -c && ls ${hidden} | wc -l && { cat ${hiddenFile} 2>/dev/null || echo masked; }`], | ||
| }); | ||
| expect(spawn).not.toBeNull(); | ||
| const r = spawnSync(spawn!.bin, spawn!.args, { encoding: 'utf8', timeout: 10_000 }); |
| cliArgs: ['-c', `cat ${lexicalOpt}/tool/f; readlink ${lexicalOpt}; cat ${lexicalOpt}/secret/key 2>/dev/null || echo denied`], | ||
| }); | ||
| expect(plan).not.toBeNull(); | ||
| const r = spawnSync(plan!.bin, plan!.args, { encoding: 'utf8', timeout: 10_000 }); |
…e 标注 Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2534 的 hostResolverBindArgs 判 operator deny 时读的是 relocate 前的 opts.policy.rules,而同函数编译挂载用的是 relocateSymlinkedBaselineRules 之后的 policy。统一成编译用哪套规则就按哪套判定,消除两份规则源。 当前可达策略形状下判定结果不变(用户 deny 由 worker 提前 canonical 化, linux 基线软链只涉及 /opt、/etc 等,/run 是编译器原语不在规则里),纯 一致性修正;sandbox-resolver-bind 真机用例(含两条 deny)双引擎全绿。 Co-Authored-By: Claude Code <[email protected]>
把上一提交的单判据(只看 relocate 后的 policy.rules)升级为 resolverPathDenied(pre, compiled):任一规则集判定 deny 即抑制 host resolver 文件的重曝。基线目录本身是软链(/etc → /data00/etc)且策略里 带未 canonical 化的词汇形 deny 时,只看编译规则会把操作者拒绝的 resolver 文件重新 bind 回来;生产中 worker 的 resolveDeny 已对所有用户 deny 做 realpath,两套规则当前一致,并集是纵深防御。 新增 resolverPathDenied 纯函数与 3 条单测(词汇形 deny 被 relocate 改名 后仍抑制、两边都只 allow 时不抑制、canonical deny 抑制);删掉并集任一 分支在 vitest 与 bun:test 双引擎都咬红,sandbox-resolver-bind 18/18。 Co-Authored-By: Claude Code <[email protected]>
Owner
Author
|
自动评审的初步提示(最终以维护者审阅为准):#2537(沙盒文档大改,已合入 master 9f57f7e)与本 PR 的文档改动在
另:本 PR 含 |
This was referenced Oct 30, 2026
added 5 commits
October 30, 2026 20:06
worker.ts 唯一冲突:lastSpawnOuterBwrapActive 之后同位置,本 PR 新增 lastSpawnLinuxBwrap/sandboxNamespaceDiagnosis,#2548 新增 sandboxWrapperAwaitingFirstPrompt,两段独立声明都保留。语义叠加正交: claude_exit 出口先由 #2548 把 wrapperSandboxExitHint 拼入 logTail,本 PR 再对该 logTail 做 namespace 诊断,hint 文本不含 bwrap 报错串、不触发或 遮蔽识别正则;sendFatal 走 rawMessage 与 wrapper 无关。sandbox.ts 的 wrapper CLI 名别名(shimBin)与本 PR relocate(挂载规则重排)机制独立。
This was referenced Oct 30, 2026
|
@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。 这次运行覆盖 54b28df…887309883(7 个提交),同批合入的还有 #2622 #2582 #2620 #2607 #2618 #2625,失败不一定由本 PR 引起。
|
This was referenced Oct 30, 2026
|
🚀 Released in v3.56.0 |
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.
改了什么
看板 #86(沙盒任务③ Linux bwrap 稳健性)的第 1–4 点。起因是用户反馈的三种现象:BOE devbox / Debian 10 / 内核 5.4 上 codex-app 绑定平台后起不来;装了 Codex 之后所有沙盒会话一启动就退出(tmux
pipe-pane can't find pane);/opt是软链的机器上报bwrap: Can't bind mount /oldroot/data00 on /newroot/opt。buildCredentialOnlySandboxArgs,src/adapters/backend/sandbox.ts)--bind / /和--proc /proc,/带进来的宿主 /dev 是 nodev 挂载,打开/dev/null、/dev/urandom都报 EACCES。在 isolate-run 里用printf x >/dev/null复现过。--dev /dev。这是 bwrap 自建的最小 /dev,不放开宿主设备。凭证文件遮罩的 bind 源仍是宿主 /dev/null,读出来依旧不可读。probeBubblewrapCredentialMasks原来只跑/bin/true,现在用同一形状的参数真写一次/dev/null、真读一次/dev/urandom。src/core/system-bwrap.ts)/usr/bin/bwrap、/bin/bwrap的顺序找;两者都没有时才退回 PATH 上的 bwrap,并打一次警告(维护者定:只警告、不拒绝)。PATH 上那份--version里带 Codex 字样时,警告会点名「Codex 自带的定制版」。prepareDirectSandbox的依赖检查和两处启动)、仅凭证隔离的预检与启动、pid namespace 探针、scratch(依赖检查和两处启动)、网络沙盒的--help能力探测。resolveSystemBwrap改为复用systemBwrapPath(),行为不变:仍然只认系统 bwrap,找不到就拒绝。它是无人值守运行的,没人能看到警告。relocateSymlinkedBaselineRules,src/adapters/cli/fs-policy.ts)/opt、/usr、/etc、~/.cache等)的路径本身是软链、且父目录已是真实路径时,处理方式和 usrmerge 的/bin一样:在沙盒里--symlink重建这个软链,再把真实路径 ro bind 进去。classifyBwrapNamespaceFailure识别两类报错:Can't mount proc on /newroot/proc(PID),以及No permissions to creat(e|ing) new namespace/setting up uid map/Creating new namespace failed(user)。error)或 CLI 非零退出(claude_exit)时,会带上sandboxNamespace。判断时先看终端输出或报错文本;tmux pane 秒退时没有输出,就退回缓存的宿主探针结果。sandbox.md中英文各加一节「Linux 运行环境要求」(锚点#linux-namespace)。这次不做:普通部署能不能去掉 pid namespace 降级运行,涉及同机其它 bot worker 进程环境里的明文 secret,属于安全取舍。降级仍只在
BOTMUX_CORE_ONLY=1(coreOnlyPidNamespaceDegrade)时发生。core-only 已经降级过的 PID 失败不会再提示。第 5 点(软链 HOME 下 Codex App 的 bootstrap 路径)不在本 PR,原因已在任务群里说明,等维护者定:用真实 worker 跑了「软链 HOME + codex-app + 仅凭证隔离」的端到端探针,pty 和 tmux 都能认证通过并完成一轮,问题没有复现。
影响面
lastSpawnLinuxBwrap为假时,诊断函数直接返回。--dev /dev。这是本 PR 修的 bug,原来连 /dev/null 都打不开。预检比原来严格一点(要求设备能读写):原来能「通过预检但会话起不来」的机器,现在会在预检阶段 fail-closed,并给出原因。bwrap换成了绝对路径。只在 PATH 上有 bwrap 的机器,行为不变,多一条警告日志。基线目录不是软链时,argv 完全不变。/data00、/opt -> /data00/opt),按既有的「最深前缀生效」,/data00/opt仍然可读。这和不涉及软链时 canonical 化的~/.cache落在被 deny 的盘下是同一语义,不是本 PR 新增的行为。--dev、relocateSymlinkedBaselineRules只用在 Linux bwrap 编译路径上。core/worker-pool.ts(两处提示文案追加)、types.ts(claude_exit和error各多一个可选字段,老 worker 不带这个字段,等于原行为)、i18n(新增一条文案)。验证
所有真沙盒用例都在
isolate-run --timeout里跑,没有在宿主上直接起沙盒。本机 isolate-run 自己就是嵌套的 PID namespace,所以分两种环境跑:一种在 isolate-run 里额外挂一个完整的 procfs,让内层 bwrap 能--unshare-pid --proc,覆盖「能起来」的分支;另一种不挂,原样跑,正好复现用户的Can't mount proc,覆盖诊断分支。变异证据:每次只撤掉一处守卫,跑
test/linux-bwrap-robustness.test.ts、test/crash-loop-diagnostic.test.ts,全部变红:--dev /dev/bin/truebwrapCan't mount proc没能验证的:
/optbind 失败的后半句报错没拿到。本机 bwrap 0.8.0 用「/opt指向另一块挂载」两种布局都复现不了原报错,所以「改完能起」只在本机布局上验证过(链接正确、真实路径可读、deny 生效)。没有在 Debian 10 自带的 bwrap 0.3.x 上实测。--version输出没有拿到实物,识别规则按「输出里含 codex(不分大小写)」写。🤖 Generated with Claude Code