Skip to content

Commit b8ce684

Browse files
authored
Merge pull request #384 from yamoyamoto/chore/unset-envs-before-launch-service
feat: Prevent exposure of configuration environment variables to runner workflows
2 parents ab85a5a + 35c099d commit b8ce684

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ These containers are built via Github actions that [copy the dockerfile](https:/
7373
| `NO_DEFAULT_LABELS` | Optional environment variable to disable adding the default self-hosted, platform, and architecture labels to the runner. Any value is considered truthy and will disable them. |
7474
| `DEBUG_ONLY` | Optional boolean to print debug output but not run any actual registration or runner commands. Used in CI and testing. Default: false |
7575
| `DEBUG_OUTPUT` | Optional boolean to print additional debug output. Default: false |
76-
76+
| `UNSET_CONFIG_VARS` | Optional flag to unset all configuration environment variables after runner setup but before starting the runner. This prevents these variables from leaking into the workflow environment. Set to 'true' to enable. Defaults to 'false' for backward compatibility. |
7777

7878
## Tests ##
7979

entrypoint.sh

+41-7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ _RUNNER_GROUP=${RUNNER_GROUP:-Default}
5757
_GITHUB_HOST=${GITHUB_HOST:="github.com"}
5858
_RUN_AS_ROOT=${RUN_AS_ROOT:="true"}
5959
_START_DOCKER_SERVICE=${START_DOCKER_SERVICE:="false"}
60+
_UNSET_CONFIG_VARS=${UNSET_CONFIG_VARS:="false"}
61+
_CONFIGURED_ACTIONS_RUNNER_FILES_DIR=${CONFIGURED_ACTIONS_RUNNER_FILES_DIR:-""}
6062

6163
# ensure backwards compatibility
6264
if [[ -z ${RUNNER_SCOPE} ]]; then
@@ -151,15 +153,42 @@ configure_runner() {
151153

152154
}
153155

156+
unset_config_vars() {
157+
echo "Unsetting configuration environment variables"
158+
unset RUN_AS_ROOT
159+
unset RUNNER_NAME
160+
unset RUNNER_NAME_PREFIX
161+
unset RANDOM_RUNNER_SUFFIX
162+
unset ACCESS_TOKEN
163+
unset APP_ID
164+
unset APP_PRIVATE_KEY
165+
unset APP_LOGIN
166+
unset RUNNER_SCOPE
167+
unset ORG_NAME
168+
unset ENTERPRISE_NAME
169+
unset LABELS
170+
unset REPO_URL
171+
unset RUNNER_TOKEN
172+
unset RUNNER_WORKDIR
173+
unset RUNNER_GROUP
174+
unset GITHUB_HOST
175+
unset DISABLE_AUTOMATIC_DEREGISTRATION
176+
unset CONFIGURED_ACTIONS_RUNNER_FILES_DIR
177+
unset EPHEMERAL
178+
unset DISABLE_AUTO_UPDATE
179+
unset START_DOCKER_SERVICE
180+
unset NO_DEFAULT_LABELS
181+
unset UNSET_CONFIG_VARS
182+
}
154183

155184
# Opt into runner reusage because a value was given
156-
if [[ -n "${CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]]; then
185+
if [[ -n "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]]; then
157186
echo "Runner reusage is enabled"
158187

159188
# directory exists, copy the data
160-
if [[ -d "${CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]]; then
189+
if [[ -d "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]]; then
161190
echo "Copying previous data"
162-
cp -p -r "${CONFIGURED_ACTIONS_RUNNER_FILES_DIR}/." "/actions-runner"
191+
cp -p -r "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}/." "/actions-runner"
163192
fi
164193

165194
if [ -f "/actions-runner/.runner" ]; then
@@ -177,10 +206,10 @@ else
177206
fi
178207
fi
179208

180-
if [[ -n "${CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]]; then
181-
echo "Reusage is enabled. Storing data to ${CONFIGURED_ACTIONS_RUNNER_FILES_DIR}"
209+
if [[ -n "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]]; then
210+
echo "Reusage is enabled. Storing data to ${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}"
182211
# Quoting (even with double-quotes) the regexp brokes the copying
183-
cp -p -r "/actions-runner/_diag" "/actions-runner/svc.sh" /actions-runner/.[^.]* "${CONFIGURED_ACTIONS_RUNNER_FILES_DIR}"
212+
cp -p -r "/actions-runner/_diag" "/actions-runner/svc.sh" /actions-runner/.[^.]* "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}"
184213
fi
185214

186215

@@ -204,6 +233,11 @@ if [[ ${_START_DOCKER_SERVICE} == "true" ]]; then
204233
fi
205234
fi
206235

236+
# Unset configuration environment variables if the flag is set
237+
if [[ ${_UNSET_CONFIG_VARS} == "true" ]]; then
238+
unset_config_vars
239+
fi
240+
207241
# Container's command (CMD) execution as runner user
208242

209243

@@ -235,7 +269,7 @@ if [[ ${_RUN_AS_ROOT} == "true" ]]; then
235269
fi
236270
else
237271
if [[ $(id -u) -eq 0 ]]; then
238-
[[ -n "${CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]] && chown -R runner "${CONFIGURED_ACTIONS_RUNNER_FILES_DIR}"
272+
[[ -n "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]] && chown -R runner "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}"
239273
chown -R runner "${_RUNNER_WORKDIR}" /actions-runner
240274
# The toolcache is not recursively chowned to avoid recursing over prepulated tooling in derived docker images
241275
chown runner /opt/hostedtoolcache/

0 commit comments

Comments
 (0)