Support multiple GitHub SSH deploy keys (#568)

* add sshPublicKeysDirectoryPath and GIT_CONFIG_EXTENSIONS parameters that adds git configs and mounts .ssh/config and public keys to the container, in order to allow multiple sh deploy key trick by webplatform@ssh-agent

* remove sshPublicKeysDirectoryPath and GIT_CONFIG_EXTENSIONS from windows runner for now
This commit is contained in:
Ely Ronnen 2023-09-07 00:35:24 +03:00 committed by GitHub
parent a073719c29
commit 2190fd5667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 2 deletions

View File

@ -85,6 +85,10 @@ inputs:
required: false required: false
default: '' default: ''
description: 'SSH Agent path to forward to the container' description: 'SSH Agent path to forward to the container'
sshPublicKeysDirectoryPath:
required: false
default: ''
description: 'Path to a directory containing SSH public keys to forward to the container.'
gitPrivateToken: gitPrivateToken:
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

@ -10,6 +10,7 @@ mkdir -p "$ACTIVATE_LICENSE_PATH"
# #
# Run steps # Run steps
# #
source /steps/set_extra_git_configs.sh
source /steps/set_gitcredential.sh source /steps/set_gitcredential.sh
source /steps/activate.sh source /steps/activate.sh
source /steps/build.sh source /steps/build.sh

View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
if [ -z "${GIT_CONFIG_EXTENSIONS}" ]
then
echo "GIT_CONFIG_EXTENSIONS unset skipping"
else
echo "GIT_CONFIG_EXTENSIONS is set configuring extra git configs"
IFS=$'\n'
for config in $(echo "${GIT_CONFIG_EXTENSIONS}" | sed 's/\(.*\)=\(.*\)/"\1" "\2"/g'); do
if [[ $config =~ \"([^\"]+)\"\ \"([^\"]+)\" ]]; then
key="${BASH_REMATCH[1]}"
value="${BASH_REMATCH[2]}"
else
echo "Error parsing config: $config"
exit 1
fi
echo "Adding extra git config: \"$key\" = \"$value\""
git config --global --add "$key" "$value"
done
unset IFS
fi
echo "---------- git config --list -------------"
git config --list
echo "---------- git config --list --show-origin -------------"
git config --list --show-origin

View File

@ -42,6 +42,7 @@ class BuildParameters {
public customParameters!: string; public customParameters!: string;
public sshAgent!: string; public sshAgent!: string;
public sshPublicKeysDirectoryPath!: string;
public providerStrategy!: string; public providerStrategy!: string;
public gitPrivateToken!: string; public gitPrivateToken!: string;
public awsStackName!: string; public awsStackName!: string;
@ -150,6 +151,7 @@ class BuildParameters {
androidSymbolType: androidSymbolExportType, androidSymbolType: androidSymbolExportType,
customParameters: Input.customParameters, customParameters: Input.customParameters,
sshAgent: Input.sshAgent, sshAgent: Input.sshAgent,
sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath,
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()), gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
chownFilesTo: Input.chownFilesTo, chownFilesTo: Input.chownFilesTo,
providerStrategy: CloudRunnerOptions.providerStrategy, providerStrategy: CloudRunnerOptions.providerStrategy,

View File

@ -40,7 +40,15 @@ class Docker {
additionalVariables: StringKeyValuePair[] = [], additionalVariables: StringKeyValuePair[] = [],
entrypointBash: boolean = false, entrypointBash: boolean = false,
): string { ): string {
const { workspace, actionFolder, runnerTempPath, sshAgent, gitPrivateToken, dockerWorkspacePath } = parameters; const {
workspace,
actionFolder,
runnerTempPath,
sshAgent,
sshPublicKeysDirectoryPath,
gitPrivateToken,
dockerWorkspacePath,
} = parameters;
const githubHome = path.join(runnerTempPath, '_github_home'); const githubHome = path.join(runnerTempPath, '_github_home');
if (!existsSync(githubHome)) mkdirSync(githubHome); if (!existsSync(githubHome)) mkdirSync(githubHome);
@ -54,6 +62,7 @@ class Docker {
${ImageEnvironmentFactory.getEnvVarString(parameters, additionalVariables)} \ ${ImageEnvironmentFactory.getEnvVarString(parameters, additionalVariables)} \
--env UNITY_SERIAL \ --env UNITY_SERIAL \
--env GITHUB_WORKSPACE=${dockerWorkspacePath} \ --env GITHUB_WORKSPACE=${dockerWorkspacePath} \
--env GIT_CONFIG_EXTENSIONS \
${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \ ${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \ ${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "${githubHome}":"/root:z" \ --volume "${githubHome}":"/root:z" \
@ -64,7 +73,12 @@ class Docker {
--volume "${actionFolder}/platforms/ubuntu/entrypoint.sh:/entrypoint.sh:z" \ --volume "${actionFolder}/platforms/ubuntu/entrypoint.sh:/entrypoint.sh:z" \
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \ --volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \ ${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \ ${
sshAgent && !sshPublicKeysDirectoryPath
? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro'
: ''
} \
${sshPublicKeysDirectoryPath ? `--volume ${sshPublicKeysDirectoryPath}:/root/.ssh:ro` : ''} \
${entrypointBash ? `--entrypoint ${commandPrefix}` : ``} \ ${entrypointBash ? `--entrypoint ${commandPrefix}` : ``} \
${image} \ ${image} \
${entrypointBash ? `-c` : `${commandPrefix} -c`} \ ${entrypointBash ? `-c` : `${commandPrefix} -c`} \

View File

@ -178,6 +178,10 @@ class Input {
return Input.getInput('sshAgent') || ''; return Input.getInput('sshAgent') || '';
} }
static get sshPublicKeysDirectoryPath(): string {
return Input.getInput('sshPublicKeysDirectoryPath') || '';
}
static get gitPrivateToken(): string | undefined { static get gitPrivateToken(): string | undefined {
return Input.getInput('gitPrivateToken'); return Input.getInput('gitPrivateToken');
} }