From 1cd9cd394893206bc96fb72cfdbe5b3c5c288530 Mon Sep 17 00:00:00 2001 From: Shaun M Date: Tue, 21 Dec 2021 01:59:18 -0600 Subject: [PATCH] fix: add --preserve-env to start-runner.sh to enable RUNNER_ALLOW_RUNASROOT (#1537) --- modules/runners/templates/start-runner.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/runners/templates/start-runner.sh b/modules/runners/templates/start-runner.sh index 38422e6440..958eb81768 100644 --- a/modules/runners/templates/start-runner.sh +++ b/modules/runners/templates/start-runner.sh @@ -54,8 +54,12 @@ if [ -z "$run_as" ]; then run_as="ec2-user" fi +if [[ "$run_as" == "root" ]]; then + export RUNNER_ALLOW_RUNASROOT=1 +fi + echo "Configure GH Runner as user $run_as" -sudo -u "$run_as" -- ./config.sh --unattended --name "$instance_id" --work "_work" $${config} +sudo --preserve-env=RUNNER_ALLOW_RUNASROOT -u "$run_as" -- ./config.sh --unattended --name "$instance_id" --work "_work" $${config} ## Start the runner echo "Starting runner after $(awk '{print int($1/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime)" @@ -63,7 +67,7 @@ echo "Starting the runner as user $run_as" if [[ $agent_mode = "ephemeral" ]]; then echo "Starting the runner in ephemeral mode" - sudo -u "$run_as" -- ./run.sh + sudo --preserve-env=RUNNER_ALLOW_RUNASROOT -u "$run_as" -- ./run.sh echo "Runner has finished" echo "Stopping cloudwatch service"