Skip to content

Commit 682ffe1

Browse files
committed
fix(sandbox): derive the sandbox PATH from the runner's PATH
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
1 parent e127227 commit 682ffe1

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

‎proxy/setup-sandbox.sh‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,59 @@ fi
9191
# through sudo into the sandbox — uv would then write its receipt/cache and any
9292
# XDG-aware tool its config under the runner's home, which the sandbox UID can't.
9393
AGENT_ENV_FILE="${RUNNER_TEMP}/tend-agent-env"
94+
# Derive the sandbox PATH from the runner's own PATH rather than hardcoding a
95+
# base set. setup-sandbox.sh runs as the privileged `runner` user, so $PATH
96+
# here already holds every toolchain dir the runner image put on PATH — the
97+
# /etc/skel-seeded language homes (.cargo/bin, .dotnet/tools, .config/composer/
98+
# vendor/bin, …) plus system dirs (/opt/pipx_bin, /usr/local/.ghcup/bin,
99+
# /usr/bin, …). `useradd -m` copied /etc/skel into the sandbox's OWN home, so
100+
# each runner-home toolchain has a sibling under ${AGENT_HOME}. We translate by
101+
# rewriting a leading ${runner_home} -> ${AGENT_HOME} and keeping the entry only
102+
# when it now exists and the sandbox UID can traverse it. This pulls every
103+
# seeded toolchain across with zero per-language code — cargo, dotnet, ghcup,
104+
# composer all arrive on the same rule, so there is no per-language allowlist to
105+
# grow.
106+
#
107+
# Security boundary: we only ever rewrite runner-home prefixes to the sandbox's
108+
# own copies and never keep a /home/runner path on the sandbox PATH — the runner
109+
# home is where the real credentials live, so the sandbox must not traverse it.
110+
# A bare ${runner_home} entry is dropped, and every kept dir is re-tested with
111+
# `sudo -u "$SANDBOX" test -x` so an un-rewritten runner-home path (which the
112+
# sandbox UID can't enter) can never survive.
113+
#
114+
# (Tools an adopter installs at runtime in a `setup:` step land in the runner's
115+
# home, not /etc/skel, so they're absent from the sandbox home and this rewrite
116+
# finds nothing to point at — reaching those still needs the sandbox-setup lever
117+
# tracked in #766.)
118+
runner_home="${HOME:-/home/runner}"
119+
declare -A _seen_path=()
120+
declare -a _agent_path=("${AGENT_HOME}/.local/bin")
121+
_seen_path["${AGENT_HOME}/.local/bin"]=1
122+
IFS=: read -ra _runner_path <<<"${PATH}"
123+
for _d in "${_runner_path[@]}"; do
124+
[ -n "${_d}" ] || continue
125+
if [ -n "${runner_home}" ]; then
126+
case "${_d}" in
127+
"${runner_home}") continue ;; # never expose the runner home root
128+
"${runner_home}"/*) _d="${AGENT_HOME}/${_d#"${runner_home}"/}" ;; # rewrite to the sandbox's own copy
129+
esac
130+
fi
131+
[ -n "${_seen_path[${_d}]:-}" ] && continue # dedup
132+
if [ -d "${_d}" ] && sudo -u "${SANDBOX}" test -x "${_d}"; then
133+
_agent_path+=("${_d}")
134+
_seen_path["${_d}"]=1
135+
fi
136+
done
137+
# Guarantee the base system dirs even if the runner PATH somehow lacks them.
138+
for _d in /usr/local/bin /usr/bin /bin; do
139+
[ -n "${_seen_path[${_d}]:-}" ] && continue
140+
_agent_path+=("${_d}")
141+
_seen_path["${_d}"]=1
142+
done
143+
AGENT_PATH="$(IFS=:; printf '%s' "${_agent_path[*]}")"
94144
cat >"$AGENT_ENV_FILE" <<EOF
95145
HOME=${AGENT_HOME}
96-
PATH=${AGENT_HOME}/.local/bin:/usr/local/bin:/usr/bin:/bin
146+
PATH=${AGENT_PATH}
97147
XDG_CONFIG_HOME=${AGENT_HOME}/.config
98148
XDG_CACHE_HOME=${AGENT_HOME}/.cache
99149
XDG_DATA_HOME=${AGENT_HOME}/.local/share

0 commit comments

Comments
 (0)