Skip to content

fix: reject Linux write grants without explicit read access - #129

Merged
kevin-orellana merged 6 commits into
mainfrom
feature/linux-filesystem-permissions
Oct 23, 2026
Merged

kevin-orellana merged 6 commits into
mainfrom
feature/linux-filesystem-permissions

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem Statement: Today, we cannot exclusively support write-only grants on filesystem paths in Linux (at least with the kernel mechanism we use, which are process namespaces). Once write is granted in box.toml, so is read, breaking the contract.

Solution: For now, we fail-close (and loudly) if write or write_file grants lack explicit covering read access on Linux. The long-term solution will be using a Landlock-based filesystem containment which allows for write-only pathing.

Description

Linux writable mounts also permit reads. This change rejects writes without explicit content-read coverage before any agent, tool, or local server runs. Every write requires a read grant for the same file or an enclosing directory tree. Directory-entry reads cannot satisfy this requirement.

Containment owns the shared rule through validate_grants. Box calls it at startup and retains authored-entry errors. The Linux namespace backend also checks direct and decoded configurations before mount planning. Containment is internal (publish = false), but its callers now receive the same refusal. Credential grants retain exact read pairing, consent, and store restrictions, plus the shared content-coverage check. The operator approved the new validator and typed refusal before implementation.

Startup disclosure identifies effective access, including overlapping grants. Local servers retain approved paths and refuse replacements before launch. Server command resolution remains lazy. macOS retains write-only access.

This is a Linux platform limitation. Adding read permission remains an explicit operator decision. Landlock implementation is deferred. The configuration guide and existing design decision record the limitation and alternatives.

Related Issues

Related to #44.

Type of Change

Bug fix and documentation update. Unsupported Linux write-only configurations fail before execution.

Testing

The containment follow-up changed seven files, with 330 insertions and 17 deletions. Most additions are tests. Local checks used the source delivered in b6634bb.

Check Result
macOS containment and Box unit tests 113 and 598 passed
Linux containment and Box unit tests 230 and 585 passed
Linux contained target execution Five passed, including refusal before the target runs
Linux filesystem execution 30 role/scope cases passed
macOS filesystem execution 21 role/scope cases passed
Lazy unused-server composition Passed on both platforms
Six added tests with coverage refusal deliberately disabled All failed; restored source and target execution passed
Affected-package Clippy and formatting Completed on both platforms; existing warnings remain
Affected-package builds without default features Passed on both platforms; existing unused backend warnings remain
Deterministic suite (bash test-integ/run.sh) GREEN, full coverage: 121 passed, eight platform exclusions, zero failures or errors

The shared tests cover files, trees, overlapping grants, both grant orders, and every write in a set. They reject directory-entry, metadata, listing, execution, and sibling-prefix substitutes for content reads. Backend and serialized credential tests cover direct callers. The real Linux execution test proves refusal before the target runs.

Linux execution used privileged ARM64 Debian with an unprivileged test user. Docker storage exhaustion required executable temporary storage for test files. Cargo targets remained on disk. These results do not qualify other Linux deployment configurations.

The complete workspace run failed. bash scripts/test-all.sh reported nine failures across runtime_mcp_policy_staging and box_telemetry. Both full targets passed unchanged on serial retry: 25 MCP tests and 25 telemetry tests, with one existing telemetry ignore. The catalog ratio was 1.92 against a limit of 3.0. No test, timeout, or threshold changed.

Main revision a861691 failed three of the same MCP tests: failure cleanup, the 256-page limit, and catalog performance. Main telemetry passed twice. The failure mechanisms were not all identical. The other candidate failures did not reproduce in this sample. These results establish intermittent behavior, not a repaired test defect. The original full workspace result remains red.

Clippy reports existing warnings in unchanged mount, argument, tool-spawner, and vendored shell code. No warning originates in changed source. A fresh-context adversarial review found no material implementation defect. The review checked the scope, backend enforcement, credential restrictions, and mutation evidence.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

The exact checklist commands above are not claimed. The executed workspace script, package checks, retries, and limitations are stated separately. Fresh remote continuous integration and human review remain pending for this revision.

The earlier workflow change in 30b8a7c retains checkout of github.sha and read-only cache access for the manual Full Tests caller. The scoped manual validation run passed. Previous green workflow results cover the previous head, not this follow-up. The human containment review thread remains open for reviewer confirmation.

The follow-up in ab359ee adds only two comments requested by automated review. It explains credential-only validation and the file/tree inputs to access disclosure. Executable code is identical to b6634bb. Formatting, whitespace checks, and independent review passed; broad test suites were not repeated.

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

The personal understanding attestation remains for the human contributor. The agent review is described under Testing.


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

## Problem

Linux writable mounts also permit reads. A write-only configuration therefore grants more access than its author requested. Local-server grants also need startup approval before the agent can run.

## Solution

Require explicit covering read access for every Linux write grant. Preserve read-only access and macOS write-only access. Disclose effective access for agent, tool, and local-server grants. Reuse startup-approved local-server paths and refuse changed identities. Document the Linux limitation and explicit read-write alternatives. Additional write-only enforcement is deferred.

## Tests

linux_rejects_write_only_before_any_process_runs proves startup refusal across 15 configurations. explicit_read_write_succeeds_for_every_process_and_scope covers 12 configurations on each platform. read_only_preserves_contents_for_every_process covers three roles. macos_write_only_preserves_content_read_refusal covers three roles. a_local_server_refuses_a_grant_replaced_after_startup_approval proves changed paths cannot replace approved grants.

Final Linux execution passed 30 cases; all 585 Linux library tests passed in a Debian 12 ARM64 container. Final macOS execution passed 18 cases and all 27 hosted tests passed. Before the local-server approval fix, all 597 macOS library tests passed. Package all-feature builds, formatting, and Clippy passed. Clippy still reports existing shell warnings and the existing tool_spawner argument-count warning. The full workspace warning-as-error gate and cloud deployment qualification were not run.
@kevin-orellana kevin-orellana changed the title Reject unsupported Linux write-only filesystem grants before execution fix: reject unsupported Linux write-only filesystem grants before execution Oct 20, 2026
Comment thread crates/box/src/command/run.rs Resolved
@github-actions

Copy link
Copy Markdown

Issue (Important): This change moves a documented premise but leaves the decision entry that records it stale. docs/design/decisions.md (~L397) still reads:

On Linux a writable bind is also readable, so write without read holds on macOS only, and the disclosure names such an entry as readable too.

After this PR, Linux no longer "holds" write-only and no longer discloses it as "readable too" — it refuses the configuration at startup. AGENTS.md states: "A decision that moves rewrites the entry it moves... Never leave a stale entry beside a second entry that corrects it." This is also squarely in foundational-premise territory ("write does not imply read" / "Linux is the residual: a writable bind reads there, and the startup disclosure says so on that entry's line"), which AGENTS.md flags as needing explicit approval before implementation.

Suggestion: Rewrite that decisions.md entry (keeping its <a id> anchor) so it describes the new Linux refusal and the read-coverage requirement, and confirm in the PR that the premise change was approved (issue #44 is referenced but the freeze asks for an explicit sign-off). The code and docs/user/config.md are internally consistent and well-pinned; this is about keeping the "why" doc from contradicting shipped behavior.

@github-actions

Copy link
Copy Markdown

Assessment: Comment (approve-leaning)

A deliberate, fail-closed fix for a real contract gap: on Linux a writable bind is also readable, so write without covering read grants more than the author asked for. The read-coverage check, disclosure classification, and the local-server startup-approval path are correct and well-pinned by unit and end-to-end tests across agent/tool/server and exact/overlapping scopes.

Review notes
  • Correctness: covers / require_read_for_every_write / effective_access behave correctly under adversarial cases (a write directory needs a single read covering the whole tree; a read_file cannot cover a write directory; exact/ancestor overlaps classify as expected). No logic issues found.
  • Interface freeze: No new box.toml keys, CLI flags, or dependencies; the added DirectGrant.access field is internal (not serialized), so no wire/record shape change.
  • Docs: docs/user/config.md matrix is clear and matches the code. One docs/design/decisions.md entry is now stale (see comment) — the main follow-up.
  • Disclosure parity: Local-server startup disclosure is lighter than agent/tool; minor (see comment).

Nice, security-first change with strong end-to-end coverage proving the refusal fires before any process runs.

@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed cc2411c (diff against c55a248, the commit from my last pass). Both findings are resolved and the change picks up extra coverage.

Follow-up verification
  • MCP disclosure parity (prior suggestion): run.rs now routes [mcp.*] through Boundary::translate in the same loop as tools, so local servers emit the full Boundary::disclosure(). Consistent shape across all three process kinds. ✅
  • Stale decision entry (prior Important): docs/design/decisions.md is rewritten to describe the Linux write-only refusal, the read-coverage rule ("a child read cannot cover a parent write grant"), macOS retaining write-only, the pinning tests, and Landlock deferred as the long-term path. Anchor preserved. ✅
  • Stronger premise coverage: new read-write-overlap / partial-read modes with sibling fixtures pin that a write grant does not expand read/write beyond its own scope and a read grant does not expand beyond its own scope; added namespace_launcher_is_usable() skip guards; new macOS partial-read test.
  • test-integ cn_t_01/03/07/08: add explicit Linux read/read_file coverage for their write grants, matching the new rule (verified cn_t_03's read = [control] covers write = [control]).
  • Identity re-check intact: the hosted.rs regression test swapped its symlink fixture for a file↔directory swap; both refusal paths (became a symbolic link, changed between a file and a directory) remain in the code and under test, so the launch-time identity premise is preserved, not weakened.
  • CI: containment-deterministic.yml now runs filesystem_modes on a supported Linux backend.

Thorough follow-up — the added sibling/overlap tests make the "write does not imply read, and neither expands beyond its grant" property explicit on both platforms.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

The earlier decision-entry finding is outdated after cc2411c. The existing decision entry now states that Linux rejects write grants without explicit covering read access, preserves macOS write-only support, and keeps the same anchor. The PR description records the operator's approval. Current decision entry.

The earlier assessment repeats that finding and the lighter local-server disclosure finding. Both are superseded by the fixes in cc2411c. I checked the current code and documentation. The latest automated assessment confirms both fixes and raises no new finding. No additional code change is needed for these review comments. Its written assessment says "Approve," but GitHub records the formal review as COMMENTED.

The separate CodeQL cache-poisoning annotation remains open. The workflow limits cache saves to pushes to main, as documented in the PR. This comment review does not dismiss that alert or claim all checks passed.

@kevin-orellana kevin-orellana changed the title fix: reject unsupported Linux write-only filesystem grants before execution fix: reject Linux write grants without explicit read access Oct 21, 2026
@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed 523f136 (diff against cc2411c). This reworks the server-disclosure change from the previous commit, and it's a net improvement — it also fixes a regression I failed to flag last time.

What this corrects and verifies
  • Lazy-resolution regression fixed: the previous commit routed every [mcp.*] spec through Boundary::translate at startup, which resolves the server's command program eagerly and would break lazy server resolution (a declared-but-uninstalled server must not block box startup — pinned by a_box_declaring_many_mcp_servers_still_runs). I praised that approach last round and missed this; good catch reverting it.
  • Two-phase disclosure: startup now prints each server's approved direct filesystem grants ([mcp.X] starts on demand; approved direct filesystem grants:) without translating — so the risky filesystem reach is disclosed up front while lazy resolution is preserved — and the full boundary.disclosure() (runtime minimum, HOME/PATH, egress) is emitted at actual launch in McpLeafLauncher::spawn. This satisfies the original parity concern without the eager cost.
  • Fail-closed hardening: a server with no judged reach now raises ConfigError::Contract instead of silently skipping disclosure. Verified ConfigError is in scope, Contract { reason } exists, and it converts into the hosted() BoxError return.
  • Single launch path: the full disclosure sits on the one leaf spawn path, so there's no spawn route that launches a server without disclosing.
  • Docs + tests: decisions.md is rewritten to describe the two-phase model and references the pinning test; filesystem_modes.rs now asserts both the startup grant line and the launch-time runtime minimum, added by Core: line for the server role, pinning both phases.

Nice correction — disclosing filesystem reach eagerly while deferring command resolution is the right split.

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

Re-reviewed 30b8a7c (CI-only, diff against 523f136). The containment-checkout simplification is correct, but the full-tests.yml cache change is broken.

Details
  • Critical — full-tests.yml:40: cache-mode: read is an invalid job key and not a declared input of rust-test-lint.yml, so the workflow file fails validation and the manual dispatch won't run. It's also redundant — the existing save-if guard in rust-test-lint.yml already blocks cache writes on a workflow_dispatch. See the inline comment.
  • OK — ci.yml + containment-deterministic.yml: dropping the ref input and checking out github.sha directly is equivalent (in a workflow_call, github.sha is the caller's triggering SHA, which is what ci.yml was passing) and simpler. ci.yml is the sole caller, so no dangling with: ref.
  • Suggestion: shortening the cache-poisoning rationale comment is defensible since it referenced inputs.ref (now removed), but verdict-hermetic.yml still says "Same guard as containment-deterministic.yml" — that cross-reference now points to a file that no longer carries the explanation. Consider keeping a one-line pointer to the shared rationale.

The containment checkout cleanup is a nice simplification — just the one blocking item to resolve.

Comment thread .github/workflows/full-tests.yml Resolved
@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

I read this assessment and addressed the blocking claim in the inline thread: #129 (comment).

The claim uses outdated syntax information. Current GitHub documentation supports the job-level cache key, and the exact manual workflow passed validation, checkout, and cache setup. Its build is in progress. The read-only cache limit remains because save-if does not restrict the job's cache token.

The verdict-hermetic.yml cross-reference still points to the same upload condition: containment retains the identical save-if expression. No pointer needs replacement for this change. The removed prose incorrectly treated that condition as a permission boundary, so it should not serve as shared security rationale.

The inline thread is resolved with documentation and the running workflow as evidence. No code change is needed for this assessment.

@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed b6634bb (diff against 30b8a7c). This moves the write-requires-read coverage floor out of box and into the containment crate, and — importantly — enforces it at the namespace backend before any irreversible mount step, not just at box's config layer.

Details
  • Defense-in-depth (the core fix): NamespaceBackend::validate_config now runs require_read_for_writes over all authorizations before MountView::plan, so a write-only grant is refused at enforcement time regardless of which config path produced it. The integration test pins this end-to-end (exit 3, "cannot enforce write-only", target never runs).
  • Correctness improvement: the new coverage predicate is scope-aware — a Dir listing no longer counts as content coverage for a write, only Root/File reads do. Pinned at config and backend levels.
  • Clean layering: box's require_supported_grants delegates to containment::validate_grants and remaps WriteOnlyUnsupported back to its friendly refusal message; the new error variant is #[non_exhaustive]-safe.
  • Test coverage is strong across unit (incl. reverse-order symmetry and empty-set), config, backend (direct + decoded), and integration.
  • Two minor, non-blocking notes left inline: a duplicate coverage predicate (covers() vs the new scope-aware match) worth consolidating, and a filtered validate_grants call worth a clarifying comment.

Nice layering — pushing the floor down to the backend closes the gap where only the box config layer validated it.

Comment thread crates/containment/src/config.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed ab359ee (diff against b6634bb): docs-only, +2 lines, and it addresses both non-blocking suggestions from my previous pass.

  • filesystem.rs covers() — comment now notes the disclosure path compares validated file/tree grants (directory-entry grants excluded), documenting why the coarser predicate is safe here. ✅
  • config.rs — comment now explains that exact read pairing keeps coverage within credential consent while the backend validates ordinary grants, clarifying the deliberate asymmetry. ✅

No behavior change. The underlying fix remains correct and well-tested. LGTM.

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.

4 participants