Repository navigation
fix(containment): copy the host's top-level links into /usr into the Linux view - #512
Conversation
…usr Linux host On Ubuntu, /bin links to usr/bin. A tool granted /usr/bin/sh saw it only at /usr/bin/sh, because the view holds no /bin link. A script the tool wrote at run time with `#!/bin/sh`, such as the entry points uvx writes for mypy and pre-commit, then failed to exec with ENOENT. Each file entry in /usr/bin or /usr/sbin is now also granted at its /bin or /sbin name when the host links those folders, with the same operation and file scope, as interpreter spellings are. The name reaches only that file. Startup lists the names under "host link names for configured access". Folder entries get no such name.
|
Assessment: Request Changes The approach is sound. Giving a granted Checks that held
Known gaps, no change requested
The fix is narrow and well disclosed. |
The /bin name was added once per name, so when a read entry for a file came before an exec entry for the same file, the exec never reached the /bin name, and the view bound it without exec. An exec entry for the command's own file was also skipped before the /bin name was added. Each (name, operation) pair is now granted once, an exec entry the command already covers still reaches the /bin name, and the startup line is printed once per name. The docs drop a folder example that can't load and say the name carries only the entries' operations.
|
Assessment: Request Changes (re-review of 4fa2e38) Both earlier findings are fixed. The follow-up commit now runs the host-link grant for exec entries that the command or an interpreter spelling already covers. That adds a second exec cell for the interpreter, and an existing guard test now fails (see inline). Checks that held on 4fa2e38
Once the failing test is resolved, the rest of the change looks ready. |
4fa2e38 added a /bin name for every exec entry, including one that the interpreter path already grants under the shebang's spelling. On Ubuntu that gave /usr/bin/dash a second exec cell (/bin/dash), and the guard test an_interpreter_an_exec_entry_covers_is_not_granted_twice failed. Choice: keep that test's rule. An exec entry an interpreter spelling already covers gets no /bin name. An exec entry for the command's own file still gets one, and the guard test is unchanged.
|
Assessment: Approve (re-review of b4a0293) All three findings are resolved. The last commit skips the Checks that held on b4a0293
Thanks for the quick, focused follow-ups. |
|
I was just working on strands-agents/box#453 which is this same problem. I found that copying the host's root links into the Linux view works too: /bin -> usr/bin, /sbin -> usr/sbin, /lib -> usr/lib and /lib64 -> usr/lib64, each written only when the host has exactly that link. With a granted /usr/bin/sh, /bin/sh then resolves through the link, and #!/bin/sh scripts run. That seems like a better approach for three reasons. It adds no grants or extra binds, because a link only opens files the view already binds. It covers every path under those folders, including folder grants and /lib64, not only /usr/bin file entries. And it fixes the agent and MCP views too, since the view then has the same shape as the host. Would you be open to exploring adding the links in the containment view, and drop the per-file /bin names? I have a working version that passes the containment and Box suites on ARM64 Linux, happy to share if you want. agent assisted reply |
The new host alias can expose a denied fileThe new On the tested Linux host, The new alias grant checks protected Box paths but does not apply the denial checks used for interpreter aliases. Could we check each added name against both the configured denial paths and their resolved targets, with regression coverage for reading and execution? There is also a separate documentation correction. The configuration reference promises the additional name for every granted file. The implementation intentionally excludes execute grants already used by an interpreter alias. For example, a configured script beginning Reproduction detailsTested: This reproduction requires Create separate, empty state and workspace directories. Give the state directory mode name = "pr512-denial"
box_dir = "/absolute/path/to/state"
[agent]
command = ["/usr/bin/env", "/bin/bash", "--noprofile", "--norc", "-c", "printf ALIAS_EXECUTED"]
workspace = "/absolute/path/to/workspace"
[agent.filesystem]
exec = ["/usr/bin/bash"]
deny = ["/usr/bin/sh"]Run the reviewed binary with: strands-box run --config /absolute/path/to/repro.tomlExpected: The denial prevents execution of Bash through the added name. Observed: The reviewed head prints Controls: Changing the command’s target to For the read variant, replace command = ["/usr/bin/od", "-An", "-tx1", "-N4", "/bin/bash"]The head exposes the executable header, |
Preserve explicit denials when adding host aliasesThis change conflicts with Box’s requirement that “a denial wins over every path grant”. The new Could we apply the existing denial checks to each added alias before granting access, with regression coverage for reading and execution? Reproduction evidence: On Amazon Linux 2023 ARM64, |
boundary.rs and docs/user/config.md take main's text: the per-file /bin names are being replaced by host root links in the Linux view (#453).
…Linux view On a host where /bin links to usr/bin, the Linux view bound only the files its grants named, so /bin was absent. A #!/bin/sh script a process wrote at run time, such as pnpm's node_modules/.bin commands or uvx's cached tool commands, failed to exec with ENOENT even with /usr/bin/sh granted (#453). The view now copies each host link from /bin, /sbin, /lib, /lib32, /lib64 or /libx32 whose text is a relative path into usr/, after every mount and before the root is sealed read-only. A name with a planned mount at or under it keeps its folder and gets no link. A link resolves only to paths the view binds, so it adds no reach. This replaces the per-file /bin names this branch added in crates/box/src/run/contain/boundary.rs, which are removed: the links cover folder grants, /lib64, and the agent and MCP views as well, and add no grants or startup lines. Suggested by @opieter-aws. Fixes #453
…ge-spellings # Conflicts: # crates/containment/AGENTS.md
|
Assessment: Request Changes (re-review of 034385a) This commit replaces the per-file Checks that held on 034385a
For the maintainers
Once the test build is fixed, this looks close to ready. |
|
Assessment: Request Changes (re-review of 034385a + merge b2d8847) The new design is better than the per-file aliases. A copied top-level link resolves inside the view, so it adds no grant, and a denial still applies to the file behind it. It also closes the denial bypass that @kevin-orellana found on b4a0293. I missed that bypass, and my earlier approval no longer applies. One blocker remains: the Linux test build doesn't compile (see inline). The merge from Checks that held
|
|
Assessment: Comment (re-review of 36fec65) No blocker remains. The only change since b2d8847 adds Checks on 36fec65
|
…d keep the link A grant, loader bind, or refusal written through a host link such as /bin -> usr/bin is now planned at its /usr name (/bin/bash at /usr/bin/bash, the loader under /lib64 at /usr/lib64). No mount then sits under a linked name, so the view keeps /bin, /lib and /lib64 even for a tool whose wrapper starts #!/bin/bash or a process with an exec file. Before, any mount under a name dropped its link, and runtime #!/bin/sh scripts failed again in those views. A refusal goes through the same mapping, so a refusal of /bin/bash replaces a grant of /usr/bin/bash. The plan test covers the #!/bin/bash wrapper, the loader closure, and that refusal; the end-to-end test refuses /bin/cat with /usr/bin/cat granted and checks the link reaches only the empty overmount.
|
Assessment: Request Changes (re-review of 21eecc3) The Checks on 21eecc3
|
…the runpath shadow test
|
Assessment: Approve (re-review of bb0402c), conditional on green CI and a maintainer's interface approval The only change since 21eecc3 updates the stale libc assertion to compare against Checks on bb0402c
The design now follows the host's own layout, which is simpler and safer than the per-file aliases it replaces. |
|
@kevin-orellana re #512 (comment): Thanks, that was a real bypass in b4a0293, and that code is gone. The PR now adds no per-file In your config, the deny of The |
|
@kevin-orellana re #512 (comment): Agreed, a deny has to win under every name. The current head adds no alias grants, so a deny has no new name to miss: |
|
Adding permission to read a system library that the agent cannot modify can prevent an otherwise valid command from starting. In Box's Could we preserve the required dependency's admitted execution access when combining entries for the same file and target, and add a startup regression test? Explicit denials and writable-library checks still need to take precedence. The dependency loop in I reproduced this on Amazon Linux 2023, 64-bit Arm, comparing base [agent]
command = ["/usr/bin/printf", "REGRESSION_OK\n"]
[agent.filesystem]
read_file = ["/usr/lib64/libc.so.6"]With otherwise equivalent configurations,
Each result repeated three times. Removing the read grant or adding an explicit I also reran the original eight alias-denial checks on |
Description
Fixes #453.
On a Linux host where
/binis a link tousr/bin, as on Ubuntu and Amazon Linux 2023, a sandbox's view binds only the files its grants name./binis absent, so a#!/bin/shscript that a process writes or downloads at run time fails to exec withENOENT, even when/usr/bin/shis granted. Two examples:node_modules/.bincommand as a#!/bin/shscript, sopnpm exec tsc --versionfails withCommand "tsc" not found([BUG] Linux: a tool cannot reach a granted file through a symbolic link, so #!/bin/sh scripts fail with ENOENT #453).#!/bin/shscripts. On GitHub's Ubuntu 24.04 runner, in a tool granted/usr/bin/sh,uvx [email protected]printederror: Failed to spawn: mypy,No such file or directory (os error 2).uvx ruff, a compiled program, ran.macOS is not affected.
The change, following @opieter-aws's suggestion on this PR:
/usr: each of/bin,/sbin,/lib,/lib32,/lib64and/libx32that is a link whose text is a relative path intousr/, such as/bin -> usr/bin.materializewrites the links into the view root after every mount and before the root is sealed read-only, so no mount target is reached through one./usrname: an interpreter spelling/bin/bashat/usr/bin/bash, the loader under/lib64at/usr/lib64. So no mount sits under a linked name, and every link is kept, including for a tool whose wrapper starts#!/bin/bash. A refusal goes through the same mapping, so a refusal of/bin/bashreplaces a grant of/usr/bin/bash./bin/catstays absent unless/usr/bin/catis granted./lib64, and the agent's, tools' and MCP servers' views.What this replaces: the earlier version of this PR gave each granted file in
/usr/binor/usr/sbinan extra/binor/sbingrant, plus a new startup section. That code incrates/box/src/run/contain/boundary.rsand its docs are removed, so this PR no longer changes the startup disclosure or what a filesystem entry grants.A tool still needs
/usr/bin/shitself in its grants (for exampleread_file = ["/usr/bin/sh"]) for the script to start. A host where/usr/bin/shis a link to another shell needs that link granted, not only its target.Related Issues
Fixes #453.
Type of Change
Bug fix
Testing
the_view_copies_the_hosts_usr_links_and_mounts_each_name_under_usr(crates/containment/src/backend/linux/namespace/view.rs) plans views and checks that each host link into/usris copied, and that no mount sits under a linked name, for a/bin/bashgrant with/usr/bin/sh, for an exec file's loader and libc, and for a refusal of/bin/bashover a grant of/usr/bin/bash, which leaves only the refusal at/usr/bin/bash.a_bin_sh_script_runs_through_the_hosts_bin_link(crates/containment/tests/root_links_linux.rs) runs a#!/bin/shscript under the real trampoline with only the script and/usr/bin/shgranted. The script must start, and/bin/lsmust be absent. It also grants/usr/bin/catand refuses/bin/cat, and checks that/bin/catis empty and does not runcat. It skips on a host whose/binis not a link tousr/bin.Locally (macOS):
cargo fmt --check;cargo clippy -p strands-box-containment --lib --all-features -D warningsforaarch64-unknown-linux-gnu,x86_64-unknown-linux-gnuand macOS; the docs site-manifest test (28 passed). This Mac has no Linux C toolchain, so the Linux tests compile and run only in CI.I ran the relevant suites (
just check, orcargo test --workspace --all-features)If I touched Rust, I ran
cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.