Skip to content

test(tui): verify the Landlock layer of pi-sandbox (plan 0.9) - #58

Merged
zy1233 merged 2 commits into
mainfrom
test/tui-landlock-verification
Oct 31, 2026
Merged

zy1233 merged 2 commits into
mainfrom
test/tui-landlock-verification

Conversation

@zy1233

@zy1233 zy1233 commented Oct 30, 2026

Copy link
Copy Markdown
Owner

结论

计划 0.9 里「沙箱的 Landlock 层(内核 ≥ 5.13)」在这台云 VM 上验证通过:Landlock 真的限制了文件访问。没有发现产品代码缺陷,没有改产品代码。

计划与代码有三处不一致(以代码为准,已写进计划):

  1. 计划说两个端到端文件「在内核不支持 Landlock 时 return」。对 deny_paths_e2e 不完整:它在 Linux 上还要 bwrap。这台 VM 有 Landlock 但没有 bwrap:不设 SANDBOX_E2E_REQUIRE_ENFORCEMENT 时 101 个测试「通过」(8 个 deny_paths_e2e 用例各 3 到 7 ms,空转);设了以后 8 个用例 panic:bwrap unavailable。
  2. deny_paths_e2e 在 Linux 上测的是 bwrap,不是 Landlock。变异检查:把 Sandbox::apply(&caps) 换成空操作,它的 8 个用例仍全部通过。原来只有 read_write_trailing_glob_e2e 一个用例真的测 Landlock。
  3. pi-sandbox 不在 scripts/tui_baseline.toml 与 tui-ci.yml 里,CI 从不跑它。

证据(内核 6.12.94+,Ubuntu 24.04.5,x86_64)

$ cat /sys/kernel/security/lsm
capability,landlock,selinux,bpf
$ dmesg | grep -i landlock
landlock: Up and running.
Landlock ABI (landlock_create_ruleset VERSION) = 6
nono support_info: Landlock available (Landlock V6, … TCP network filtering, …)
运行 结果
sandbox_smoke_test 的 workspace / read-only / strict 都 kernel-enforced;写 ~/ 被拒(EACCES);read-only 写 CWD 被拒;strict 读 ~/ 被拒
新测试 landlock_enforcement_e2e,REQUIRE=1 4 / 4 通过(3 个 profile 各 19 到 21 次探测,父进程不加沙箱的对照全部成功,子进程继承)
新测试 + 变异(Sandbox::apply 空操作) 3 个 profile 用例全部失败(每个 10 到 15 项探测失败)
已有 e2e,装了 bwrap,REQUIRE=1 9 / 9 通过
整个 pi-sandbox,REQUIRE=1 105 通过,3 个跳过(#[ignore] 的子进程入口)

完整输出:/opt/cursor/artifacts/landlock-verification-evidence.txt(随本次运行上传)。

命令:

cd tui; unset PI_HOME GROK_HOME PI_AGENT_COMMAND PI_PYTHON GROK_SANDBOX; export CARGO_BUILD_JOBS=2
SANDBOX_E2E_REQUIRE_ENFORCEMENT=1 cargo nextest run -p pi-sandbox --no-fail-fast

改了什么

  • 新增 tui/crates/codegen/pi-sandbox/tests/landlock_enforcement_e2e.rs(只在 Linux 上编译;内核不支持时跳过,设 SANDBOX_E2E_REQUIRE_ENFORCEMENT=1 则失败;不需要 bwrap)。
  • 计划 docs/PLAN/PLAN-RUST-AGENT-RUNTIME-REMOVAL.md、执行记录 §10.27(r24)与 docs/baselines/tui.md:用实测结论替换「未验证」。

副作用检查

已有测试留下东西(这一轮没有改):deny_paths_e2e 在 /tmp 留下 grok-sandbox-e2e-exact-grok-* 目录,并写真实的 ~/.pi-python/(hooks/、hooks-paths、sandbox-blocked.*);read_write_trailing_glob_e2e 留下空目录 ~/.cache/grok-starstar-e2e。新测试不留任何东西。

没验证的

  • 内核 < 5.13 或没启用 Landlock 时的行为(这台 VM 有 Landlock);新测试的跳过分支没在这样的内核上跑过。r8 在 WSL2(5.10)测过降级。
  • 内核 5.13 到 6.11(ABI 1 到 5)。
  • zypi --sandbox <profile> 真机运行(没有构建 zypi);bwrap 加 Landlock 叠加时 Landlock 一半的断言。
  • restrict_network(代码里是 seccomp,不是 Landlock TCP)。
  • CI:没有把 pi-sandbox 加进清单或 workflow;GitHub 的 ubuntu-24.04 runner 是否有 Landlock、bwrap、用户命名空间,没有查。
  • macOS(Seatbelt)、Windows、aarch64。这里没有 Windows / WSL,所以没有跑 Python 的 Windows/WSL 对照;只改了 Rust 测试与文档,ruff check . 与 ruff format --check . 通过。

这台 VM 一开始没有 bwrap,用 apt-get install bubblewrap(0.9.0)装上后才跑已有的 deny_paths_e2e。

Open in Web Open in Cursor 

cursoragent and others added 2 commits October 30, 2026 17:13
Add landlock_enforcement_e2e (workspace, read-only, strict profiles; parent
control; child inheritance) and record the 0.9 Landlock result and three
plan/code mismatches in the plan and execution log.

Co-authored-by: z123385708 <[email protected]>
@zy1233

zy1233 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

Stack #66, bottom to top: #58, #59, #56, #57, #60, #61, #62, #63, #64, #65. One atomic squash merge (gh stack merge).

This PR is position 1 of 10. The branch is not changed (head 02e1f69). The other PRs of the stack were rebased above #59. This PR keeps r24 / section 10.27 and #59 keeps r25 / section 10.28; PR #56 was renumbered from r24 to r26 so that no round number is used twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants