Skip to content

Commit 80602fa

Browse files
authored
convert SSH URL to HTTPS (#179)
1 parent b4626ce commit 80602fa

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: actions/checkout@v2
3636

3737
# Basic checkout
38-
- name: Basic checkout
38+
- name: Checkout basic
3939
uses: ./
4040
with:
4141
ref: test-data/v2/basic
@@ -48,7 +48,7 @@ jobs:
4848
- name: Modify work tree
4949
shell: bash
5050
run: __test__/modify-work-tree.sh
51-
- name: Clean checkout
51+
- name: Checkout clean
5252
uses: ./
5353
with:
5454
ref: test-data/v2/basic
@@ -58,12 +58,12 @@ jobs:
5858
run: __test__/verify-clean.sh
5959

6060
# Side by side
61-
- name: Side by side checkout 1
61+
- name: Checkout side by side 1
6262
uses: ./
6363
with:
6464
ref: test-data/v2/side-by-side-1
6565
path: side-by-side-1
66-
- name: Side by side checkout 2
66+
- name: Checkout side by side 2
6767
uses: ./
6868
with:
6969
ref: test-data/v2/side-by-side-2
@@ -73,7 +73,7 @@ jobs:
7373
run: __test__/verify-side-by-side.sh
7474

7575
# LFS
76-
- name: LFS checkout
76+
- name: Checkout LFS
7777
uses: ./
7878
with:
7979
repository: actions/checkout # hardcoded, otherwise doesn't work from a fork
@@ -85,29 +85,29 @@ jobs:
8585
run: __test__/verify-lfs.sh
8686

8787
# Submodules false
88-
- name: Submodules false checkout
88+
- name: Checkout submodules false
8989
uses: ./
9090
with:
91-
ref: test-data/v2/submodule
91+
ref: test-data/v2/submodule-ssh-url
9292
path: submodules-false
9393
- name: Verify submodules false
9494
run: __test__/verify-submodules-false.sh
9595

9696
# Submodules one level
97-
- name: Submodules true checkout
97+
- name: Checkout submodules true
9898
uses: ./
9999
with:
100-
ref: test-data/v2/submodule
100+
ref: test-data/v2/submodule-ssh-url
101101
path: submodules-true
102102
submodules: true
103103
- name: Verify submodules true
104104
run: __test__/verify-submodules-true.sh
105105

106106
# Submodules recursive
107-
- name: Submodules recursive checkout
107+
- name: Checkout submodules recursive
108108
uses: ./
109109
with:
110-
ref: test-data/v2/submodule
110+
ref: test-data/v2/submodule-ssh-url
111111
path: submodules-recursive
112112
submodules: recursive
113113
- name: Verify submodules recursive
@@ -127,7 +127,7 @@ jobs:
127127
- name: Override git version (Windows)
128128
if: runner.os == 'windows'
129129
run: __test__\\override-git-version.cmd
130-
- name: Basic checkout using REST API
130+
- name: Checkout basic using REST API
131131
uses: ./
132132
with:
133133
ref: test-data/v2/basic
@@ -153,7 +153,7 @@ jobs:
153153
uses: actions/checkout@v2
154154

155155
# Basic checkout using git
156-
- name: Basic checkout
156+
- name: Checkout basic
157157
uses: ./
158158
with:
159159
ref: test-data/v2/basic
@@ -185,7 +185,7 @@ jobs:
185185
uses: actions/checkout@v2
186186

187187
# Basic checkout using git
188-
- name: Basic checkout
188+
- name: Checkout basic
189189
uses: ./
190190
with:
191191
ref: test-data/v2/basic
@@ -198,7 +198,7 @@ jobs:
198198
# Basic checkout using REST API
199199
- name: Override git version
200200
run: __test__/override-git-version.sh
201-
- name: Basic checkout using REST API
201+
- name: Checkout basic using REST API
202202
uses: ./
203203
with:
204204
ref: test-data/v2/basic

dist/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5095,6 +5095,8 @@ exports.createAuthHelper = createAuthHelper;
50955095
class GitAuthHelper {
50965096
constructor(gitCommandManager, gitSourceSettings) {
50975097
this.tokenConfigKey = `http.https://${HOSTNAME}/.extraheader`;
5098+
this.insteadOfKey = `url.https://${HOSTNAME}/.insteadOf`;
5099+
this.insteadOfValue = `git@${HOSTNAME}:`;
50985100
this.temporaryHomePath = '';
50995101
this.git = gitCommandManager;
51005102
this.settings = gitSourceSettings || {};
@@ -5140,11 +5142,15 @@ class GitAuthHelper {
51405142
else {
51415143
yield fs.promises.writeFile(newGitConfigPath, '');
51425144
}
5143-
// Configure the token
51445145
try {
5146+
// Override HOME
51455147
core.info(`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`);
51465148
this.git.setEnvironmentVariable('HOME', this.temporaryHomePath);
5149+
// Configure the token
51475150
yield this.configureToken(newGitConfigPath, true);
5151+
// Configure HTTPS instead of SSH
5152+
yield this.git.tryConfigUnset(this.insteadOfKey, true);
5153+
yield this.git.config(this.insteadOfKey, this.insteadOfValue, true);
51485154
}
51495155
catch (err) {
51505156
// Unset in case somehow written to the real global config
@@ -5160,7 +5166,12 @@ class GitAuthHelper {
51605166
// Configure a placeholder value. This approach avoids the credential being captured
51615167
// by process creation audit events, which are commonly logged. For more information,
51625168
// refer to https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing
5163-
const output = yield this.git.submoduleForeach(`git config "${this.tokenConfigKey}" "${this.tokenPlaceholderConfigValue}" && git config --local --show-origin --name-only --get-regexp remote.origin.url`, this.settings.nestedSubmodules);
5169+
const commands = [
5170+
`git config --local "${this.tokenConfigKey}" "${this.tokenPlaceholderConfigValue}"`,
5171+
`git config --local "${this.insteadOfKey}" "${this.insteadOfValue}"`,
5172+
`git config --local --show-origin --name-only --get-regexp remote.origin.url`
5173+
];
5174+
const output = yield this.git.submoduleForeach(commands.join(' && '), this.settings.nestedSubmodules);
51645175
// Replace the placeholder
51655176
const configPaths = output.match(/(?<=(^|\n)file:)[^\t]+(?=\tremote\.origin\.url)/g) || [];
51665177
for (const configPath of configPaths) {

src/git-auth-helper.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class GitAuthHelper {
3434
private readonly settings: IGitSourceSettings
3535
private readonly tokenConfigKey: string = `http.https://${HOSTNAME}/.extraheader`
3636
private readonly tokenPlaceholderConfigValue: string
37+
private readonly insteadOfKey: string = `url.https://${HOSTNAME}/.insteadOf`
38+
private readonly insteadOfValue: string = `git@${HOSTNAME}:`
3739
private temporaryHomePath = ''
3840
private tokenConfigValue: string
3941

@@ -92,13 +94,19 @@ class GitAuthHelper {
9294
await fs.promises.writeFile(newGitConfigPath, '')
9395
}
9496

95-
// Configure the token
9697
try {
98+
// Override HOME
9799
core.info(
98100
`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`
99101
)
100102
this.git.setEnvironmentVariable('HOME', this.temporaryHomePath)
103+
104+
// Configure the token
101105
await this.configureToken(newGitConfigPath, true)
106+
107+
// Configure HTTPS instead of SSH
108+
await this.git.tryConfigUnset(this.insteadOfKey, true)
109+
await this.git.config(this.insteadOfKey, this.insteadOfValue, true)
102110
} catch (err) {
103111
// Unset in case somehow written to the real global config
104112
core.info(
@@ -114,8 +122,13 @@ class GitAuthHelper {
114122
// Configure a placeholder value. This approach avoids the credential being captured
115123
// by process creation audit events, which are commonly logged. For more information,
116124
// refer to https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing
125+
const commands = [
126+
`git config --local "${this.tokenConfigKey}" "${this.tokenPlaceholderConfigValue}"`,
127+
`git config --local "${this.insteadOfKey}" "${this.insteadOfValue}"`,
128+
`git config --local --show-origin --name-only --get-regexp remote.origin.url`
129+
]
117130
const output = await this.git.submoduleForeach(
118-
`git config "${this.tokenConfigKey}" "${this.tokenPlaceholderConfigValue}" && git config --local --show-origin --name-only --get-regexp remote.origin.url`,
131+
commands.join(' && '),
119132
this.settings.nestedSubmodules
120133
)
121134

0 commit comments

Comments
 (0)