Skip to content

fix(containment): refuse Linux root sandbox directory writes - #300

Merged
kevin-orellana merged 2 commits into
mainfrom
feature/root-owned-host-files
Nov 4, 2026
Merged

kevin-orellana merged 2 commits into
mainfrom
feature/root-owned-host-files

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: When root starts Box on Linux, a workload can create root-owned files in granted host directories. A separate privileged program can later trust those files and access data outside the workload grant.

Solution: Refuse sandbox directory write grants before a root workload starts. Root can still read granted directories, write explicitly granted existing files, and use private temporary storage.

Trade-off: Linux sandbox workloads that create files in host directories must run Box as a non-root account. This also applies to containers that present the launcher as user ID zero.

Remaining gap: Policy-approved Shell and Python file creation runs in the trusted process and retains its file identity. This PR does not change that route. The broader ownership finding must remain open until that route receives a disposition. macOS root creation also remains unchanged and unmeasured here.

Description

The Linux backend checks the launcher's real and effective user IDs against every composed directory write grant. It checks during validation and again before namespace entry. Agent, tool, and local-server workloads use this check.

This is an approved narrowing of Linux root behavior, selected on November 4 after testing the compatibility effects. The user configuration and containment design pages describe the restriction. The check uses the current user namespace. It does not resolve arbitrary mappings into ancestor namespaces.

PR #199's permission-bit restrictions and inherited directory-group behavior stay unchanged. Removing capabilities already occurs at startup, but does not change the identity that owns newly created files.

Related Issues

Follow-up to #199 for ownership assigned during file creation.

Type of Change

Breaking change

Testing

Tested the candidate on Amazon Linux 2023 ARM64, kernel 6.12.113-138.209.amzn2023.aarch64, with EXPERIMENTAL_LINUX_SUPPORT=TRUE. Runtime validation covers c479e216208471ca0f1cdb52344dd2525ef7e87b, based on 1d5cb050d2072727a0dd53e2f11db4854b251615. Follow-up f089f4a6f03461fc8b18676ffd1863db966f33d3 changes documentation only. Its runtime and test files are identical, and all 27 site-manifest tests passed again.

Check Result
Containment build and full-feature tests Passed. 669 top-level test outcomes, zero failures, zero ignored tests, and no runtime prerequisite skips.
Full workspace suite through scripts/test-all.sh Passed. 4,889 test outcomes passed, zero failed, and 17 ignored. Runtime omissions are described below.
Deterministic integration Passed all 131 Linux cases from 140 declared cases. Nine cases declare macOS-only support. No failures or errors.
Formatting and strict containment Clippy Passed all targets and features with zero warnings.
Workspace Clippy Passed with the exact allowances in just clippy and CONTRIBUTING.md. Bare strict Clippy reports six errors in unchanged vendored crates/shell code.
No-default-feature containment build Passed. It reports 66 dead-code warnings in unchanged macOS, configuration, and floor code.
Documentation site manifest All 27 tests passed.
Independent source review No correctness, security, or documentation blocker found.
Hosted Linux and macOS checks Both unit suites, both deterministic suites, and the required CI Gate passed at the current head.
Hosted ownership regressions Four behavioral tests and one helper passed, with no failures, ignored tests, or prerequisite skips. Root cases use a user namespace.
Hosted static analysis All five CodeQL analyses passed. The comparison reports no new alerts in changed code.

Hosted evidence: CI run, ownership test job, and CodeQL run. Linux deterministic results were 131 passes from 140 declared cases, with nine macOS-only exclusions. macOS results were 128 passes from 140 declared cases, with 12 Linux-only exclusions. Both had zero failures or errors. The hosted root cases use namespace user ID zero; the separate campaign below supplies actual-host-root evidence.

The new startup-refusal test fails without the guard and passes with it. A separate comparison used actual root and inert host-consumer fixtures. The baseline reproduced an outside-grant symbolic-link write and disclosure through a precreated regular file. The candidate prevented both, and restoring the baseline reproduced both again. Equivalent non-root controls kept file creation available.

Production-trampoline tests also preserve root existing-file reads and writes, private /tmp files and links, ordinary permission changes, and special-permission refusal. The test file has four behavioral tests and one subprocess helper. The helper's top-level return is not extra behavioral coverage.

Validation limits:

  • The workspace run initially skipped the installed socket-alias helper test. After the documented fixture preparation, its focused rerun passed one test without a skip.
  • The real credential-daemon test lacks its external daemon. The existing Linux alias-read assertion remains excluded, while its write assertions ran.
  • The examples gate builds the binaries, but this source tree has no scripted examples. The live SDK tutorial did not run.
  • Hosted Linux and macOS execution passed. Separate real/effective-ID predicates and the application recheck were not independently mutated.
  • These measurements do not constitute RoboSec revalidation or security acceptance. After merge, rerun the recorded finding against the merged revision. Include the policy-mediated creation route in the remaining scope assessment.

The deterministic verdict records its commit as unknown. Separate source and executable hash manifests bind that run to this candidate. The staged patch SHA-256 is 9b79c5006b3e9a8f567ba693be68caa70c952d3ded4cefaa857be222c3ce12d6.

  • 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 strict workspace command ran and failed on the documented vendored diagnostics above. The repository-prescribed lint command passed.

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

A Linux root launch lets a workload create root-owned files and symbolic links
inside granted host directories. A later privileged host program can trust
that ownership and write outside the workload grant or disclose data through
a precreated file. Removing capabilities does not change new-file ownership.

## Solution

Refuse directory write grants when either the real or effective launcher user
ID is zero. Check every composed authorization during validation and again
before namespace entry. Keep root reads, explicitly granted existing-file
writes, private temporary storage, and non-root directory writes available.

This deliberately narrows supported Linux root configurations. Kevin selected
this behavior on November 4, 2026, after compatibility testing and directed its
completion. Rootless containers that present user ID zero also meet the
restriction. The check does not resolve arbitrary ancestor identity mappings.
The configuration and design pages explain the migration to non-root launches.
PR199 permission restrictions and inherited directory groups remain unchanged.

## Tests

On Amazon Linux 2023 ARM64, the containment suite passed 669 top-level test
outcomes. The workspace suite passed, including all features. The deterministic
suite passed all 131 Linux cases from 140 declared cases, with nine macOS-only
exclusions. Build, formatting, strict containment Clippy, and repository
workspace Clippy passed. Bare strict workspace Clippy failed only on six
unchanged vendored shell diagnostics covered by the documented allowances.

root_directory_grants_are_refused_before_workload_execution failed without
the guard and passed with it. Actual host-root comparison fixtures reproduced
the symbolic-link write and regular-file disclosure on the baseline, prevented
both with the candidate, and reproduced both after restoring the baseline.

root_file_grants_preserve_private_access_and_temporary_storage and
file_grants_preserve_private_access_and_refuse_new_host_entries preserved
private existing-file access, private /tmp creation, ordinary modes, and
special-mode refusal. nonroot_directory_grants_preserve_creation preserved
non-root directory writes and symbolic-link creation.

The real credential-daemon test and the existing Linux alias-read assertion
remain unavailable. No scripted examples remain in this source tree, and the
live SDK tutorial did not run. macOS checks remain for hosted CI. Separate
real/effective-ID predicates and the apply recheck were not individually
mutated. RoboSec has not revalidated this candidate.
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Comment

The Linux sandbox guard does what it says for Write+Root grants. The open question is scope: the same root-owned-entry vector is still reachable through the trusted-process Shell/Monty path and through macOS write roots, and the docs now read as if the finding is closed.

Checked and held
  • write naming a file maps to Write+File (filesystem.rs:438), so exact-file writes stay allowed under root; write_file on a directory is refused earlier.
  • Private /tmp is not an authorization, so the guard doesn't affect it.
  • The check runs in both validate_config and apply (via apply_backend) before namespace entry, for agent, tool, and MCP sandboxes alike.
  • The namespace-root over-refusal (rootless containers) is documented as an accepted trade-off.
  • Interface narrowing: the PR cites the approval and updates docs/user/config.md in the same change, per root AGENTS.md.
  • Tests: the aarch64 gate matches file_permissions_linux.rs; the probe result is asserted as one full JSON object rather than field by field.

The test design (production trampoline, a non-root control, and a refusal test that leaves no side effects) is solid.

Comment thread docs/design/containment.md Resolved
@kevin-orellana kevin-orellana changed the title fix(containment): refuse Linux root directory write grants fix(containment): refuse Linux root sandbox directory writes Nov 4, 2026
@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 4, 2026 09:15
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed at f089f4a. The only change since c479e21 is documentation, in four files. It limits the claim to sandbox directory grants, records the mediated-creation route as an open finding, and states that macOS is left as it is. Runtime code is unchanged from what I reviewed before.

Checked and held
  • The revised docs match the code. Reach is built from the home, operator home, and workspace, not from the filesystem lists. So mediated Shell and Python writes are separate from sandbox grants, as config.md now says.
  • The Shell can't create an absolute or escaping symlink (verify_symlink_target, vfs_kernel.rs:1457), so my earlier /etc/shadow example didn't apply. The remaining residual, root-owned regular files from policy-approved writes, is recorded in crates/box/AGENTS.md under open findings.
  • The containment AGENTS.md entry no longer reads as closed and links to the box open finding, so the finding has one owner.
  • The macOS residual is now stated in both the design page and containment AGENTS.md.
  • The runtime checks from the earlier review are unchanged: exact-file writes and private /tmp are still allowed, the check runs in both validation and apply, and the tests assert the whole result object.

@kevin-orellana
kevin-orellana merged commit e24d903 into main Nov 4, 2026
25 of 26 checks passed
@kevin-orellana
kevin-orellana deleted the feature/root-owned-host-files branch November 4, 2026 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Agent Containment bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants