Skip to content

Commit fda43f9

Browse files
committed
fix(sandbox): correct PATH security comment, adopter precedence, drop 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).
1 parent 5c5fb7c commit fda43f9

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

‎proxy/setup-sandbox.sh‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,38 +128,44 @@ AGENT_ENV_FILE="${RUNNER_TEMP}/tend-agent-env"
128128
# composer all arrive on the same rule, so there is no per-language allowlist to
129129
# grow.
130130
#
131-
# Security boundary: we only ever rewrite runner-home prefixes to the sandbox's
132-
# own copies and never keep a /home/runner path on the sandbox PATH — the runner
133-
# home is where the real credentials live, so the sandbox must not traverse it.
134-
# A bare ${runner_home} entry is dropped, and every kept dir is re-tested with
135-
# `sudo -u "$SANDBOX" test -x` so an un-rewritten runner-home path (which the
136-
# sandbox UID can't enter) can never survive.
131+
# Security boundary: the `case` rewrite below is the SOLE credential boundary. It
132+
# maps every runner-home prefix to the sandbox's own copy and drops the bare
133+
# runner-home root, so no /home/runner path ever reaches the sandbox PATH — and
134+
# the runner home is where the real credentials live. Do NOT relax that rewrite
135+
# trusting the `sudo -u "$SANDBOX" test -x` below as a backstop: it is not one.
136+
# Step 3 grants o+x on every ancestor of $GITHUB_WORKSPACE (which lives under the
137+
# runner home), so the sandbox UID can traverse /home/runner and `test -x` passes
138+
# for any world-executable dir beneath it. That test only filters nonexistent or
139+
# non-traversable dirs; an un-rewritten runner-home path would sail through it.
137140
#
138141
# (Tools an adopter installs at runtime in a `setup:` step land in the runner's
139142
# home, not /etc/skel, so they're absent from the sandbox home and this rewrite
140143
# finds nothing to point at — reaching those is what the `sandbox_path:` lever
141144
# above is for.)
142145
runner_home="${HOME:-/home/runner}"
143146
declare -A _seen_path=()
144-
declare -a _agent_path=("${AGENT_HOME}/.local/bin")
145-
_seen_path["${AGENT_HOME}/.local/bin"]=1
146-
# Adopter-declared dirs win over the auto-derived toolchains: prepend them
147-
# verbatim (trusted opt-in, so not existence-tested like the derived entries
148-
# below — the dir may be populated by a later `setup:` step).
147+
declare -a _agent_path=()
148+
# Adopter-declared dirs win over everything, .local/bin included: prepend them
149+
# first and verbatim (trusted opt-in, so not existence-tested like the derived
150+
# entries below — the dir may be populated by a later `setup:` step) so an
151+
# adopter dir can shadow a same-named binary in .local/bin.
149152
for _d in ${_extra_path[@]+"${_extra_path[@]}"}; do
150153
[ -n "${_seen_path[${_d}]:-}" ] && continue
151154
_agent_path+=("${_d}")
152155
_seen_path["${_d}"]=1
153156
done
157+
# .local/bin next, ahead of the auto-derived toolchains below.
158+
if [ -z "${_seen_path["${AGENT_HOME}/.local/bin"]:-}" ]; then
159+
_agent_path+=("${AGENT_HOME}/.local/bin")
160+
_seen_path["${AGENT_HOME}/.local/bin"]=1
161+
fi
154162
IFS=: read -ra _runner_path <<<"${PATH}"
155163
for _d in "${_runner_path[@]}"; do
156164
[ -n "${_d}" ] || continue
157-
if [ -n "${runner_home}" ]; then
158-
case "${_d}" in
159-
"${runner_home}") continue ;; # never expose the runner home root
160-
"${runner_home}"/*) _d="${AGENT_HOME}/${_d#"${runner_home}"/}" ;; # rewrite to the sandbox's own copy
161-
esac
162-
fi
165+
case "${_d}" in
166+
"${runner_home}") continue ;; # never expose the runner home root
167+
"${runner_home}"/*) _d="${AGENT_HOME}/${_d#"${runner_home}"/}" ;; # rewrite to the sandbox's own copy
168+
esac
163169
[ -n "${_seen_path[${_d}]:-}" ] && continue # dedup
164170
if [ -d "${_d}" ] && sudo -u "${SANDBOX}" test -x "${_d}"; then
165171
_agent_path+=("${_d}")

0 commit comments

Comments
 (0)