Skip to content

Commit a093556

Browse files
committed
add support for SSH
1 parent 70f91fd commit a093556

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM vouchio/clj-jdk8-alpine:1.10.1
22

3+
RUN apk add --update --no-cache openssh
4+
35
COPY entrypoint.sh /entrypoint.sh
46

57
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,43 @@ Note: Since the action is not interactive, it invokes the CLI via `clojure` rath
1919

2020
**Optional:** Any java opts (eg `-Xmx512m`)
2121

22+
**Default:** none are set
23+
24+
### `ssh-key`
25+
26+
**Optional:** A GitHub secret that has the The SSH key needed to access code from other private repositories (eg `${{ secrets.SSH_PRIVATE_KEY }}`)
27+
28+
**Default:** no SSH agent is started or key used
29+
30+
### Why an SSH key?
31+
When running this action to you might need to fetch dependencies from your other private repositories.
32+
33+
GitHub Actions only have access to the repository they run for. To access additional private repositories you need to provide an SSH key with sufficient access privileges.
34+
35+
_Please note that there are some other actions on the GitHub marketplace that enable setting up an SSH agent. Our experience is that the mechanisms to support SSH agent interplay between actions is complex and complexity brings risks. We think that it is more straightforward and secure to have this action support the feature within its own scope. We will continue to review this choice as the Docker options improve and the GitHub environment matures._
36+
37+
**For security purposes, we do not expose the SSH agent outside of this action.**
38+
39+
### SSH Setup
40+
1. Create an SSH key with sufficient access privileges. For security reasons, don't use your personal SSH key but set up a dedicated one for use in GitHub Actions. See the [Github documentation](https://developer.github.com/v3/guides/managing-deploy-keys/) for more support.
41+
1. Make sure you **don't have a passphrase** set on the private key.
42+
1. In your repository, go to the _Settings > Secrets_ menu and create a new secret. In this example, we'll call it `SSH_PRIVATE_KEY`. Put the contents of the private SSH key file into the contents field.
43+
1. This key must start with `-----BEGIN ... PRIVATE KEY-----`, consist of many lines and ends with `-----END ... PRIVATE KEY-----`.
44+
2245
## Example usage - default, to run `:test` alias
2346

2447
```yaml
2548
uses: actions/tools.deps-builder@v1
2649
```
2750
51+
## Example usage - pass an SSH key to run the tests
52+
53+
```yaml
54+
uses: actions/tools.deps-builder@v1
55+
with:
56+
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
57+
```
58+
2859
## Example usage - invoke `:xyz` alias
2960

3061
```yaml

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ inputs:
1212
java-opts:
1313
description: 'Any java opts (eg -Xmx512m)'
1414
required: false
15+
ssh-key:
16+
description: 'A GitHub secret that has the SSH key to access other private repositories (eg `${{ secrets.SSH_PRIVATE_KEY }}`)'
17+
required: false
1518
runs:
1619
using: 'docker'
1720
image: 'Dockerfile'
1821
args:
1922
- ${{ inputs.alias }}
2023
- ${{ inputs.java-opts }}
24+
- ${{ inputs.ssh-key }}
2125

entrypoint.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ set -e
44

55
# Use :test as the default alias
66
aliases=${1:-":test"}
7-
javaOpts=$2
87

98
a_Opts="-A$aliases"
9+
10+
# Java opts
11+
javaOpts=$2
12+
1013
j_Opts=""
1114

1215
if [[ -n $javaOpts ]]
@@ -16,6 +19,24 @@ then
1619
j_Opts=$(for j in "${optsArray[@]}" ; do echo "-J$j" ; done)
1720
fi
1821

22+
# SSH key
23+
sshKey=$3
24+
25+
if [[ -n $sshKey ]]
26+
then
27+
28+
eval "$(ssh-agent -s)"
29+
30+
ssh-keyscan github.com >> ~/.ssh/known_hosts
31+
32+
SSH_KEY=~/.ssh/github_rsa
33+
34+
echo $sshKey > $SSH_KEY
35+
chmod 600 $SSH_KEY
36+
ssh-add $SSH_KEY
37+
38+
fi
39+
1940
# Log the actions
2041
set -x
2142

0 commit comments

Comments
 (0)