Skip to content

fix(box): accept a configured command with several names when this user cannot write it - #332

Merged
opieter-aws merged 4 commits into
mainfrom
feature/opieter-aws/multilink-commands
Nov 5, 2026
Merged

opieter-aws merged 4 commits into
mainfrom
feature/opieter-aws/multilink-commands

Conversation

@opieter-aws

@opieter-aws opieter-aws commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Box runs an agent's tools only from a file that the agent cannot change. #263 added a rule for
this: a tool's program can have only one name (hard link). Box cannot find every name of a file,
and a write through an unknown name could change the tool.

Many system programs have several names. On macOS, /usr/bin/git is one file with 78 names, which
it shares with make, clang, and others. On Linux, /usr/bin/perl has 2. Since #263, a box that
declares one of these tools does not start.

A second name is a risk only when the user that runs Box can write the file. A root-owned system
program is locked, so the kernel refuses a write through every name, also through the names that
Box cannot see.

This change:

  • accepts a program with several names only when this user does not own it and the kernel refuses
    this user a write;
  • checks before each launch that the program's link count, owner, group, and mode did not change;
  • keeps refusing a program with several names that this user owns, because an owner can unlock it;
  • keeps exactly one name for Box's own files: box.toml, the policy, and the CA bundle.

Tested end to end on macOS: an agent in a box runs Apple's /usr/bin/git, and an operator-owned
program with two names is still refused. Each new rule has a test that fails when the rule breaks.

Description

Problem. A configured tool whose program has more than one hard link stops the run. That
includes root-owned system programs that no name lets the box's user write: on macOS,
/usr/bin/git (and make, clang, cc, swift, 78 names in all), /usr/bin/java (37 names),
/usr/bin/id, unzip, and less; on Linux, /usr/bin/perl, unzip, bzip2, and Fedora's
gcc.

Solution. Box keeps the one-name rule for every file that the user that runs Box may be able to
write. It accepts a file with several names only when the kernel refuses this user a write, because
then no name, known or not, can change the bytes. The rule follows inode_may_be_writable in the
Linux containment backend: the real and the effective user, the write bits, and the kernel's answer
on the opened descriptor, where only EACCES refuses by itself. On macOS, EPERM and EROFS come
from checks that run before the permission check: a MAC policy (System Integrity Protection, or a
Sandbox profile that Box inherits) and the read-only system volume (when System Integrity
Protection is off, as on GitHub's macOS runners). So there they refuse only when the file carries
no access-control list, and the owner, the mode, and the list decide. Root always counts as
writable. Before each launch Box requires the same link count, owner, group, and mode, and asks the
kernel again, which covers the whole run.

What stays refused. An operator-owned program with a second name, for example a
uv tool install on Linux, which hard-links from uv's cache. A write grant over that cache could
change the program's bytes, so the rule still applies there.

Wire. A tool whose program has several names travels in a new command_identities list, which
is omitted when empty. A tool whose program has one name keeps identity_requirements, so a
configuration without a multi-link tool is byte-identical to main. The authority lists keep
exactly one name on load, also when a payload states a link count. A tool whose program has
several names needs a sandbox helper built from the same source.

Interface change. This touches two interface-frozen surfaces, and it asks a maintainer to
approve both:

  • strands-box: box.toml accepts a [tool.<name>] whose program has several names that this user
    cannot write, which main refuses. The refusal for the rest changes from
    must be a regular file with exactly one hard link to
    has <n> hard links, and the user that runs Box may be able to write it.
  • strands-box-containment: a new public method, ContainmentConfig::require_command_identity,
    and a new optional wire field, command_identities, which is omitted when empty. The method
    checks identity and link count only. The write check stays in strands-box
    (ConfiguredCommands::load at startup, ConfiguredCommand::verify before each launch), and the
    method's rustdoc states that a caller must make it first.

Decisions. docs/design/decisions.md#an-opened-file-can-require-identity-or-write-protection
now names the third method.

Residual risk. A forwarding stub, such as macOS /usr/bin/git, starts a second program that
Box does not pin (xcrun selects it). With the Command Line Tools that program is root-owned. A
command reached through a mount that remaps ownership (an idmapped bind mount, a FUSE view) is not
covered; that gap exists for a one-name command too, and crates/box/AGENTS.md records it as an
open finding.

Related Issues

Follow-up to #263. Review discussion:
#263 (comment)

Type of Change

Bug fix

Testing

  • The unit and integration tests in the commit message. Each rule was broken on purpose, its test
    failed, and it passed after the restore.

  • End to end on macOS 26.7.1 arm64: an agent in a box ran git --version, git status, and
    git log through [tool.git] command = ["/usr/bin/git"] (Apple's 78-name file), and
    cargo --version through a second tool. The same configuration on main stops with
    must be a regular file with exactly one hard link. An operator-owned program with two names
    stops with has 2 hard links, and the user that runs Box may be able to write it.

  • macOS-only regression tests that fail instead of skip: apples_git_loads_as_a_configured_command
    loads /usr/bin/git as a configured command, a_command_identity_requirement_accepts_apples_git
    sends it through the sandbox helper's configuration, and the deterministic case CN-T-09 starts a
    box with [tool.git] and runs /usr/bin/unzip (2 names) through [tool.unzip]. The containment
    suite blocks CI Gate on macOS.

  • Linux arm64, in a container as a non-root user: the run::commands tests pass with
    /usr/bin/perl (2 names, root-owned). The Linux integration suites did not run.

  • I ran the relevant suites (cargo test -p strands-box -p strands-box-containment --all-features)

  • If I touched Rust, I ran cargo fmt and cargo clippy for both packages with --all-features

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.

zastrowm
zastrowm previously approved these changes Nov 5, 2026
@opieter-aws
opieter-aws marked this pull request as ready for review November 5, 2026 18:26
Comment thread crates/box/src/run/commands.rs Resolved
Comment thread crates/containment/src/config.rs Resolved
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Request Changes

The Linux and SIP-on macOS cases are correct. Two things block or weaken the change: the new public containment method pins a writable file that has several names and leaves the write check to its caller, and on macOS an EPERM from any MAC policy is read as "no name can write".

Review Categories
  • Correctness: The accept rule trusts a kernel answer that can come from a path-based check before the per-inode checks. The narrow fix is to send EPERM to the same owner, mode, and ACL check as EROFS. See the inline comment.
  • Frozen surface / ownership: The containment surface gains require_command_identity and the command_identities wire field without approval. The check that makes the method safe lives in crates/box, so the write rule now has two owners. The wire claim in the description holds only for a box with no tools.

Checks that held:

  • Linux /usr/bin/perl (root-owned, 2 names) with EACCES → accepted, correct.
  • An operator-owned file with several names (uv tool install) → refused by the owner check, correct.
  • Root, group write, and other write → refused, correct.
  • With SIP off, EROFS falls back to the ACL check, correct.
  • On Linux, EROFS counts as writable (a conservative refusal).
  • identity_requirements and write_protections still refuse a crafted links value (loading_refuses_a_stated_link_count_that_the_builder_refuses).
  • verify checks the same link count, owner, group, and mode again before each launch, and asks the kernel again.
  • A tool with one name behaves as on main (only its wire list changes).
  • zastrowm's request for a macOS-only test is covered by apples_git_loads_as_a_configured_command and CN-T-09.

The detailed residual-risk notes in crates/box/AGENTS.md (the forwarding stub and idmapped mounts) make the scope of the protection easy to check.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Comment

I re-reviewed abfed49 against 643a7ed and found no new defects. Both earlier findings are addressed in code or in the description. One decision is still with a maintainer: approving the frozen strands-box-containment addition (require_command_identity and command_identities). The write check stays in strands-box, and the rustdoc now states the caller contract.

Checks that held on this commit:

  • macOS EPERM from SIP or an inherited Sandbox profile now falls back to the owner, mode, and ACL checks, the same as EROFS. /usr/bin/git has no ACL, so it still loads.
  • When acl_get_fd_np fails with anything other than ENOENT, the file counts as writable (a conservative refusal).
  • On Linux, EPERM and EROFS still count as writable. Only EACCES refuses.
  • A tool with one name at load goes through require_file_identity again, so its wire form is the same as on main. a_tool_program_with_one_name_keeps_its_identity_requirement pins this.
  • A link added or removed between load and launch is refused by verify, which requires the same link count, before the has_several_names branch runs.
  • Run on Linux: run::commands and run::contain::boundary (69 tests) and config_model (21 tests) pass.

The fixes are narrow, and each comes with a test that pins it.

@opieter-aws
opieter-aws merged commit c47a858 into main Nov 5, 2026
25 of 26 checks passed
@opieter-aws
opieter-aws deleted the feature/opieter-aws/multilink-commands branch November 5, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants