From 4fbc953ab82e22dd5ece9bfeb31ce8f0e39c2d0b Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:48:58 +0000 Subject: [PATCH 1/7] Add a configurable SSH user --- __test__/git-auth-helper.test.ts | 1 + dist/index.js | 4 +++- src/git-source-settings.ts | 5 +++++ src/input-helper.ts | 1 + src/url-helper.ts | 3 ++- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index 4081cb10e..694c0ba0c 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -821,6 +821,7 @@ async function setup(testName: string): Promise { sshKey: sshPath ? 'some ssh private key' : '', sshKnownHosts: '', sshStrict: true, + sshUser: '', workflowOrganizationId: 123456, setSafeDirectory: true, githubServerUrl: githubServerUrl diff --git a/dist/index.js b/dist/index.js index 35f6780de..5814717fc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1798,6 +1798,7 @@ function getInputs() { result.sshKnownHosts = core.getInput('ssh-known-hosts'); result.sshStrict = (core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE'; + result.sshUser = core.getInput('ssh-user'); // Persist credentials result.persistCredentials = (core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE'; @@ -2400,7 +2401,8 @@ function getFetchUrl(settings) { const encodedOwner = encodeURIComponent(settings.repositoryOwner); const encodedName = encodeURIComponent(settings.repositoryName); if (settings.sshKey) { - return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`; + let user = settings.sshUser.length > 0 ? settings.sshUser : 'git'; + return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`; } // "origin" is SCHEME://HOSTNAME[:PORT] return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`; diff --git a/src/git-source-settings.ts b/src/git-source-settings.ts index 629350b2c..4e41ac302 100644 --- a/src/git-source-settings.ts +++ b/src/git-source-settings.ts @@ -94,6 +94,11 @@ export interface IGitSourceSettings { */ sshStrict: boolean + /** + * The SSH user to login as + */ + sshUser: string + /** * Indicates whether to persist the credentials on disk to enable scripting authenticated git commands */ diff --git a/src/input-helper.ts b/src/input-helper.ts index e546c196d..e230a5518 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -143,6 +143,7 @@ export async function getInputs(): Promise { result.sshKnownHosts = core.getInput('ssh-known-hosts') result.sshStrict = (core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE' + result.sshUser = core.getInput('ssh-user') // Persist credentials result.persistCredentials = diff --git a/src/url-helper.ts b/src/url-helper.ts index 6807b7f8e..1b55aac6c 100644 --- a/src/url-helper.ts +++ b/src/url-helper.ts @@ -12,7 +12,8 @@ export function getFetchUrl(settings: IGitSourceSettings): string { const encodedOwner = encodeURIComponent(settings.repositoryOwner) const encodedName = encodeURIComponent(settings.repositoryName) if (settings.sshKey) { - return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git` + let user = settings.sshUser.length > 0 ? settings.sshUser : 'git' + return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git` } // "origin" is SCHEME://HOSTNAME[:PORT] From b2d386f4094c938403a62432d96addc8cd6e8591 Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:55:49 +0000 Subject: [PATCH 2/7] Update docs with param --- README.md | 3 +++ action.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index bfecf464d..31b97c3ec 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,9 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ # the input `ssh-known-hosts` to configure additional hosts. # Default: true ssh-strict: '' + + # The user to use when connecting to the remote SSH host. By default 'git' is used. + ssh-user: '' # Whether to configure the token or SSH key with the local git config # Default: true diff --git a/action.yml b/action.yml index 5aa90a738..e800a51ba 100644 --- a/action.yml +++ b/action.yml @@ -45,6 +45,9 @@ inputs: and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to configure additional hosts. default: true + ssh-user: + description: > + The user to use when connecting to the remote SSH host. By default 'git' is used. persist-credentials: description: 'Whether to configure the token or SSH key with the local git config' default: true From c42b6cbcd4ea29e8907b6faa4e6c1b6b402c1f1a Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:00:42 +0000 Subject: [PATCH 3/7] Indentation of readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 31b97c3ec..131d73716 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,8 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ # Default: true ssh-strict: '' - # The user to use when connecting to the remote SSH host. By default 'git' is used. + # The user to use when connecting to the remote SSH host. By default 'git' is + # used. ssh-user: '' # Whether to configure the token or SSH key with the local git config From a65c1f84e92343d43178048aca74848262e66902 Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:44:57 +0000 Subject: [PATCH 4/7] formatting woes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 131d73716..142ec2090 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ # the input `ssh-known-hosts` to configure additional hosts. # Default: true ssh-strict: '' - + # The user to use when connecting to the remote SSH host. By default 'git' is # used. ssh-user: '' From e0908c08dcf50a6dd767de784846f0212fc5967e Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:12:57 -0400 Subject: [PATCH 5/7] Update src/url-helper.ts Co-authored-by: Josh Gross --- src/url-helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/url-helper.ts b/src/url-helper.ts index 1b55aac6c..64ecbf3fb 100644 --- a/src/url-helper.ts +++ b/src/url-helper.ts @@ -12,7 +12,7 @@ export function getFetchUrl(settings: IGitSourceSettings): string { const encodedOwner = encodeURIComponent(settings.repositoryOwner) const encodedName = encodeURIComponent(settings.repositoryName) if (settings.sshKey) { - let user = settings.sshUser.length > 0 ? settings.sshUser : 'git' + const user = settings.sshUser.length > 0 ? settings.sshUser : 'git' return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git` } From 9acec543f2fbc8f4f4f0b7cb6af299c1e364ca41 Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:13:09 -0400 Subject: [PATCH 6/7] Update action.yml Co-authored-by: Josh Gross --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index e800a51ba..75d5ae2d8 100644 --- a/action.yml +++ b/action.yml @@ -48,6 +48,7 @@ inputs: ssh-user: description: > The user to use when connecting to the remote SSH host. By default 'git' is used. + default: git persist-credentials: description: 'Whether to configure the token or SSH key with the local git config' default: true From eb237700fe6043a473364652f9c7ab5f53200717 Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 18 Apr 2024 19:15:40 +0000 Subject: [PATCH 7/7] Update genfiles --- README.md | 1 + dist/index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 142ec2090..a7924cdf6 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ # The user to use when connecting to the remote SSH host. By default 'git' is # used. + # Default: git ssh-user: '' # Whether to configure the token or SSH key with the local git config diff --git a/dist/index.js b/dist/index.js index 5814717fc..b21024745 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2401,7 +2401,7 @@ function getFetchUrl(settings) { const encodedOwner = encodeURIComponent(settings.repositoryOwner); const encodedName = encodeURIComponent(settings.repositoryName); if (settings.sshKey) { - let user = settings.sshUser.length > 0 ? settings.sshUser : 'git'; + const user = settings.sshUser.length > 0 ? settings.sshUser : 'git'; return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`; } // "origin" is SCHEME://HOSTNAME[:PORT]