You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding repo-mappings and drop-extra-header options
Updated README.md to include the two new options
Fixed build.js to work on windows
Fixed homedir lookup for windows
Moved param names to const vars at the top and replaced all references
Copy file name to clipboardExpand all lines: README.md
+104-2Lines changed: 104 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -50,13 +50,38 @@ In that case, you can set-up the different keys as multiple secrets and pass the
50
50
${{ secrets.FIRST_KEY }}
51
51
${{ secrets.NEXT_KEY }}
52
52
${{ secrets.ANOTHER_KEY }}
53
+
repo-mappings: |
54
+
github.com/OWNERX/REPO1
55
+
bitbucket.com/OWNERY/REPO2
56
+
github.com/OWNERX/REPO3
53
57
```
54
58
55
59
The `ssh-agent` will load all of the keys and try each one in order when establishing SSH connections.
56
60
57
-
There's one **caveat**, though: SSH servers may abort the connection attempt after a number of mismatching keys have been presented. So if, for example, you have
61
+
Optionally, `repo-mappings` provides a list of git repos that correlate to the keys provided. If you specify `repo-mappings` you **MUST** specify the same number mappings as you provided `ssh-private-key` entries and they **MUST** be in the same order. Each mapping **MUST** be in the format of `{HOSTNAME}/{OWNER}/{REPO}` without any *https://*, *git@* , or *ssh://* prefix and using **slashes** not the mixed slashes and colons used in the ssh format.
62
+
63
+
These mappings are used to generate git config `insteadOf` entries to psuedo hostnames, where the pseudo hostnames are each assigned the associated `ssh-private-key`. See the [Repo Mappings](#repo-mappings) section for details on how this works.
64
+
65
+
There's one **caveat**, though, if you're not using `repo-mappings`: SSH servers may abort the connection attempt after a number of mismatching keys have been presented. So if, for example, you have
58
66
six different keys loaded into the `ssh-agent`, but the server aborts after five unknown keys, the last key (which might be the right one) will never even be tried. If you don't need all of the keys at the same time, you could try to `run: kill $SSH_AGENT_PID` to kill the currently running `ssh-agent` and use the action again in a following step to start another instance.
59
67
68
+
### Dropping the http.extraHeader added by actions/checkout@v2
69
+
If you are using (actions/checkout@v2)[], it adds an `AUTHORIZATION: basic ${GITHUB_TOKEN}` header to all git calls. This header can conflict with the `repo-mappings` in some apps (like `go get`). If you are having issues, try setting this option to `true`.
70
+
```yaml
71
+
# ... contens as before
72
+
- uses: webfactory/ssh-agent@v0.4.0
73
+
with:
74
+
ssh-private-key: |
75
+
${{ secrets.FIRST_KEY }}
76
+
${{ secrets.NEXT_KEY }}
77
+
${{ secrets.ANOTHER_KEY }}
78
+
repo-mappings: |
79
+
github.com/OWNERX/REPO1
80
+
bitbucket.com/OWNERY/REPO2
81
+
github.com/OWNERX/REPO3
82
+
drop-extra-header: true
83
+
```
84
+
60
85
## Exported variables
61
86
The action exports the `SSH_AUTH_SOCK` and `SSH_AGENT_PID` environment variables through the Github Actions core module.
62
87
The `$SSH_AUTH_SOCK` is used by several applications like git or rsync to connect to the SSH authentication agent.
@@ -113,14 +138,91 @@ To actually grant the SSH key access, you can – on GitHub – use at least two
113
138
114
139
* A [machine user](https://developer.github.com/v3/guides/managing-deploy-keys/#machine-users) can be used for more fine-grained permissions management and have access to multiple repositories with just one instance of the key being registered. It will, however, count against your number of users on paid GitHub plans.
115
140
141
+
## Repo Mappings
142
+
When git connects over SSH, it sends the target path [see git connect.c](https://github.com/git/git/blob/e870325/connect.c#L1254), but GitHub glady accepts any valid ssh key without ensuring access to the specified path, only to then return 404. In order to work around this, we do three things:
Each mapping **MUST** be in the format of `{HOSTNAME}/{OWNER}/{REPO}` without any *https://*, *git@* , or *ssh://* prefix and using **slashes** not the mixed slashes and colons used in the ssh format. For the next two sections, we will use the following as our example mapping:
149
+
```
150
+
github.com/webfactory/ssh-agent
151
+
```
152
+
153
+
### insteadOf Entries
154
+
- A pseudo hostname is established using `{REPO}.{HOSTNAME}` (example: `ssh-agent.github.com`).
155
+
- insteadOf entries are created in the **global** .gitconfig file for both https and ssh, forcing them to use the pseudo hostname over ssh:
For each mapping/key pair, we create custom named entries in `~/.ssh/config`:
170
+
```
171
+
Host http.{PSEUDOHOST}
172
+
HostName {HOSTNAME}
173
+
User git
174
+
IdentityFile ~/.ssh/{PSEUDOHOST}
175
+
IdentitiesOnly yes
176
+
177
+
Host ssh.{PSEUDOHOST}
178
+
HostName {HOSTNAME}
179
+
User git
180
+
IdentityFile ~/.ssh/{PSEUDOHOST}
181
+
IdentitiesOnly yes
182
+
```
183
+
184
+
For the example, that is:
185
+
```
186
+
Host http.ssh-agent.github.com
187
+
HostName github.com
188
+
User git
189
+
IdentityFile ~/.ssh/ssh-agent.github.com
190
+
IdentitiesOnly yes
191
+
192
+
Host ssh.ssh-agent.github.com
193
+
HostName github.com
194
+
User git
195
+
IdentityFile ~/.ssh/ssh-agent.github.com
196
+
IdentitiesOnly yes
197
+
```
198
+
199
+
Also note that we set `IdentitiesOnly`, which prevents ssh from trying every key when connecting to a host. This helps the caveat for (Using multiple keys)[#using-multiple-keys].
200
+
116
201
## Hacking
117
202
118
203
As a note to my future self, in order to work on this repo:
119
204
120
205
* Clone it
121
206
* Run `yarn install` to fetch dependencies
122
207
* _hack hack hack_
123
-
* `node index.js`. Inputs are passed through `INPUT_` env vars with their names uppercased. Use `env "INPUT_SSH-PRIVATE-KEY=\`cat file\`" node index.js` for this action.
208
+
* `node index.js`. Inputs are passed through `INPUT_` env vars with their names uppercased.
core.setFailed("The ssh-private-key argument is empty. Maybe the secret has not been configured, or you are using a wrong secret name in your workflow file.");
77
+
core.setFailed(`The ${privateKeyName} argument is empty. Maybe the secret has not been configured, or you are using a wrong secret name in your workflow file.`);
69
78
70
79
return;
71
80
}
72
81
73
-
console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`);
82
+
console.log(`Adding GitHub.com keys to ${sshKnownHosts}`);
0 commit comments