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 (#240)

pull/241/head v3
Ely Ronnen 2023-09-07 00:35:36 +03:00 committed by GitHub
parent 9d0bc623a7
commit 275df9854c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1258 additions and 1174 deletions

View File

@ -36,6 +36,10 @@ inputs:
required: false
default: ''
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:
required: false
default: ''

1
dist/entrypoint.sh vendored
View File

@ -12,6 +12,7 @@ mkdir -p "$ACTIVATE_LICENSE_PATH"
#
source /steps/activate.sh
source /steps/set_extra_git_configs.sh
source /steps/set_gitcredential.sh
source /steps/run_tests.sh
source /steps/return_license.sh

26
dist/index.js generated vendored
View File

@ -98,7 +98,7 @@ function run() {
try {
model_1.Action.checkCompatibility();
const { workspace, actionFolder } = model_1.Action;
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, packageMode, packageName, chownFilesTo, unityLicensingServer, } = model_1.Input.getFromUser();
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, sshPublicKeysDirectoryPath, gitPrivateToken, githubToken, checkName, packageMode, packageName, chownFilesTo, unityLicensingServer, } = model_1.Input.getFromUser();
const baseImage = new model_1.ImageTag({ editorVersion, customImage });
const runnerContext = model_1.Action.runnerContext();
try {
@ -112,6 +112,7 @@ function run() {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
packageMode,
packageName,
gitPrivateToken,
@ -262,7 +263,7 @@ const Docker = {
});
},
getLinuxCommand(image, parameters) {
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, sshPublicKeysDirectoryPath, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
if (!(0, fs_1.existsSync)(githubHome))
(0, fs_1.mkdirSync)(githubHome);
@ -307,6 +308,7 @@ const Docker = {
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
--env CHOWN_FILES_TO="${chownFilesTo}" \
--env GIT_CONFIG_EXTENSIONS \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "${githubHome}:/root:z" \
--volume "${githubWorkflow}:/github/workflow:z" \
@ -316,7 +318,12 @@ const Docker = {
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
${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`
: ''} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image} \
@ -572,6 +579,10 @@ const Input = {
const validFolderName = new RegExp(/^(\.|\.\/)?(\.?[\w~]+([ _-]?[\w~]+)*\/?)*$/);
return validFolderName.test(folderName);
},
isValidGlobalFolderName(folderName) {
const validFolderName = new RegExp(/^(\.|\.\/|\/)?(\.?[\w~]+([ _-]?[\w~]+)*\/?)*$/);
return validFolderName.test(folderName);
},
/**
* When in package mode, we need to scrape the package's name from its package.json file
*/
@ -619,6 +630,7 @@ const Input = {
const rawArtifactsPath = (0, core_1.getInput)('artifactsPath') || 'artifacts';
const rawUseHostNetwork = (0, core_1.getInput)('useHostNetwork') || 'false';
const sshAgent = (0, core_1.getInput)('sshAgent') || '';
const rawSshPublicKeysDirectoryPath = (0, core_1.getInput)('sshPublicKeysDirectoryPath') || '';
const gitPrivateToken = (0, core_1.getInput)('gitPrivateToken') || '';
const githubToken = (0, core_1.getInput)('githubToken') || '';
const checkName = (0, core_1.getInput)('checkName') || 'Test Results';
@ -635,12 +647,18 @@ const Input = {
if (!this.isValidFolderName(rawArtifactsPath)) {
throw new Error(`Invalid artifactsPath "${rawArtifactsPath}"`);
}
if (!this.isValidGlobalFolderName(rawSshPublicKeysDirectoryPath)) {
throw new Error(`Invalid sshPublicKeysDirectoryPath "${rawSshPublicKeysDirectoryPath}"`);
}
if (rawUseHostNetwork !== 'true' && rawUseHostNetwork !== 'false') {
throw new Error(`Invalid useHostNetwork "${rawUseHostNetwork}"`);
}
if (rawPackageMode !== 'true' && rawPackageMode !== 'false') {
throw new Error(`Invalid packageMode "${rawPackageMode}"`);
}
if (rawSshPublicKeysDirectoryPath !== '' && sshAgent === '') {
throw new Error('sshPublicKeysDirectoryPath is set, but sshAgent is not set. sshPublicKeysDirectoryPath is useful only when using sshAgent.');
}
// sanitize packageMode input and projectPath input since they are needed
// for input validation
const packageMode = rawPackageMode === 'true';
@ -655,6 +673,7 @@ const Input = {
}
// Sanitise other input
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
const sshPublicKeysDirectoryPath = rawSshPublicKeysDirectoryPath.replace(/\/$/, '');
const useHostNetwork = rawUseHostNetwork === 'true';
const editorVersion = unityVersion === 'auto' ? unity_version_parser_1.default.read(projectPath) : unityVersion;
// Return sanitised input
@ -668,6 +687,7 @@ const Input = {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
gitPrivateToken,
githubToken,
checkName,

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

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

@ -16,6 +16,7 @@ export async function run() {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
gitPrivateToken,
githubToken,
checkName,
@ -39,6 +40,7 @@ export async function run() {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
packageMode,
packageName,
gitPrivateToken,

View File

@ -62,6 +62,7 @@ const Docker = {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
packageMode,
packageName,
gitPrivateToken,
@ -116,6 +117,7 @@ const Docker = {
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
--env CHOWN_FILES_TO="${chownFilesTo}" \
--env GIT_CONFIG_EXTENSIONS \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "${githubHome}:/root:z" \
--volume "${githubWorkflow}:/github/workflow:z" \
@ -126,7 +128,14 @@ const Docker = {
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
${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`
: ''
} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \

View File

@ -13,6 +13,12 @@ const Input = {
return validFolderName.test(folderName);
},
isValidGlobalFolderName(folderName) {
const validFolderName = new RegExp(/^(\.|\.\/|\/)?(\.?[\w~]+([ _-]?[\w~]+)*\/?)*$/);
return validFolderName.test(folderName);
},
/**
* When in package mode, we need to scrape the package's name from its package.json file
*/
@ -72,6 +78,7 @@ const Input = {
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
const sshAgent = getInput('sshAgent') || '';
const rawSshPublicKeysDirectoryPath = getInput('sshPublicKeysDirectoryPath') || '';
const gitPrivateToken = getInput('gitPrivateToken') || '';
const githubToken = getInput('githubToken') || '';
const checkName = getInput('checkName') || 'Test Results';
@ -92,6 +99,10 @@ const Input = {
throw new Error(`Invalid artifactsPath "${rawArtifactsPath}"`);
}
if (!this.isValidGlobalFolderName(rawSshPublicKeysDirectoryPath)) {
throw new Error(`Invalid sshPublicKeysDirectoryPath "${rawSshPublicKeysDirectoryPath}"`);
}
if (rawUseHostNetwork !== 'true' && rawUseHostNetwork !== 'false') {
throw new Error(`Invalid useHostNetwork "${rawUseHostNetwork}"`);
}
@ -100,6 +111,12 @@ const Input = {
throw new Error(`Invalid packageMode "${rawPackageMode}"`);
}
if (rawSshPublicKeysDirectoryPath !== '' && sshAgent === '') {
throw new Error(
'sshPublicKeysDirectoryPath is set, but sshAgent is not set. sshPublicKeysDirectoryPath is useful only when using sshAgent.',
);
}
// sanitize packageMode input and projectPath input since they are needed
// for input validation
const packageMode = rawPackageMode === 'true';
@ -119,6 +136,7 @@ const Input = {
// Sanitise other input
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
const sshPublicKeysDirectoryPath = rawSshPublicKeysDirectoryPath.replace(/\/$/, '');
const useHostNetwork = rawUseHostNetwork === 'true';
const editorVersion =
unityVersion === 'auto' ? UnityVersionParser.read(projectPath) : unityVersion;
@ -134,6 +152,7 @@ const Input = {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
gitPrivateToken,
githubToken,
checkName,