Repository navigation
fix(box): accept a configured command with several names when this user cannot write it - #332
Conversation
…er cannot write it
|
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 Review Categories
Checks that held:
The detailed residual-risk notes in |
|
Assessment: Comment I re-reviewed Checks that held on this commit:
The fixes are narrow, and each comes with a test that pins it. |
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/gitis one file with 78 names, whichit shares with
make,clang, and others. On Linux,/usr/bin/perlhas 2. Since #263, a box thatdeclares 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:
this user a write;
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-ownedprogram 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(andmake,clang,cc,swift, 78 names in all),/usr/bin/java(37 names),/usr/bin/id,unzip, andless; on Linux,/usr/bin/perl,unzip,bzip2, and Fedora'sgcc.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_writablein theLinux containment backend: the real and the effective user, the write bits, and the kernel's answer
on the opened descriptor, where only
EACCESrefuses by itself. On macOS,EPERMandEROFScomefrom 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 installon Linux, which hard-links from uv's cache. A write grant over that cache couldchange the program's bytes, so the rule still applies there.
Wire. A tool whose program has several names travels in a new
command_identitieslist, whichis omitted when empty. A tool whose program has one name keeps
identity_requirements, so aconfiguration without a multi-link tool is byte-identical to
main. The authority lists keepexactly 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.tomlaccepts a[tool.<name>]whose program has several names that this usercannot write, which
mainrefuses. The refusal for the rest changes frommust be a regular file with exactly one hard linktohas <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 methodchecks identity and link count only. The write check stays in
strands-box(
ConfiguredCommands::loadat startup,ConfiguredCommand::verifybefore each launch), and themethod's rustdoc states that a caller must make it first.
Decisions.
docs/design/decisions.md#an-opened-file-can-require-identity-or-write-protectionnow names the third method.
Residual risk. A forwarding stub, such as macOS
/usr/bin/git, starts a second program thatBox does not pin (
xcrunselects it). With the Command Line Tools that program is root-owned. Acommand 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.mdrecords it as anopen 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, andgit logthrough[tool.git] command = ["/usr/bin/git"](Apple's 78-name file), andcargo --versionthrough a second tool. The same configuration onmainstops withmust be a regular file with exactly one hard link. An operator-owned program with two namesstops 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_commandloads
/usr/bin/gitas a configured command,a_command_identity_requirement_accepts_apples_gitsends 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 containmentsuite blocks CI Gate on macOS.
Linux arm64, in a container as a non-root user: the
run::commandstests 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 fmtandcargo clippyfor both packages with--all-featuresChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.