Fix codex-host profile: capability allow + netlink (bwrap needs both)
Two bwrap failures found by live host tasks, both in the AppArmor profile (not in codex or the worker): 1. deny capability sys_admin (etc.) breaks bwrap at userns creation: codex-host with the deny list failed, the same profile with capability, allowed it. codexsvc holds no host capabilities, so the allow only covers fake-root caps inside bwrap's own user namespace (scoped, harmless to the host); network/ptrace/file denies still hold independently. 2. bwrap brings up loopback in its new net namespace via a NETLINK_ROUTE socket: without network netlink raw, codex workspace-write fails with 'Failed to bind NETLINK_ROUTE socket' and no tool runs. And a bare 'deny network raw' overrides the netlink allow (deny wins over allow), so the raw deny must name inet/inet6 explicitly (verified by an isolated netlink bind test under each profile variant). README correction in the same change: codex workspace-write does NOT isolate /tmp -- an agent /tmp write lands on host /tmp (verified). The verified boundary is: own worktree writable, everything else read-only, /tmp shared.
This commit is contained in:
1 parent
bfe3521ef7
commit
4a78ca1e95
3 files changed
+50
-26
No files matched your search
+10
-4
@@ -514,16 +514,22 @@ interrupted 且终态任务 cancel 返回 400、心跳后 sweep 不扫刚心跳
|
||||
`host-config-host.json`(sandbox workspace-write,state 独立
|
||||
为 work/host-state-host.json),以 `aa-exec -p codex-host`
|
||||
运行(见 `deploy/apparmor/codex-host`:docker-codex 基础 +
|
||||
userns/mount/pivot_root,仍禁 raw/ptrace/危险 capability),
|
||||
userns/mount/pivot_root,仍禁 raw 网络与 ptrace;capability
|
||||
必须放行——codexsvc 本身无宿主 capability,放行的只是 bwrap
|
||||
的 userns 内假 root capability,实测 deny sys_admin 会让
|
||||
bwrap 在 userns 创建处失败),
|
||||
并带 `HTTP(S)_PROXY=http://127.0.0.1:8888` 让 relay/git 出口
|
||||
同样走 Tinyproxy 白名单。路由靠任务的 executor 字段
|
||||
(POST /tasks 已支持 local/docker/cloud):宿主 worker 必须
|
||||
开 `--claim-executor-only`,只认领 executor='local' 的任务,
|
||||
绝不抢 executor 为 NULL 的任务(否则会把本该进 Docker 的
|
||||
任务拉到宿主上跑,丢了 Docker 外层)。宿主任务放弃 Docker
|
||||
外层(无容器、无租户挂载/网络隔离),换来的是 bwrap 内层
|
||||
(agent 只能写自己 worktree,/tmp 是隔离的 tmpfs,写不到
|
||||
宿主 /tmp;其它任务 worktree 与宿主文件同样不可见)。
|
||||
外层(无容器、无租户挂载/网络隔离),换来的是 bwrap 内层。
|
||||
实测过的沙箱边界(诚实版):agent 只能写自己 worktree,
|
||||
写宿主其它目录与其它任务 worktree 均被挡(报文件系统只读);
|
||||
但 /tmp 不隔离——agent 写 /tmp 会落到宿主 /tmp 上(codex
|
||||
的 workspace-write 不把 /tmp 做成隔离 tmpfs),所以 /tmp
|
||||
是任务间的共享区,不能当作隔离边界。
|
||||
- 网络白名单的诚实边界:docker run 默认 bridge 网络,本执行
|
||||
器不做 egress 白名单——真正的“只放行模型 API”需要宿主防火
|
||||
墙或代理规则,那是部署项,不是本轮代码假装做到的,不要宣称
|
||||
|
||||
@@ -93,6 +93,22 @@ class HostConfigProfileTestCase(unittest.TestCase):
|
||||
self.assertIn("pivot_root,", text)
|
||||
self.assertNotIn("deny mount,", text)
|
||||
self.assertNotIn("deny umount,", text)
|
||||
# bwrap 还需要 userns 内的 capability(实测:deny
|
||||
# capability sys_admin 会让 bwrap 在 userns 创建处失败,
|
||||
# 而 capability, 允许则成功;codexsvc 本身无宿主
|
||||
# capability,所以这里允许的只是 userns 内的假 root
|
||||
# capability,不授予宿主特权)。
|
||||
self.assertIn("capability,", text)
|
||||
self.assertNotIn("deny capability sys_admin,", text)
|
||||
# bwrap 还需要 netlink(在新网络命名空间里拉起 loopback;
|
||||
# 缺了会报 Failed to bind NETLINK_ROUTE socket,且任何
|
||||
# 工具都跑不起来)。注意 AppArmor 里 deny 优先于 allow,
|
||||
# 所以 raw 的 deny 必须写明 inet/inet6,不能写裸的
|
||||
# deny network raw(那样会连 netlink raw 一起挡掉,
|
||||
# 已用隔离 netlink bind 实测验证)。
|
||||
self.assertIn("network netlink raw,", text)
|
||||
self.assertIn("deny network inet raw,", text)
|
||||
self.assertNotIn("deny network raw,", text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user