Repository navigation
fix(linux): refuse root file creation through built-in interpreters - #329
kevin-orellana wants to merge 1 commit into
Conversation
## Problem Root-launched Shell and Python operations can create host-root-owned entries. The sandbox directory-write restriction does not cover these trusted operations. ## Solution Refuse new host files, directories, symbolic links, and renames on Linux when real or effective user ID is zero. Preserve policy-approved existing-file access and Shell virtual storage. Admit the ownership floor after policy and Reach, so each refusal records one effective denial and a failed outcome. Remove the creation flag at the final host open to prevent recreation races. Document the root restriction and non-root requirement for creation examples. No CLI, configuration, policy-action, or public API names change. macOS behavior is unchanged. Existing-file contents remain writable when policy permits them. ## Tests On Linux ARM64, all 15 focused ownership tests passed with no ignored tests: - root_shell_refuses_new_host_entries and root_python_refuses_new_host_entries cover refused creation and rename. - root_shell_preserves_existing_reads_writes_and_append and its Python pair cover existing-file access. - nonroot_shell_preserves_host_creation and its Python pair cover ordinary use. - root_shell_preserves_virtual_storage covers writable in-memory paths. - root_python_open_does_not_recreate_a_leaf_removed_after_reach covers a disappearing file. The Shell resolution counterpart pins the older defense. - root_ownership_refusals_have_one_effective_denial (Shell and Python), root_ownership_admission_keeps_policy_first, root_ownership_rename_denial_records_failed_history, and both root_ownership_admission_does_not_reclassify_io_failures cases cover records. Direct host-root execution passed seven behavior and six audit cases. Disabling the original guard caused three failures. Bypassing admission and the Shell create-flag removal caused five failures. Restored source passed all 15 tests. Syscall traces showed O_CREAT for mutant write/append and its absence after restoration. Formatting and diff whitespace checks passed. Full-workspace testing failed during build with ENOSPC before tests ran. Clippy, default-off builds, site-manifest, deterministic integration, and macOS checks remain pending. Mixed-identity setup was killed before test execution. The draft PR records these limits and requires hosted validation and review.
| | OsFunctionCall::AppendText(_) | ||
| | OsFunctionCall::AppendBytes(_) => true, | ||
| OsFunctionCall::Open(args) => args.mode.create(), | ||
| _ => false, |
There was a problem hiding this comment.
Suggestion (non-blocking): This security classifier is the only OsFunctionCall match in this file with a wildcard arm. Its siblings mutates_authority and monty_decision_subject list every variant.
Example: Every variant that reaches _ today is correct: the reads, Stat/Exists/Is*/Iterdir/Resolve/Absolute, Unlink/Rmdir, and the env/clock calls. Now suppose a later monty-types release (monty-types = "1.0.0" is a caret requirement) adds a variant that creates an entry, such as a symlink or touch call. The sibling matches then stop compiling. This one keeps compiling, and it puts the new variant in the "never creates" group. If the new call uses a new HeldPath method rather than open, nothing strips O_CREAT or refuses it. Root AGENTS.md says: "Make an invalid state impossible by construction."
Suggestion: Replace _ => false with an explicit list of the remaining variants, as mutates_authority does. A new variant then has to be classified before the code compiles.
| let [decision] = recorded.as_slice() else { | ||
| panic!("exactly one effective record: {recorded:?}"); | ||
| }; | ||
| let (_, _, rule, verdict, reason) = decision.parts(); |
There was a problem hiding this comment.
Suggestion (non-blocking): The new denial-record tests discard action and resource. They also check the reason with a substring match. A denial recorded against the wrong subject would therefore pass.
Example: Take the rename and symlink cases in this loop. If the ownership denial were recorded against from (existing) and not against the destination, or under the wrong action, all of these asserts would still pass. effects.rs:1352 has the same pattern, including Path.rename, where the subject should be dst. Nothing in the tuple is non-deterministic. The reason is the constant ROOT_CREATION_REFUSAL, and the resource comes from the fixture.
Suggestion: For each case, assert the whole tuple, for example assert_eq!(decision.parts(), (expected_action, expected_resource.as_str(), &EffectiveRule::Enforcement("ownership-floor"), EffectiveVerdict::Deny, Some(ROOT_CREATION_REFUSAL))). Expose the constant as pub(super) for the tests.
| | Any other | The path changed between the check and the operation, for example a directory was swapped for a symlink. The Shell refuses rather than act on a file policy didn't judge. Run the command again. | `strands-shell: <command>: filesystem identity changed during effect admission` | | ||
| | Any other | The operation would change a configured tool program or an enclosing path. Update the program between runs. | `<path>: is a configured tool command or its ancestor` | | ||
| | Any other | The operation would change an installed Box program or an enclosing path. [Update the installation between runs](config.md#installation-integrity). | `<path>: cannot change a trusted Box executable or its path` | | ||
| | Any other | Linux root refused creation or rename in the surrounding OS. Run Box as a non-root account. | `root launch cannot create or move host filesystem entries; run Box as a non-root account` | |
There was a problem hiding this comment.
Important (non-blocking): Two existing pages that describe policy-independent refusals are now wrong. The decision log gets a new rule value that no page documents.
Example: Box runs as root on Linux, and policy permits fs:write. A user runs echo hi > ~/proj/new.txt. The refusal is recorded with strands.box.policy.cause = enforcement and strands.box.policy.rule = enforcement:ownership-floor. An operator who looks up this denial finds the following:
docs/user/security.md:51("What Box always enforces") says "One rule holds whatever a policy permits". The only rule value it names isenforcement:reach-floor.docs/user/policy.md:98says "Two refusals look like a denial, and nopermitlifts them". Neither of the two it lists is this one.
.agents/references/doc-updates.md covers this case: "Changes a refusal, a denial, or a warning that an operator reads → … policy.md for … how a denial reads".
Suggestion: Add the Linux-root ownership refusal to the list in policy.md. In security.md, add a sentence that names enforcement:ownership-floor and its reason text, and link to it from the shell.md/monty.md sections you already added.
|
Assessment: Comment (reviewed head I found no correctness defect. The two layers, the admission-time floor plus Assumptions and rules checked that held
Closing the open finding with a race-safe design that has two layers is a solid improvement. |
Human readable section
Status: Withdrawn in favor of PR #348, the active proposal for Linux root directory-write support.
The two PRs take different approaches to the same root-output behavior. This PR extends #300 by refusing host file creation and renames through built-in Shell and Python when Box runs as root. PR #348 restores sandbox directory-write grants and documents that permitted output can remain root-owned; a separate host program consumes that output using its own authority.
We are consolidating on the #348 model. This PR's blanket ownership refusal will not be merged or copied into #348. Existing policy checks and reachable-path restrictions still apply to built-in operations. The implementation and validation below are retained as historical evidence of the withdrawn approach. This consolidation does not assert closure of the related security assessment.
Historical proposal and validation
Human readable section
Problem: When root starts Box on Linux, built-in Shell and Python operations can create files with the trusted process's root identity. The sandbox restriction in #300 does not cover these operations.
Solution: On Linux, check whether either real or effective user ID is zero. Refuse new files, directories, symbolic links, and renames through the built-in interpreters for those launches. Reads, in-place writes, and appends to existing files remain subject to policy and the reachable paths check. Shell's in-memory filesystem remains writable.
Trade-off: Run Box as a non-root account when scripts need to create or rename entries in the surrounding OS. Root launches also refuse saves that replace an existing file through rename. Non-root Linux and macOS behavior stays unchanged.
Description
The ownership check runs after policy and the reachable paths check. A refused operation records an enforcement denial and a failed history outcome. An ordinary I/O failure remains distinct from an ownership refusal.
Host file opens through Shell and Python omit
O_CREATfor Linux root. The operating system therefore refuses a missing file without creating a replacement, including when an approved file disappears before the open. Directory creation, symbolic-link creation, and renames have corresponding checks before the operation. Existing identity checks remain in place.The refusal tells the operator to run Box as a non-root account. Operator documentation describes the restriction and preserved behavior. The change adds no policy actions or configuration keys and retains #300's sandbox restriction. It does not remove policy-approved access to existing file contents.
Related Issues
Follow-up to #300.
Type of Change
Breaking change
Testing
Tested on Amazon Linux 2023 ARM64, kernel
6.12.113-138.209.amzn2023.aarch64. The tests use the production Shell and Monty paths within the test binary. Local results cover the working-tree candidate based on3f69359a1ae257fd2b299b002050928d526a518f. All 13 changed-file SHA-256 hashes match commit5f513820fa5ad3b1a06e1a4990b336ec8a16054a. The local checkout was not yet committed during execution; hosted CI will test the commit directly.O_CREATfor both write and append. Fixed and restored calls omitted it for both operations.scripts/test-all.shstopped after build-time disk exhaustion, before tests ran. Hosted all-targets/all-features builds completed on Linux ARM64 and macOS; full workspace tests remain in progress in the direct branch run.cargo fmt --all --checkandgit diff --checkpassed. Hosted workspace lint passed on the committed head with the repository-prescribed vendored-code allowances; no warnings appeared.cargo build -p strands-box --no-default-featuresandcargo test -p strands-box --lib --no-default-features --no-runpassed on the committed head. This compiled the actual library test harness; it did not execute tests. The build reported 66 warnings in unchanged containment code and none in the changed Box crate.box_commit: unknown. macOS integration is still running.Draft status: independent automated source, design, and documentation review found no remaining defect. Full validation remains incomplete. Direct CI for the committed branch is running both platform suites, including containment tests omitted from draft-triggered CI. Automated review awaits the
manual-approvalenvironment decision fromstrands-box-maintainers; it has not started.AI-assisted implementation, testing, description, and author-side source review: Codex. Independent maintainer review remains pending.
Mixed real/effective user IDs remain unmeasured: the identity-changing setup was killed before any test ran. Local execution covers Linux ARM64. Hosted macOS all-feature builds and native adapter tests passed; its full workspace and deterministic tests are still running.
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsHosted Clippy used
-D warningswith the current repository allowances:too_many_arguments,only_used_in_recursion,await_holding_refcell_ref,explicit_auto_deref,chunks_exact_to_as_chunks,dead_code, andnon_snake_case. Owned-crate lint settings remain enforced.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.