Skip to content

Commit 6b283d3

Browse files
kpturneresteve
authored andcommitted
Add ability to specify user
1 parent 46506b5 commit 6b283d3

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ inputs:
7070
description: >-
7171
Start the runner as a service rather than using ./run.sh as root.
7272
required: false
73+
run-runner-as-user:
74+
description: >-
75+
Specify user under whom the runner service should run
7376
outputs:
7477
label:
7578
description: >-

src/aws.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ function buildUserDataScript(githubRegistrationToken, label) {
1010
// to be pre-installed in the AMI, so we simply cd into that directory and then start the runner
1111
userData = [
1212
'#!/bin/bash',
13+
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
1314
`cd "${config.input.runnerHomeDir}"`,
1415
'export RUNNER_ALLOW_RUNASROOT=1',
1516
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
1617
];
1718
} else {
1819
userData = [
1920
'#!/bin/bash',
21+
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
2022
'mkdir actions-runner && cd actions-runner',
2123
'case $(uname -m) in aarch64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}',
2224
'curl -O -L https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-${RUNNER_ARCH}-2.299.1.tar.gz',
@@ -25,11 +27,14 @@ function buildUserDataScript(githubRegistrationToken, label) {
2527
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
2628
];
2729
}
30+
if (config.input.runAsUser) {
31+
userData.push(`chown -R ${config.input.runAsUser} ${config.input.runnerHomeDir}`);
32+
}
2833
if (config.input.runAsService) {
29-
userData.push('./svc.sh install');
34+
userData.push(`./svc.sh install ${config.input.runAsUser || ''}`);
3035
userData.push('./svc.sh start');
3136
} else {
32-
userData.push('./run.sh');
37+
userData.push(`${config.input.runAsUser ? `su ${config.input.runAsUser} -c` : ''} ./run.sh`);
3338
}
3439
return userData;
3540
}

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class Config {
1414
ec2InstanceId: core.getInput('ec2-instance-id'),
1515
iamRoleName: core.getInput('iam-role-name'),
1616
runnerHomeDir: core.getInput('runner-home-dir'),
17-
runAsService: core.getInput('run-runner-as-service')
17+
runAsService: core.getInput('run-runner-as-service') === 'true',
18+
runAsUser: core.getInput('run-runner-as-user')
1819
};
1920

2021
const tags = JSON.parse(core.getInput('aws-resource-tags'));

0 commit comments

Comments
 (0)