Skip to content

fix(box): refuse the box's private tree in the kernel - #145

Merged
abhisheksp merged 3 commits into
mainfrom
feature/box/private-tree-kernel-refusal
Oct 22, 2026
Merged

abhisheksp merged 3 commits into
mainfrom
feature/box/private-tree-kernel-refusal

Conversation

@abhisheksp

@abhisheksp abhisheksp commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This change adds kernel-level enforcement for <box_dir>/private/. Before, only startup checks in Box kept the workload out of this directory. Now the operating system also blocks every read, write, and execute in it, from the agent and from every tool and MCP server. The startup checks stay as the first, readable error.

Description

Context. Each box keeps its own state in <box_dir>/private/: the stored record, the policy, the durable history, the containment configs, and the helper images. The workload must never reach this directory.

Before. Box checked each filesystem grant at startup and refused a grant that reaches or encloses private/. No sandbox rule named the directory. If a grant got past the startup check, for example through a path name that the check did not recognize, the kernel did not stop the access. Also, on macOS a refusal rule named only the usual path, and not the same path under /System/Volumes/Data.

After.

  • Every sandbox profile that Box builds refuses <box_dir>/private/ beneath all grants: the agent box, each tool, and each MCP server. On macOS, Seatbelt denies every operation in the directory, and the rule comes after every allow rule. On Linux, the namespace view puts an empty read-only mount over the directory.
  • On macOS, each refusal rule also names the path under /System/Volumes/Data, as the credential rules already do. This also applies to operator deny entries.
  • On Linux, a refusal under a directory-only grant now counts as content below that grant. Without this, the empty mount had no place to attach, and the box did not start.
  • The startup checks do not change. The startup output does not list this rule as an operator deny entry, because Box adds it. No frozen interface changes.

Related Issues

None.

Type of Change

Bug fix

Testing

  • Unit tests pin each part, and each test fails when its part of the change is removed:
    • every_profile_refuses_the_private_tree_after_every_allow_that_reaches_it
    • a_refusal_renders_its_data_volume_spelling_after_every_allow
    • a_refusal_replaces_its_metadata_only_ancestor
    • a_refusal_beneath_a_metadata_only_directory_establishes
  • the_boxs_own_private_tree_is_unwritable_from_inside writes into the directory from a real box. It passes on main too, because the startup checks hold there, so it protects against regressions.
  • The kernel rule was checked on its own on a macOS host, on a scratch branch with the startup checks turned off and a write grant on the directory that holds the box. On main, a write into private/ succeeded. With this change it failed with EPERM, and a write next to the box still succeeded.
  • CN-T-02 now accepts an empty listing of private/ on Linux, because the directory is an empty mount there. The test still requires every file read and write to fail, and the host files to stay unchanged.
  • The containment golden profiles are re-recorded. The only change is the added /System/Volumes/Data deny lines.
  • box_filesystem passes 24/24 on macOS and on ARM64 Linux, and the deterministic containment suite gives the same result for every case before and after.
  • I ran the relevant suites: cargo test -p strands-box --all-features and cargo test -p strands-box-containment --all-features --no-fail-fast, on x86_64 Linux, ARM64 Linux, and macOS.
  • If I touched Rust, I ran cargo fmt and cargo clippy --all-targets --all-features on the changed crates. No new warnings.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

The workload must never reach `<box_dir>/private/`. The tree holds the
record, the policy, the durable history, the containment configs, and the
helper images. Today only the startup guards keep it closed. No profile
carries a rule for it, so a grant spelling that a guard does not detect
reaches the tree, and the kernel does not stop the access. Also, a
refusal renders only its own spellings and not its `/System/Volumes/Data`
spelling.

## Solution

`Boundary::translate` adds one refusal of the canonical private tree, at
`Root` scope, beneath every grant. Each profile that Box builds holds it:
the agent box, each tool leaf, and each MCP leaf. On macOS the refusal
renders after every allow. On Linux it lowers to an empty read-only
overmount. The refusal is not an operator `deny` entry, so the startup
disclosure does not show it. The startup guards do not change.

Seatbelt now renders each refusal under its data-volume spelling too,
the same as the credential floor does. This applies to every refusal,
operator `deny` entries included.

The Linux view plans a `Dir` grant as a fresh read-only filesystem
unless a grant sits below it. A refusal below it now counts the same
way, because its mountpoint cannot be created on a read-only
filesystem. No frozen surface changes.

## Tests

- `every_profile_refuses_the_private_tree_after_every_allow_that_reaches_it`
  shows that the agent, tool-leaf, and MCP-leaf profiles refuse the tree
  in both spellings. It fails when the refusal is removed and when the
  data-volume spelling is removed.
- `a_refusal_renders_its_data_volume_spelling_after_every_allow` pins the
  Seatbelt half.
- `a_refusal_replaces_its_metadata_only_ancestor` pins the Linux plan, and
  `a_refusal_beneath_a_metadata_only_directory_establishes` applies it.
  Without the planner change the apply fails with `Read-only file
  system`.
- `the_eight_lists_translate_to_their_cells` now shows that only the
  refusal names the private tree.
- `the_boxs_own_private_tree_is_unwritable_from_inside` writes into
  `private/` and its helper directory from a real box. The test passes on
  main too, because the guards hold there. It guards against regression
  and does not prove the floor.
- The floor was proved on a macOS host, on a scratch branch with the
  guards disabled and a write grant on the directory that holds the box.
  On main the helper image changed and a new file appeared. With this
  change both writes failed with EPERM, and a write beside the box
  succeeded.
- macOS host: box_filesystem 24/24 and the box library tests pass before
  and after. ARM64 Linux host: box_filesystem 24/24. The deterministic
  containment suite on EC2 gives the same result per case before and
  after: Linux 61/2/16, macOS 61/5/3/10, which is the standing set.
@github-actions

Copy link
Copy Markdown

Assessment: Approve

Focused security hardening that closes the box's private tree in the kernel rather than relying solely on the startup guards. The core change is a single unconditional refuse(guard.private, Scope::Root), and the surrounding backend edits (Seatbelt data-volume twin, Linux view mountpoint accounting) are consistent with existing idioms. Each behavioral claim is pinned by a test, and the diff carries no frozen-surface or public-API change.

Review notes
  • Correctness: Verified the Linux view.rs change is fail-closed. When a metadata-only Dir ancestor's fresh tmpfs is skipped because a refusal lies below it, the ancestor degrades to an empty directory in the read-only root scaffold (real contents are never bound), which is at least as strict as the tmpfs it replaces — the refusal tmpfs then establishes beneath it. No widening.
  • Ordering: The refuse is added before the grant loop, yet "beneath every grant" holds because Seatbelt renders denies in a separate cell after every allow, and protect_authorities skips Deny grants, so nothing is re-validated. The new *_after_every_allow_that_reaches_it test pins the rendered position.
  • Seatbelt: Twin-spelling handling mirrors the credential floor and granted-existence paths, and correctly extends to operator deny entries. Dedup via Vec::contains is fine at this scale.
  • Testing: the_boxs_own_private_tree_is_unwritable_from_inside complements the existing _unreachable_from_inside test (not a duplicate) and doubles as regression protection on main. The per-field assertions in the view/seatbelt unit tests match the established sibling-test style, so no change requested.
  • Golden profiles: The re-recorded twin deny blocks are mechanical and consistent across all five files.

Nicely scoped change with strong defense-in-depth reasoning and thorough cross-platform verification.

@github-actions

Copy link
Copy Markdown

Re-review @ d793a5e — Assessment unchanged: Approve

The incremental commit touches only test-integ/tests/containment/cn_t_02.rs, adapting CN-T-02 to the Linux behavior this PR introduces: the private tree is now an empty read-only overmount, so a list on it succeeds naming nothing rather than failing with ENOENT. I traced it against the probe output (LIST_OK {path:?} names=<joined>) and the gate is correct — an empty listing is accepted only on Linux, while a non-empty listing still falls through to refused_as and fails loudly, so a genuine leak is still caught. The desc and doc-comment updates match the new behavior.

Two prose-only, non-blocking notes:

  • The ENOENT fallback in denials() for the LIST case is now effectively unreachable on Linux (the overmount makes the empty listing deterministic). It's harmless/conservative, just no longer exercised for this assertion.
  • The PR description's claim that the deterministic suite "gives the same result for every case before and after" no longer strictly holds for CN-T-02 on Linux (the LIST outcome flips from ENOENT to an empty listing). Worth a one-line note in the description so the behavior change is recorded.

No code changes requested.

@abhisheksp
abhisheksp merged commit ef73fce into main Oct 22, 2026
19 checks passed
@abhisheksp
abhisheksp deleted the feature/box/private-tree-kernel-refusal branch October 22, 2026 17:11
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