Default to root user with option to use host user

This commit is contained in:
Andrew Kahr 2023-11-20 19:56:48 -08:00
parent 1921dc4e1b
commit 30b936fecb
7 changed files with 20 additions and 2 deletions

View File

@ -101,6 +101,12 @@ inputs:
required: false required: false
default: '' default: ''
description: '[CloudRunner] GitHub owner name or organization/team name' description: '[CloudRunner] GitHub owner name or organization/team name'
runAsHostUser:
required: false
default: 'false'
description:
'Whether to run as a user that matches the host system or the default root container user. Only applicable to
Linux hosts and containers. This is useful for fixing permission errors on Self-Hosted runners.'
chownFilesTo: chownFilesTo:
required: false required: false
default: '' default: ''

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -52,7 +52,12 @@ else
echo "Not updating Android SDK." echo "Not updating Android SDK."
fi fi
if [[ "RUN_AS_HOST_USER" == "true" ]]; then
# Switch to the host user so we can create files with the correct ownership # Switch to the host user so we can create files with the correct ownership
su $USERNAME -c "$SHELL -c 'source /steps/runsteps.sh'" su $USERNAME -c "$SHELL -c 'source /steps/runsteps.sh'"
else
# Run as root
source /steps/runsteps.sh
fi
exit $? exit $?

View File

@ -59,6 +59,7 @@ class BuildParameters {
public kubeVolumeSize!: string; public kubeVolumeSize!: string;
public kubeVolume!: string; public kubeVolume!: string;
public kubeStorageClass!: string; public kubeStorageClass!: string;
public runAsHostUser!: String;
public chownFilesTo!: string; public chownFilesTo!: string;
public commandHooks!: string; public commandHooks!: string;
public pullInputList!: string[]; public pullInputList!: string[];
@ -168,6 +169,7 @@ class BuildParameters {
sshAgent: Input.sshAgent, sshAgent: Input.sshAgent,
sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath, sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath,
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()), gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
runAsHostUser: Input.runAsHostUser,
chownFilesTo: Input.chownFilesTo, chownFilesTo: Input.chownFilesTo,
dockerCpuLimit: Input.dockerCpuLimit, dockerCpuLimit: Input.dockerCpuLimit,
dockerMemoryLimit: Input.dockerMemoryLimit, dockerMemoryLimit: Input.dockerMemoryLimit,

View File

@ -62,6 +62,7 @@ class ImageEnvironmentFactory {
{ name: 'ANDROID_EXPORT_TYPE', value: parameters.androidExportType }, { name: 'ANDROID_EXPORT_TYPE', value: parameters.androidExportType },
{ name: 'ANDROID_SYMBOL_TYPE', value: parameters.androidSymbolType }, { name: 'ANDROID_SYMBOL_TYPE', value: parameters.androidSymbolType },
{ name: 'CUSTOM_PARAMETERS', value: parameters.customParameters }, { name: 'CUSTOM_PARAMETERS', value: parameters.customParameters },
{ name: 'RUN_AS_HOST_USER', value: parameters.runAsHostUser },
{ name: 'CHOWN_FILES_TO', value: parameters.chownFilesTo }, { name: 'CHOWN_FILES_TO', value: parameters.chownFilesTo },
{ name: 'GITHUB_REF', value: process.env.GITHUB_REF }, { name: 'GITHUB_REF', value: process.env.GITHUB_REF },
{ name: 'GITHUB_SHA', value: process.env.GITHUB_SHA }, { name: 'GITHUB_SHA', value: process.env.GITHUB_SHA },

View File

@ -193,6 +193,10 @@ class Input {
return Input.getInput('gitPrivateToken'); return Input.getInput('gitPrivateToken');
} }
static get runAsHostUser(): string {
return Input.getInput('runAsHostUser') || 'false';
}
static get chownFilesTo() { static get chownFilesTo() {
return Input.getInput('chownFilesTo') || ''; return Input.getInput('chownFilesTo') || '';
} }