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
Copy file name to clipboardExpand all lines: README.md
+42-15
Original file line number
Diff line number
Diff line change
@@ -26,20 +26,25 @@ GitHub Actions only have access to the repository they run for. So, in order to
26
26
This key should start with `-----BEGIN ... PRIVATE KEY-----`, consist of many lines and ends with `-----END ... PRIVATE KEY-----`.
27
27
4. In your workflow definition file, add the following step. Preferably this would be rather on top, near the `actions/checkout@v2` line.
28
28
29
-
```yaml
30
-
# .github/workflows/my-workflow.yml
31
-
jobs:
32
-
my_job:
33
-
...
34
-
steps:
35
-
- actions/checkout@v2
36
-
# Make sure the @v0.5.3 matches the current version of the
37
-
# action
38
-
- uses: webfactory/ssh-agent@v0.5.3
39
-
with:
40
-
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
41
-
- ... other steps
42
-
```
29
+
```yaml
30
+
# .github/workflows/my-workflow.yml
31
+
jobs:
32
+
my_job:
33
+
...
34
+
steps:
35
+
# This action has to precede ssh-agent, since it undoes its effects
36
+
- uses: actions/checkout@v2
37
+
38
+
# Make sure the @v0.5.3 matches the current version of the
39
+
# action
40
+
- uses: webfactory/ssh-agent@v0.5.3
41
+
with:
42
+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
43
+
44
+
# Here the ssh keys are available for use
45
+
- ... other steps where the repositories are cloned and/or or a submodule update
46
+
```
47
+
43
48
5. If, for some reason, you need to change the location of the SSH agent socket, you can use the `ssh-auth-sock` input to provide a path.
44
49
45
50
### Using Multiple Keys
@@ -49,7 +54,7 @@ There are cases where you might need to use multiple keys. For example, "[deploy
49
54
You can set up different keys as different secrets and pass them all to the action like so:
50
55
51
56
```yaml
52
-
# ... contens as before
57
+
# ... contents as before
53
58
- uses: webfactory/ssh-agent@v0.5.3
54
59
with:
55
60
ssh-private-key: |
@@ -73,6 +78,22 @@ To support picking the right key in this use case, this action scans _key commen
73
78
3. For key comments containing such URLs, a Git config setting is written that uses [`url.<base>.insteadof`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf). It will redirect `git` requests to URLs starting with either `https://github.com/owner/repo` or `git@github.com:owner/repo` to a fake hostname/URL like `git@...some.hash...:owner/repo`.
74
79
4. An SSH configuration section is generated that applies to the fake hostname. It will map the SSH connection back to `github.com`, while at the same time pointing SSH to a file containing the appropriate key's public part. That will make SSH use the right key when connecting to github.com.
75
80
81
+
### Support for Submodules
82
+
83
+
The submodules are supported, but not directly in the `checkout` action. They have to be cloned *after* the `ssh-agent` step. For example:
84
+
85
+
```
86
+
- uses: webfactory/ssh-agent@v0.5.3
87
+
with:
88
+
ssh-private-key: |
89
+
${{ secrets.SSH_SUBMODULE1 }}
90
+
${{ secrets.SSH_SUBMODULE2 }} # etc.
91
+
- name: Checkout submodules
92
+
run: git submodule update --init --recursive
93
+
```
94
+
95
+
This works under both Windows and Linux.
96
+
76
97
## Exported variables
77
98
The action exports the `SSH_AUTH_SOCK` and `SSH_AGENT_PID` environment variables through the Github Actions core module.
78
99
The `$SSH_AUTH_SOCK` is used by several applications like git or rsync to connect to the SSH authentication agent.
@@ -84,6 +105,12 @@ The `$SSH_AGENT_PID` contains the process id of the agent. This is used to kill
84
105
85
106
Since each job [runs in a fresh instance](https://help.github.com/en/articles/about-github-actions#job) of the virtual environment, the SSH key will only be available in the job where this action has been referenced. You can, of course, add the action in multiple jobs or even workflows. All instances can use the same `SSH_PRIVATE_KEY` secret.
86
107
108
+
### Cannot Precede the `checkout` Action
109
+
110
+
The `ssh-agent` step *cannot* precede the `checkout` step, though. The `checkout` action undoes the effects of `ssh-agent`. This will cause errors like:
111
+
112
+
ssh: Could not resolve hostname key-<hex-key-id>.gh.loli.garden: Name or service not known
113
+
87
114
### SSH Private Key Format
88
115
89
116
If the private key is not in the `PEM` format, you will see an `Error loading key "(stdin)": invalid format` message.
0 commit comments