Repository navigation
test(shell): pin that sh FILE is decided as shell:exec on sh - #472
Conversation
|
Assessment: Comment The new Assumptions and rules checked that held
The guard proof in the description, where the author put the defect back and saw all 5 tests fail, makes these regression pins credible. |
|
Assessment: Request Changes Re-review of Checked at this head, and held
|
|
Assessment: Approve (provided the Linux aarch64 CI passes) Re-review of Checked at this head, and held
Thanks for the quick fixes and for checking each one with the harness. |
|
Assessment: Comment (this replaces my earlier "Approve") Re-review at Checked at this head, and held
|
## Problem
`sh FILE` and `lash FILE` run the file in the Shell. No host program starts. An earlier Shell
decided `sh FILE` as `shell:spawn` on the host `sh` that `PATH` found, for example
`/usr/bin/bash`. So a `forbid shell:exec` on `sh` did not stop `sh FILE`, and the decision changed
with the operator's host. The move to the upstream Shell made the decision `shell:exec` on `sh`,
but no test pins it. A Box test still has a `shell:spawn` permit for `sh` and a `[tool.sh]` table,
because it thinks that the host `sh` runs the file. The user docs do not list `sh` as a Shell
interpreter.
## Solution
- Add `sh_script_admission.rs`. It records each decision and each call to the host spawner for
`sh FILE`, `lash FILE`, `/bin/sh FILE`, a `#!/bin/sh` script in the memory filesystem, and a
refused `sh`. It declares `sh` and `lash` as the host `/bin/sh`, so a decision that reached the
host lookup gives a spawn on every host, with or without `sh` on `PATH`.
- Add a `programs` passthrough to the shell test support builder.
- Remove the `shell:spawn` permit and the `[tool.sh]` table from
`a_program_the_box_never_saw_behaves_like_a_unix_program`. `PERMISSIVE` is sufficient.
- List `sh` and `lash` as interpreters in `docs/user/shell.md`.
No product code and no interface change.
## Tests
- `sh_script_admission.rs`: 5 tests pass. Each one asserts the decisions and that the host spawner
ran nothing. They also pass with `PATH=/nonexistent`.
- Proof that the guard fires: `check_command` was changed to send `sh` and `lash` through
`check_fallback`, which is the reported defect. All 5 tests failed (`[Spawn("/bin/sh"), ...]`, and
status 0 in place of 126). The change was then removed.
- `box_programs.rs`: 22 passed, 2 ignored, with `PERMISSIVE` only.
- `cargo test -p strands-box-shell --all-features`: 135 passed.
- `cargo test -p strands-box --all-features --no-fail-fast`: 1618 passed. Two `data_volume` unit
tests fail when `TMPDIR` is on `/Volumes/workplace`, and pass with the default `TMPDIR`.
- `site_manifest`: 27 passed. Clippy has no warnings in the changed crates. `fmt --check` is clean.
- Run on macOS only. Not run: Linux, `test-integ`, and `scripts/test-all.sh`.
Not in scope: `sh` with no file and `echo CMD | sh` give status 0 and do nothing. This is an
upstream Shell defect. A `#!/bin/sh` script in a home or the workspace is a program named by a
path, so `shell:spawn` decides it.
…nce test, and document that sh and lash are two policy names
…name when called by its /bin/ path
3a28341 to
e873a38
Compare
|
Assessment: Comment Re-review at The only open item is still the Checked at this head, and held
|
One conflict, in docs/user/shell.md: main rewrote the interpreters line to cover sh and lash (#472), and this branch added that python and python3 are external programs with monty = false. The resolved line keeps both.
Brings the containment fix that permits kill and rt_sigtimedwait for a workload that runs an init such as tini (dc1d8e8). Without it a workload started under tini dies at start. The fix branch sits on upstream 5ed679f (the v0.2.3 release commit), so this merge also brings in the four upstream commits after 941fd27, the base of dogfood/main: - e8b4ced docs(design): add path locations design doc (strands-agents#461) - aa18761 test(shell): pin that `sh FILE` is decided as `shell:exec` on `sh` (strands-agents#472) - 1ccd68a feat: add Linux x86-64 release downloads (strands-agents#475) - 5ed679f feat: add Linux filesystem policy operations (strands-agents#193) No conflicts. Git merged crates/box/{AGENTS.md,Cargo.toml}, crates/box/src/command/run.rs, crates/box/src/record/config/mod.rs, crates/box/src/run/contain/boundary.rs, crates/box/src/run/hosted.rs and docs/user/native-filesystem-policy.md automatically.
Description
Human readable section
Problem: When an agent runs
sh FILE, Box asked policy about the wrong program. It looked upshon the host and asked whether that host program (for example/usr/bin/bash) may start. But the hostshnever started. The Shell read the file and ran it itself. So a policy rule that forbidsshdid not stopsh FILE, and the answer could change from one machine to another.Solution: #414 already fixed the behaviour: Box now knows that
shandlashare the Shell's own programs, so it asks policy aboutshas a program the Shell runs (shell:exec). This PR adds tests that check both the decision and that no host program starts. The tests fail if the old behaviour comes back. It also fixes a Box test that wrongly relied on the hostsh(it now runs a real host program in its own sandbox), and listsshandlashin the user docs, with the policy names each one gets. No product code changes.Trade-off: Policies now see
sh FILEasshell:exec. A policy with a broadshell:execpermit now allowssh FILE, the same as. FILE, and aforbid shell:spawnon/bin/shno longer matches it. To block it, forbidshell:execwherecontext.input.programis"sh"or"lash". Policy sees them as two names, and/bin/shand/bin/lashappear asshandlash. This change shipped with #414 and needs maintainer sign-off.Details
sh FILEandlash FILErun the file in the Shell, and no host program starts. An earlier Shell decidedsh FILEasshell:spawnon the hostshthatPATHfound, such as/usr/bin/bash. So aforbid shell:execonshdid not stopsh FILE, and the action that governed the command depended on the operator's host.The move to the upstream Shell (#414) already decides
sh FILEasshell:execonsh. This PR adds no product code. It pins that decision, and it removes the two places that still assumed the old behaviour:sh_script_admission.rsrecords each decision and each host-spawner call forsh FILE,lash FILE,/bin/sh FILE, a#!/bin/shscript in the memory filesystem, and a refusedsh. It declaresshandlashas the host/bin/sh, so the tests can fail on every host, including a host with noshonPATH.box_programs.rs::a_program_the_box_never_saw_behaves_like_a_unix_programransh FILEwith ashell:spawnpermit forshand a[tool.sh]table, because it believed the hostshran the script. The Shell ran it, so the grant hid the defect, and the test checked no host program. It now runs the script as a declared[tool.faketool], so it is decided asshell:spawnonfaketooland runs in its own sandbox. When the permit names another program, the test fails with status 126.docs/user/shell.mdlistsshandlashamong the interpreters the Shell implements. It says that policy sees them as two names, and that/bin/shand/bin/lashappear asshandlash.Policy-visible behaviour. The change already shipped in #414, and this PR does not change it. Operators should know about it:
shell:execpermit and no spawn permit) refusedsh FILEbefore refactor(shell): migrate Box to upstream Strands Shell #414 and allow it now. That is the same reach as. FILE.forbid shell:spawnaimed at/bin/shno longer matchessh FILE. Useforbid shell:execoncontext.input.program == "sh".Scope limits.
#!/bin/shscript in a home or the workspace is a program named by a path, soshell:spawnstill decides it. Onlysh FILE,/bin/sh FILE, and a script in the memory filesystem run in the Shell.shwith no file andecho CMD | shgive status 0 and run nothing. That is an upstream Shell defect, and this PR does not fix it.Related Issues
Internal security finding:
sh FILEwas decided asshell:spawnon a host program that never ran.Type of Change
Bug fix (regression tests and docs for a fix that landed in #414)
Testing
sh_script_admission.rs: 7 passed, also withPATH=/nonexistent. They include/bin/lash FILEand a rule onshalone that does not refuselash.Guard proof:
check_commandwas made to sendsh/lashthroughcheck_fallback, which is the reported defect. All 5 tests failed ([Spawn("/bin/sh"), Exec("echo")], and status0in place of126). The change was then reverted.cargo test -p strands-box-shell --all-features: 137 passed.cargo test -p strands-box --all-features --no-fail-fast: 1618 passed. Twodata_volumeunit tests fail only whenTMPDIRis on a non-root volume, and pass with the defaultTMPDIR.box_programs: 22 passed, 2 ignored.site_manifest: 27 passed.cargo clippy --all-targets --all-features: no warnings in the changed crates.cargo fmt --checkis clean.Checked on macOS only. Linux,
test-integ, andscripts/test-all.shdid not run here and are left to CI.I ran the relevant suites (
cargo test -p strands-box-shell -p strands-box --all-features)If I touched Rust, I ran
cargo fmtandcargo clippy --all-targets --all-featureson the changed cratesChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.