Skip to content

Commit e150b2d

Browse files
jmcteHephaestus
authored andcommitted
Scrub runner auth before job pipeline
1 parent 55aebf0 commit e150b2d

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

docker/runner-entrypoint.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ runner_configured="false"
1010
runner_exit_code=0
1111
runner_exec_mode="runner"
1212
RUNNER_AUDIT_DEREGISTER_EVENT="runner_deregistered"
13+
github_pat_for_cleanup=""
14+
github_app_id_for_cleanup=""
15+
github_app_installation_id_for_cleanup=""
16+
github_app_private_key_for_cleanup=""
1317

1418
run_runner_bash() {
1519
local command="$1"
@@ -81,7 +85,23 @@ prepare_runner_home() {
8185
}
8286

8387
cleanup_runner() {
88+
export GITHUB_PAT="${github_pat_for_cleanup}"
89+
export GITHUB_APP_ID="${github_app_id_for_cleanup}"
90+
export GITHUB_APP_INSTALLATION_ID="${github_app_installation_id_for_cleanup}"
91+
export GITHUB_APP_PRIVATE_KEY="${github_app_private_key_for_cleanup}"
8492
cleanup_runner_registration "run_runner_bash \"cd '${RUNNER_HOME}' && ./config.sh remove --token \\\"\\\${RUNNER_REMOVE_TOKEN}\\\"\""
93+
unset GITHUB_PAT GITHUB_APP_ID GITHUB_APP_INSTALLATION_ID GITHUB_APP_PRIVATE_KEY
94+
}
95+
96+
stash_github_auth_for_cleanup() {
97+
github_pat_for_cleanup="${GITHUB_PAT:-}"
98+
github_app_id_for_cleanup="${GITHUB_APP_ID:-}"
99+
github_app_installation_id_for_cleanup="${GITHUB_APP_INSTALLATION_ID:-}"
100+
github_app_private_key_for_cleanup="${GITHUB_APP_PRIVATE_KEY:-}"
101+
}
102+
103+
scrub_github_auth_env() {
104+
unset GITHUB_PAT GITHUB_APP_ID GITHUB_APP_INSTALLATION_ID GITHUB_APP_PRIVATE_KEY
85105
}
86106

87107
prepare_runtime_dirs() {
@@ -165,6 +185,7 @@ trap on_exit EXIT
165185
trap 'log "termination requested"; RUNNER_AUDIT_DEREGISTER_EVENT="runner_evicted"; export RUNNER_AUDIT_DEREGISTER_EVENT; exit 0' TERM INT
166186

167187
require_github_auth
188+
stash_github_auth_for_cleanup
168189
require_env GITHUB_ORG
169190
require_env RUNNER_NAME
170191
require_env RUNNER_LABELS
@@ -279,5 +300,6 @@ runner_configured="true"
279300
audit_event runner_registered
280301

281302
log "starting runner ${RUNNER_NAME}"
303+
scrub_github_auth_env
282304
run_runner_job_bash "cd '${RUNNER_HOME}' && exec ./run.sh" \
283305
2>&1 | tee -a "${RUNNER_LOG_DIR}/runner.log"

scripts/smoke-test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ run_smoke_case() {
182182
grep -q "config path: /tmp/runner-state/runner-home" "${state_dir}/config-context.log"
183183
grep -q "run path: /tmp/runner-state/runner-home" "${state_dir}/run-context.log"
184184
grep -q "github auth: unset" "${state_dir}/run-context.log"
185+
grep -q "process github auth: unset" "${state_dir}/run-context.log"
185186
grep -q "runner writable home: /tmp/runner-state/runner-home" "${runner_stdout}"
186187
grep -q "^job output$" "${state_dir}/logs/runner.log"
187188
grep -q "run.sh stub executed" "${state_dir}/run.log"

scripts/smoke/actions-runner/run.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ if [[ -n "${GITHUB_PAT:-}" \
1212
exit 1
1313
fi
1414
printf 'github auth: unset\n' >> "${RUNNER_STATE_DIR}/run-context.log"
15+
if [[ "$(id -u)" == "0" ]]; then
16+
for environ in /proc/[0-9]*/environ; do
17+
[[ -r "${environ}" ]] || continue
18+
if tr '\0' '\n' < "${environ}" | grep -Eq '^(GITHUB_PAT|GITHUB_APP_ID|GITHUB_APP_INSTALLATION_ID|GITHUB_APP_PRIVATE_KEY)='; then
19+
printf 'github auth visible in process env: %s\n' "${environ}" >> "${RUNNER_STATE_DIR}/run-context.log"
20+
exit 1
21+
fi
22+
done
23+
fi
24+
printf 'process github auth: unset\n' >> "${RUNNER_STATE_DIR}/run-context.log"
1525
mkdir -p "${RUNNER_WORK_DIR}/workspace"
1626
touch "${RUNNER_WORK_DIR}/workspace/job.txt"
1727
echo "job output"

0 commit comments

Comments
 (0)