Repository navigation
#656 [security][tools] Bash と検証コマンドの書き込みを Linux の landlock で閉じ込める(1b) - #666
Merged
Kewton merged 3 commits intoOct 13, 2026
Merged
Conversation
Confine model Bash and verifier command writes on Linux with the landlock crate as stage 1b of the #502 write-confinement track. The ruleset and the allowed-location descriptors are opened in the parent; the child's pre_exec calls only prctl(PR_SET_NO_NEW_PRIVS) and landlock_restrict_self. ABI1 is required, ABI2/ABI3 are best-effort, and availability is probed once at run start via the ABI query and a child restrict_self. Make --sandbox a public flag and start the GUI delegate with --sandbox required. Add Linux integration tests that fail under CI when Landlock is unavailable and print the kernel release and ABI. 判断: ABI2/ABI3 欠如時に閉じない操作を bash_sandbox_status の既存 reason field に 記録するため、os_sandbox.rs に backend ノートを配線した(backend 選択の配線の範囲内の 最小追加。event の名前と schema は変えない)。 判断: Linux の依存キャッシュ場所(~/.cargo 等)は landlock.rs 内で解決し、 os_sandbox.rs の resolve_cache_paths は変えない。 判断: Landlock の利用可否は ABI 照会に加え、bounded_process 経由の子で landlock_restrict_self を 1 回試す(seccomp で拒否された場合も未適用として扱う)。 判断: ABI 照会結果→Available/Unavailable と理由、および limitation_note の ABI 分岐を syscall を呼ばない純粋関数 decide/limitation_for に切り出し、cfg(test) 単体試験で ABI0・Err・1・2・3・9 と理由に kernel と ABI が入ることを確かめる。 判断: auto で probe は Available でも landlock::wrap が実行時に失敗したとき、 installed の availability を Unavailable に降格して is_applied() を false にする (reconcile_workspace と同じ考え方)。required は従来どおり拒否。降格は Linux 専用。 判断: Linux の hardlink 試験は jsonl の symlink 経路ではなく、テスト tempdir 内の 「外」の inode への絶対パス link で ABI2 の refer を測る(ABI2 未満は記録して外す)。 判断: GUI delegate の --sandbox required の試験は gui feature の bin 単体試験として 追加(本 Issue の許可ファイルに tests/gui_server.rs が無いため)。 Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Close the cargo-mutants survivors that let a wrong ABI or a blank backend report slip through the Linux tests: - Query the kernel ABI independently with libc::syscall(SYS_landlock_create_ruleset, null, 0, VERSION) and pin landlock::detected_abi() to it, so a mutated detected_abi (for example a constant 1) fails; gate the hardlink test on the independent ABI too. - Add a truncate(2) test: with ABI >= 3, os.truncate of an outside inode must fail and leave the outside fixture unchanged; below ABI3 record the skip. - Add a run-start status test: on Linux, os_sandbox::install must report backend == "landlock" and applied == true, reason == None on ABI3+, and the unclosed operations named on an older ABI. 判断: 実装は変えない。試験だけを追加し、ABI は backend を経由せず独立に照会する。 判断: truncate 試験は jsonl ではなく os.truncate(truncate(2))で ABI3 を測り、 ABI3 未満は理由を出して外す。 判断: status の試験は install(実 backend)で probe を通し、ABI 3 以上は reason == None、 未満は reason に閉じない操作名を要求する。 Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Make the kernel and ABI visible in the PR CI log and stop a too-old ABI from silently skipping the ABI2/ABI3 closures: - Add a pure abi_gate(ci, abi, required_abi, kernel) decision (continue / skip / fail) and apply it to the hardlink (ABI2) and truncate (ABI3) tests: under CI a too-old ABI fails with the kernel and ABI in the message; locally it skips. A unit test covers ABI1 with/without CI and ABI3. - Append one line, issue502/656 landlock: kernel=<v> abi=<n>, to $GITHUB_STEP_SUMMARY once per process when that variable is set. Best effort: a write failure never fails the test, and only the kernel version and ABI number are written. 判断: 実装・CI・scripts は変えず、tests/issue502_os_sandbox_write.rs だけを直す。 判断: 判定(CI の有無・ABI・必要 ABI → 続ける/SKIP/失敗)は syscall を呼ばない abi_gate に切り出し、env を書き換えずに単体試験する。 判断: step summary への記録は std::sync::Once で 1 回だけ、失敗しても試験は落とさない。 Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
15 tasks
Kewton
deleted the
feature/issue-656-security-tools-bash-linux-landlock-1-b
branch
October 13, 2026 05:06
This was referenced Oct 13, 2026
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.
概要
#502 の第 1 段 b です。1a(#655)で作った隔離の葉モジュールに、Linux の backend として landlock を足し、Bash と検証コマンドの書き込みを閉じ込めます。あわせて、GUI の delegate を
--sandbox requiredで起動し、--sandboxを公開のフラグにします。Refs #656
変更(develop 比 11 ファイル、3 commit)
src/tools/os_sandbox/landlock.rs、新規の葉モジュール)landlock0.4(lock では 0.4.7)だけで、Linux だけの依存です。pre_execではprctl(PR_SET_NO_NEW_PRIVS)とlandlock_restrict_selfだけを呼び、確保・lock・ログをしません(コメントに明示)。bash_sandbox_statusの既存の reason に書きます。restrict_selfの試し)。seccomp が拒んだ場合も「未適用」と理由を返します。decideとlimitation_forに切り出し、単体試験で確かめています(ABI 0・Err・1・2・3・9)。src/tools/os_sandbox.rs)autoで wrap が実行時に失敗したら、Unavailable に降格し、is_applied()を false にします。requiredは拒否します。src/bin/gui_server/delegate.rs):--sandbox requiredを固定の引数に足し、単体試験を付けました(設計 4)。--sandboxを公開のフラグに(src/cli.rs、H-23 の推奨):docs/guide/README.mdのフラグの数と、ja・en の cli-reference を直しました。SECURITY.mdも更新しました。tests/issue502_os_sandbox_write.rs):Linux の適用の試験を足しました。os.truncate(ABI3)、システムの一時ディレクトリ、検証の入口、隔離の中で要る道具、依存のない crate のcargo build(ignored)、install 直後の status。CIの環境変数があるときは、landlock が未適用なら失敗します(黙って外れません)。detected_abi()とは独立に問い合わせて照合し、ABI ごとの試験の判定にもその値を使います。deny.toml、.github/workflows/ci.yml。検証(HEAD
f446ffd8、developfe9cc7a3の上)commandmate verifyで 15/15 passed。cargo deny check:exit 0(除外の追加なし。advisories・bans・licenses・sources とも ok)。cargo-zigbuild clippy --all-targets --target x86_64-unknown-linux-gnuは exit 0。--include-ignoredで 18/18、SKIP 0(1a の挙動は変わっていません)。cargo clippy --features gui --bin gui_server -- -D warningsは exit 0、delegate の単体試験は 1/1。rust:1.94-bookworm、既定の seccomp)CI=true、--include-ignored)は、CI の runner と同じく toolchain を$HOMEの下に置いた配置で 16/16 でした。required、本物の probe)で、次を確かめました。npm ci --prefer-offline(キャッシュを温めた後):成功next build:成功touch:Permission denied--jobs 1、--timeout 300、RUSTFLAGS="-A unused-variables")detected_abi→1があり、試験を足しました。backend_noteとlimitation_noteを None に置き換える変異です。ABI3 以上の kernel ではもともと None なので、区別できません。記録の文だけの変異で、許可は増えません。Defaultを持たない型への置き換えです。レビュー
pre_execは 2 つの syscall だけで、失敗すれば exec の前に spawn エラーになります。legacy_tiocsti=1の kernel で、端末から起動したとき)。別の Issue で、process_group(0)の代わりにsetsid()を使い、ABI5 以上では/dev/tty・/dev/ptsの IoctlDev を許可しないことを推奨。GUI の delegate と CI には届きません。/dev/ptsを directory ごと許可しています。F1 と同じ Issue で/dev/ttyだけに絞ることを推奨。~/.npmなどのキャッシュが外を指す symlink だと、その先が書き込みの許可になります。canonicalize して$HOMEの下のときだけ許可することを推奨(優先度中)。requiredで止まることを書く」が未対応です。後続でまとめます。確かめてほしい点
RUSTUP_HOME・CARGO_HOME:既存の env の許可リストは、この 2 つを子に渡しません。そのため、toolchain を$HOMEの外に置く環境(rust の公式イメージなど)では、隔離の有無にかかわらず Bash のcargoが使えません。~/.rustupを作ろうとして Permission denied になります。--test gui_serverだけを流し、--bin gui_serverの単体試験は流しません。手元では 1/1 でした。autoとrequiredの挙動は、判定を差し替える単体試験だけで確かめています。CI の runner の kernel と landlock の ABI(受け入れ条件の記録)
fb3703ce(試験だけ)で、記録の方法と外し方を直しました。GITHUB_STEP_SUMMARYがあるとき、kernel と ABI を job summary に 1 行書きます(書けなくても試験は失敗させません)。CIがあるときは、ABI2(hardlink)・ABI3(truncate)の試験は、ABI が足りなければ SKIP せずに失敗します(手元では SKIP のまま)。CommandAgent Test and Guardrails、ubuntu-24.04、image 20261004.327.1、x86_64)の summary:issue502/656 landlock: kernel=6.17.0-1022-azure abi=7CI=trueとGITHUB_STEP_SUMMARYを付けて 17/17 でした(summary に 1 行)。🤖 Generated with Claude Code