From 04c5c5378a840e9d3c782f2a9ac6056cbb083148 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 1 Nov 2022 21:39:52 +0000 Subject: [PATCH] Add ability to specify user --- action.yml | 3 +++ src/aws.js | 9 +++++++-- src/config.js | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 32a785c5..770a37b1 100644 --- a/action.yml +++ b/action.yml @@ -74,6 +74,9 @@ inputs: description: >- Start the runner as a service rather than using ./run.sh as root. required: false + run-runner-as-user: + description: >- + Specify user under whom the runner service should run outputs: label: description: >- diff --git a/src/aws.js b/src/aws.js index c7e2002a..90c390c6 100644 --- a/src/aws.js +++ b/src/aws.js @@ -10,6 +10,7 @@ function buildUserDataScript(githubRegistrationToken, label) { // to be pre-installed in the AMI, so we simply cd into that directory and then start the runner userData = [ '#!/bin/bash', + 'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1', `cd "${config.input.runnerHomeDir}"`, `echo "${config.input.preRunnerScript}" > pre-runner-script.sh`, 'source pre-runner-script.sh', @@ -19,6 +20,7 @@ function buildUserDataScript(githubRegistrationToken, label) { } else { userData = [ '#!/bin/bash', + 'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1', 'mkdir actions-runner && cd actions-runner', `echo "${config.input.preRunnerScript}" > pre-runner-script.sh`, 'source pre-runner-script.sh', @@ -29,11 +31,14 @@ function buildUserDataScript(githubRegistrationToken, label) { `./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`, ]; } + if (config.input.runAsUser) { + userData.push(`chown -R ${config.input.runAsUser} ${config.input.runnerHomeDir}`); + } if (config.input.runAsService) { - userData.push('./svc.sh install'); + userData.push(`./svc.sh install ${config.input.runAsUser || ''}`); userData.push('./svc.sh start'); } else { - userData.push('./run.sh'); + userData.push(`${config.input.runAsUser ? `su ${config.input.runAsUser} -c` : ''} ./run.sh`); } return userData; } diff --git a/src/config.js b/src/config.js index f9bc9d86..3b0f6011 100644 --- a/src/config.js +++ b/src/config.js @@ -15,7 +15,8 @@ class Config { iamRoleName: core.getInput('iam-role-name'), runnerHomeDir: core.getInput('runner-home-dir'), preRunnerScript: core.getInput('pre-runner-script'), - runAsService: core.getInput('run-runner-as-service') + runAsService: core.getInput('run-runner-as-service') === 'true', + runAsUser: core.getInput('run-runner-as-user') }; const tags = JSON.parse(core.getInput('aws-resource-tags'));