Repository navigation
fix(sandbox): derive the sandbox PATH from the runner's PATH - #767
Conversation
|
is |
|
Good challenge — and checking it live, you're right to be wary. The GitHub runner image seeds a batch of toolchain homes into Verified in the sandbox (
|
yes, right is there a way we can bring all.the pathe entries in from outside the sandbox? |
|
Yes — and it lands cleanly because of where The translation is a home-prefix rewrite: for each entry, rewrite a leading runner_home="$HOME" # setup runs as runner
declare -a keep=()
IFS=: read -ra dirs <<<"$PATH"
for d in "${dirs[@]}"; do
case "$d" in "$runner_home"/*) d="${AGENT_HOME}/${d#"$runner_home"/}";; esac
[ -d "$d" ] && sudo -u "$SANDBOX" test -x "$d" && keep+=("$d")
done
AGENT_PATH="${AGENT_HOME}/.local/bin:$(IFS=:; echo "${keep[*]}"):/usr/local/bin:/usr/bin:/bin"That pulls every seeded toolchain across with zero per-language code — cargo, dotnet, ghcup, nvm all come in on the same rule, and the "why cargo but not X" objection disappears. One security line we must not cross. This works precisely because What it still won't reach (same gap as this PR, just now general instead of cargo-only): tools an adopter installs at runtime in a I'm happy to rewrite this branch to the PATH-derivation above and drop the cargo special-case — it's strictly better than the current diff. Want me to push that here? |
|
yes great, thx |
setup-sandbox.sh runs as the runner user, whose PATH already lists every toolchain dir the runner image seeded — /etc/skel language homes (.cargo/bin, .dotnet/tools, .config/composer/vendor/bin, …) plus system dirs (/opt/pipx_bin, /usr/local/.ghcup/bin, …). useradd -m copies /etc/skel into the sandbox's own home, so each runner-home toolchain has a sibling under the sandbox home. Rewrite a leading /home/runner -> the sandbox home for each PATH entry and keep it only when it now exists and the sandbox UID can traverse it, instead of hardcoding a base set with per-language special cases. This brings every seeded toolchain (cargo, dotnet, ghcup, composer, …) across on one rule — no per-language allowlist to grow. Security: only runner-home prefixes are rewritten to the sandbox's own copies; a raw /home/runner path is never kept (bare home dropped, every kept dir re-tested with `sudo -u sandbox test -x`), so the sandbox still cannot traverse the runner home where the real credentials live. Tools an adopter installs at runtime in a setup: step land in the runner's home, not /etc/skel, so they're absent from the sandbox home and this rewrite finds nothing to point at — reaching those still needs the sandbox-setup lever in #766. Refs #766
449135f to
682ffe1
Compare
|
Done — rewrote the branch to derive the sandbox PATH from the runner's PATH and dropped the cargo special-case (682ffe1). Since So the rule is: rewrite a leading The security line holds: only runner-home prefixes get rewritten to the sandbox's own copies, and a raw Still |
tend-agent
left a comment
There was a problem hiding this comment.
The derivation logic itself is correct and secure for the target environment — I traced it (set -e/-u safe, dedup works, .local/bin stays first, empties/nonexistent/dups filtered) and simulated it against a synthetic runner PATH. The string rewrite catches every /home/runner/* entry because $HOME is exactly /home/runner on hosted runners, so no runner-home path is ever kept raw.
One correction on the security comment, though: it credits the sudo -u "$SANDBOX" test -x check as a backstop against un-rewritten runner-home paths "which the sandbox UID can't enter." The sandbox UID can enter /home/runner — it's mode 0751 (drwxr-x--x, the o+x/traversal bit is set by default), and step 3 later chmods it further. So test -x /home/runner/<dir> would pass for the sandbox, and a hypothetical un-rewritten runner-home dir would not be dropped by that check. The -d/test -x gate only filters entries that don't exist or aren't executable; the actual credential boundary is entirely the string rewrite (rewrite every prefix, drop the bare root). Worth correcting so a future change doesn't relax the rewrite trusting test -x to catch the leak.
Inline suggestion below.
|
@tend-agent resolve conflicts |
Resolve the setup-sandbox.sh PATH conflict by combining both levers: the adopter's explicit sandbox_path (TEND_SANDBOX_PATH) is prepended so it wins, then the runner-PATH auto-derivation pulls in the /etc/skel-seeded toolchains. Adopter dirs dedup against the auto-derived rewrites. Also regenerate the stale test_sandbox_levers snapshot, which was left mismatched against the mention template on main by #762.
|
Resolved conflicts with main (5c5fb7c). The only real conflict was
I also updated the derivation's closing note: the runtime-installed-tool gap is now covered by the merged One thing worth flagging: |
|
@tend-agent Please make these changes:
Otherwise ready to merge: the derivation logic checks out and CI is green.
|
… dead guard
- Security comment: the case rewrite is the sole credential boundary;
test -x only filters nonexistent/non-traversable dirs, not un-rewritten
runner-home paths (step 3's o+x on workspace ancestors lets the sandbox
traverse /home/runner).
- Restore adopter precedence: prepend sandbox_path dirs ahead of
.local/bin so an adopter dir can shadow a same-named binary there.
- Drop the dead [ -n "${runner_home}" ] guard (:-} default is never empty).
|
All three done (fda43f9):
|
## Summary Version bump + CHANGELOG for 0.1.11. See [CHANGELOG.md](https://github.com/max-sixty/tend/blob/release/CHANGELOG.md#0111) for the full notes. 13 commits since 0.1.10: - Adopter sandbox levers (`sandbox_path`/`sandbox_env`/`sandbox_setup`, #768) - Sandbox `PATH` derived from the runner's own `PATH` (#767) - Invited upstream contributions (#770) - `tend-mention` self-comment no-op skip (#751) - Actionable self-review handling (#762, #775) - `tend-outage` dedup self-heal (#744) - Dropped-cron-tick recovery in `list-recent-runs` (#753) - Drop self-authored attribution sign-offs (#773) - Docs fixes (#776, #771) - `claude_version` bump (#774) ## Test plan - [x] `wt test` (275 passed) - [x] `pre-commit run --all-files` (all hooks passed) - [ ] CI green on this PR > _This was written by Claude Code on behalf of Maximilian Roos_
Automated nightly regeneration of tend's workflow files, picking up the upstream release. **tend version:** 0.1.10 → 0.1.11 **Notable changes** (consumer-relevant): - Skip no-op `tend-mention` sessions triggered by the bot's own comments — a new pre-mention guard in the generated `tend-mention.yaml` short-circuits before the engagement heuristics (max-sixty/tend#751). - Respond to actionable bot self-reviews instead of exiting as a self-loop: a review the review workflow leaves on its own PR is the bot's reviewer role, so it gets actioned rather than silently skipped (max-sixty/tend#762). - Sandbox: adopter levers to reach inside the Claude-family sandbox, and derive the sandbox `PATH` from the runner's `PATH` (max-sixty/tend#768, max-sixty/tend#767). - `running-in-ci`: permit maintainer-invited upstream contributions, and prohibit self-authored attribution sign-offs (max-sixty/tend#770, max-sixty/tend#773). - Action reliability: self-heal duplicate `tend-outage` issues from concurrent leg failures, and recover dropped cron ticks in list-recent-runs via a previous-run anchor (max-sixty/tend#744, max-sixty/tend#753). Compare: max-sixty/tend@0.1.10...0.1.11 Co-authored-by: worktrunk-bot <[email protected]>
Problem
The sandbox launches with a hardcoded PATH (
${AGENT_HOME}/.local/bin:/usr/local/bin:/usr/bin:/bin) that omits every toolchain the runner image seeds into user homes. A Rust adopter's first barecargo/rustcfails withcommand not found; so does a .NET adopter'sdotnet, a Haskell adopter'sghc, and so on. Hardcoding one dir per language (.cargo/bin, then.dotnet/tools, then.ghcup/bin, …) would be an implicit, ever-growing allowlist tend doesn't otherwise care about.Solution
Derive the sandbox PATH from the runner's own PATH instead of hardcoding a base set.
setup-sandbox.shruns as the privilegedrunneruser, so its$PATHalready lists every dir the runner image put on PATH — the/etc/skel-seeded language homes (.cargo/bin,.dotnet/tools,.config/composer/vendor/bin, …) plus system dirs (/opt/pipx_bin,/usr/local/.ghcup/bin,/usr/bin, …).useradd -mcopied/etc/skelinto the sandbox's own home, so each runner-home toolchain has a sibling under${AGENT_HOME}.The translation is a home-prefix rewrite: for each PATH entry, rewrite a leading
/home/runner→${AGENT_HOME}, and keep the entry only when it now exists and the sandbox UID can traverse it. Every seeded toolchain comes across on one rule — cargo, dotnet, ghcup, composer alike — with no per-language code and no allowlist to grow.Security boundary
This works precisely because the rewritten paths point at the sandbox's own copies of the seeded dirs. The rewrite only ever maps runner-home prefixes to
${AGENT_HOME}; a raw/home/runnerpath is never kept on the sandbox PATH:${runner_home}entry is dropped outright, andsudo -u "$SANDBOX" test -x— so any un-rewritten runner-home path, which the sandbox UID can't enter, can never survive.The runner home is where the real credentials live; the sandbox must not be able to traverse it. Rewrite prefixes, never widen access.
Scope / what this does not cover
Tools an adopter installs at runtime in a runner-side
setup:step (cargo-nextest,cargo-insta, …) land in the runner's home, not/etc/skel, so they're absent from the sandbox home and the rewrite finds nothing to point at. Reaching those still needs the general sandbox-setup lever tracked in #766. HenceRefs #766, notCloses.Testing
.local/binstays first, and the block isset -euo pipefail-safe./etc/environment's PATH is resolved (/home/runner/.cargo/bin, not literal$HOME/...), so the prefix rewrite matches, and that/etc/skelseeds.cargo/.dotnet/.ghcupinto the sandbox home.shellcheck -S warning proxy/setup-sandbox.shclean.Refs #766 — automated triage