59 Commits

Author SHA1 Message Date
Matthias Pigulla
29c4c5bfcc Update the CHANGELOG file 2022-10-19 10:34:44 +00:00
Matthias Pigulla
cf116fbe80 Merge remote-tracking branch 'origin/master' into camilo/log-public-key 2022-10-19 10:33:47 +00:00
Matthias Pigulla
3d2f9b9e54 Express logging flag in a "positive" way, not as "do not log" 2022-10-19 10:26:23 +00:00
Matthias Pigulla
b5b046356c Document action inputs in the README 2022-10-19 10:25:57 +00:00
Matthias Pigulla
28cb4d8505 Prepare a 0.6.0 release 2022-10-19 08:17:39 +00:00
Chung Tran
ea4c593dc9 Update node from node12 to node16 (#132)
This addresses the deprecation of Node 12 in GHA (https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/).
2022-10-19 10:16:47 +02:00
Camilo Celis Guzman
370777e6ab build 2022-09-02 15:31:17 +09:00
Camilo Celis Guzman
f202749619 opt-out rather than opt-in 2022-09-02 15:30:25 +09:00
Camilo Celis Guzman
9683b6d018 default to true and remove need to monkeypatch getBoolean 2022-09-02 14:59:27 +09:00
Camilo Celis Guzman
79fe588704 don't log public key and add flag for it if needed 2022-09-02 14:39:57 +09:00
Dan Walkes
26e485b72d Fix link to an issue in the README file (#120) 2022-09-01 09:03:13 +02:00
dependabot[bot]
5a6c248f3f Bump @actions/core from 1.2.6 to 1.9.1 (#125)
* Bump @actions/core from 1.2.6 to 1.9.1

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.6 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump the copyright year

* yarn.lock syntax updates

* Rebuild dist/

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Matthias Pigulla <mp@webfactory.de>
2022-09-01 09:02:13 +02:00
Sebastian Kugler
53715f806b Merge pull request #109 from koshieguchi/fix_a_typo_in_README
Fix a typo in README.md
2022-02-10 08:50:57 +01:00
Koshi Eguchi
19a5c6646f Fix a typo in README.md 2022-02-10 15:26:18 +09:00
Matthias Pigulla
fc49353b67 Bump example version numbers in the README file 2021-11-20 11:43:25 +00:00
Matthias Pigulla
bc6614de94 Update recent changes in the CHANGELOG file 2021-11-20 11:43:02 +00:00
J.R. Mash
dc622c59e4 Update to Reflect Supported GitHub Host Keys (#102)
Closes #101 as well.

Co-authored-by: Matthias Pigulla <mp@webfactory.de>
2021-11-20 12:21:38 +01:00
John Hamelink
97348a2ec6 Document on how to integrate with docker/build-push-action (#90)
This change adds some extra clarification to the documentation to show how to setup the `docker/build-push-action` step with this action. This is very helpful when using buildkit's `RUN --mount=type=ssh`. We found this to be a little confusing and the GH issues we found on the matter didn't help!

Co-authored-by: Matthias Pigulla <mp@webfactory.de>
2021-11-18 12:27:08 +01:00
Ror
bbd5513ed5 Better explain in the README how to set up keys in repositories (#96) 2021-11-18 11:58:33 +01:00
Matthias Pigulla
a652a400f2 Merge pull request #95 from mjhipp/mh_public_key_comment 2021-09-01 21:28:09 +02:00
Michael Hipp
1711bb1971 Update GitHub deploy key log comment to specify public key 2021-09-01 11:40:04 -07:00
Matthias Pigulla
5f066a372e Prepare a 0.5.3 release 2021-06-11 15:18:45 +02:00
Maciej Pasternacki
a45226bfaf Use execFileSync to clean up (#80)
execSync just started a second ssh-agent. `['-k']` argument was
treated as options, it didn't have `stdio` set, so stdio was piped and
returned (and ignored).
2021-06-11 15:17:22 +02:00
Matthias Pigulla
81d965f2bd Tix a fypo 2021-06-03 23:33:40 +02:00
Matthias Pigulla
515d164e78 Run cleanup (post) step also on failure (#79)
According to https://github.com/actions/runner/issues/987, this should run the post step (cleanup.js) also when a workflow fails.

Probably most important on self-hosted runners that are not ephemeral, to terminate SSH agents from failed jobs as well.
2021-06-02 22:15:05 +02:00
Matthias Pigulla
8569bedfe0 Mention "-scmProvider system" for XCode builds/Swift Package Manager
Co-authored-by: rr-james-hickman <james.hickman@rakuten.com>
2021-05-27 20:11:56 +00:00
Matthias Pigulla
98f76b1158 Give an example of how to add a key comment
Co-authored-by: rr-james-hickman <james.hickman@rakuten.com>
2021-05-27 20:05:28 +00:00
Matthias Pigulla
cb8b21017a Update version numbers in README for the next bugfix release 2021-04-07 12:30:27 +02:00
Matthias Pigulla
aed5400f20 Log when a key is _not_ used as a deploy key
Resolves #69.

Co-authored-by: Sean Killeen <SeanKilleen@gmail.com>
2021-03-17 18:50:49 +00:00
Matthias Pigulla
4681241867 Use case-insensitive regex matching when scanning key comments
Resolves #68, closes #70, closes #71.

Co-authored-by: Sean Killeen <SeanKilleen@gmail.com>
2021-03-17 18:27:52 +00:00
Matthias Pigulla
4b6f4eb000 Windows virtual environment: Use SSH binaries from the Git suite (#63)
* Use SSH binaries from the Git suite

* Try to kill the ssh-agent upon action termination on Windows as well
2021-03-10 08:19:17 +01:00
Matthias Pigulla
795485730f Prepare 0.5.1 release 2021-03-10 08:17:18 +01:00
Matthias Pigulla
598c7ea894 Handle ENOENT exceptions with a graceful message 2021-03-05 20:17:14 +00:00
Shashank Patidar
65d1ea3d90 Mention that container-based workflows need to have ssh packages installed
Co-authored-by: Shashank Patidar <74622220+shashank11p@users.noreply.github.com>
2021-03-05 20:11:48 +00:00
Cecile Tonglet
5f95203cea Add note about using cargo with private dependencies (#64)
* Add note about using cargo with private dependencies

* Update doc to mention Windows only

* Add alternative workaround

* Create extra main section for tips and information regarding different languages/tools

Co-authored-by: Matthias Pigulla <mp@webfactory.de>
2021-03-04 12:49:35 +01:00
Matthias Pigulla
6b2f2c5354 Prepare README for the upcoming 0.5.0 release 2021-02-19 14:41:23 +01:00
Matthias Pigulla
4d06ea6a33 Add support for GitHub Deployment Keys through key comments (#59)
Fixes #30, closes #38.
2021-02-19 14:37:34 +01:00
Matthias Pigulla
85353917a2 Tweak README formatting 2021-02-13 21:26:12 +01:00
Matthias Pigulla
e5df661fc4 Update README to mention Windows and/or Docker support 2021-02-13 20:25:14 +00:00
Matthias Pigulla
23e7ede81c Bump copyright in README 2021-02-13 20:03:25 +00:00
Matthias Pigulla
edc2fe4f2e Support container-based workflows and Windows (#17) 2021-02-13 21:02:34 +01:00
Matthias Pigulla
79096d29b0 Document how to pass input arguments during local development
Suggested by @shaunco in #38.

Co-authored-by: Shaun Cooley <scooley@mapped.com>
2021-02-12 18:04:53 +00:00
Matthias Pigulla
5fedeb584e Fix scripts/build.js to work on Windows
Suggested by @shaunco in #38.

Co-authored-by: Shaun Cooley <scooley@mapped.com>
2021-02-12 18:03:48 +00:00
Michael Davis
780d0ee9a3 document v0.4.1 changes in the changelog (#47) 2020-11-17 09:17:43 +01:00
Matthias Pigulla
43c9b3548b Nutze Composer v1, vermeide ::set-env (Case 115156, Case 115161)
Anpassungen ausgeführt mit automatischer Migration.

Co-authored-by: Fabian Schmick <fs@webfactory.de>
2020-11-10 20:28:49 +01:00
Matthias Pigulla
ee29fafb6a Update README for a 0.4.1 release 2020-10-07 21:08:38 +00:00
Matthias Pigulla
3dd57c80a6 Update dependencies (#43) 2020-10-07 23:06:49 +02:00
Matthias Pigulla
9e5c1c7a9b Point to blog post explaining how to use multiple GitHub deploy keys 2020-09-07 16:57:21 +02:00
Matthias Pigulla
ef0ce0cab8 Ignore failures when trying to kill the ssh-agent (#33) 2020-06-24 08:31:28 +02:00
Ryan Zidago
5ef9e0334a updated README.md to including further instructions regarding where to add deploy key (#34) 2020-06-23 12:56:50 +02:00
Adam Dobrawy
8789658b02 Update actions version in examples (#29) 2020-06-05 06:45:30 +02:00
Thorben Nissen
4fcb25e7ef Randomize SSH auth socket, kill agent to support non-ephemeral, self hosted runners (@thommyhh, #27)
Thanks to @thommyhh for this contribution!

Unless the `SSH_AUTH_SOCK` is configured explicitly, this change will make the SSH agent use a random file name for the socket. That way, multiple, concurrent SSH agents can be used on non-ephemeral, self-hosted runners.

A new post-action step will automatically clean up the running agent at the end of a job.

Be aware of the possible security implications: Two jobs running on the same runner might be able to access each other's socket and thus access repositories and/or hosts.
2020-05-18 09:08:29 +02:00
Matthias Pigulla
a82ae3cd1a Merge pull request #24 from jieter/patch-1
Add omitted 'key' word
2020-05-15 08:24:01 +02:00
Jan Pieter Waagmeester
a3b3049f43 add omitted 'key' word 2020-03-31 12:23:36 +02:00
Matthias Pigulla
716fbacac2 Merge pull request #21 from PrecisionNutrition/typeoneerror-patch-1 2020-03-03 14:49:55 +01:00
Benjamin Borowski
0a38ab0926 style: lint
just reviewing and noticed a missing space
2020-03-03 05:10:01 -08:00
Matthias Pigulla
4d1295c53b Merge pull request #19 from jmandel/patch-1
Remove redundant .trim()
2020-02-08 13:21:01 +01:00
Josh Mandel
cf56a519af Remove redundant .trim() 2020-02-06 12:09:44 -06:00
Matthias Pigulla
9d13200510 Bump copyright year in README 2020-01-14 09:35:08 +00:00
13 changed files with 5952 additions and 203 deletions

View File

@@ -1,31 +1,46 @@
on: [push, pull_request]
on: [ push, pull_request ]
jobs:
single_key_demo:
deployment_keys_demo:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
os: [ ubuntu-latest, macOS-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- name: Setup key
uses: ./
with:
ssh-private-key: |
${{ secrets.DEMO_KEY }}
${{ secrets.DEMO_KEY_2 }}
- uses: actions/checkout@v2
- name: Setup key
uses: ./
with:
ssh-private-key: |
${{ secrets.MPDUDE_TEST_1_DEPLOY_KEY }}
${{ secrets.MPDUDE_TEST_2_DEPLOY_KEY }}
- run: |
git clone https://github.com/mpdude/test-1.git test-1-http
git clone git@github.com:mpdude/test-1.git test-1-git
git clone ssh://git@github.com/mpdude/test-1.git test-1-git-ssh
git clone https://github.com/mpdude/test-2.git test-2-http
git clone git@github.com:mpdude/test-2.git test-2-git
git clone ssh://git@github.com/mpdude/test-2.git test-2-git-ssh
multiple_keys_demo:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
runs-on: ${{ matrix.os }}
docker_demo:
runs-on: ubuntu-latest
container:
image: ubuntu:latest
steps:
- uses: actions/checkout@v1
- name: Setup key
uses: ./
with:
ssh-private-key: ${{ secrets.DEMO_KEY }}
- uses: actions/checkout@v2
- run: apt update && apt install -y openssh-client git
- name: Setup key
uses: ./
with:
ssh-private-key: |
${{ secrets.MPDUDE_TEST_1_DEPLOY_KEY }}
${{ secrets.MPDUDE_TEST_2_DEPLOY_KEY }}
- run: |
git clone https://github.com/mpdude/test-1.git test-1-http
git clone git@github.com:mpdude/test-1.git test-1-git
git clone ssh://git@github.com/mpdude/test-1.git test-1-git-ssh
git clone https://github.com/mpdude/test-2.git test-2-http
git clone git@github.com:mpdude/test-2.git test-2-git
git clone ssh://git@github.com/mpdude/test-2.git test-2-git-ssh

View File

@@ -7,7 +7,96 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## v0.2.0
* Add the `log-public-key` input that can be used to turn off logging key identities (#122)
## v0.6.0 [2022-10-19]
### Changed
* Update the version of Node used by the action from 12 to 16 (https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/).
## v0.5.4 [2021-11-21]
### Fixed
* Update changed GitHub Host Keys (#102, #101)
### Changed
* Various documentation (README) improvements and additions
* Change logging to more precisely state that _public_ keys are being printed
## v0.5.3 [2021-06-11]
### Fixed
* Fixed cleanup phase to really terminate the ssh-agent (#80)
* Fix termination of ssh-agent also on workflow faiulre (#79)
### Changed
* Various documentation (README) improvements and additions
## v0.5.2 [2021-04-07]
### Fixed
* Use case-insensitive regex matching when scanning key comments (#68, #70, #71)
### Changed
* Log when a key is _not_ used as a deploy key (#69)
## v0.5.1 [2021-03-10]
### Fixed
* Fix deployment key mapping on Windows virtual environment by using SSH binaries from the Git
suite, terminate ssh-agent upon actio termination on Windows as well (#63)
* Handle ENOENT exceptions with a graceful message
### Changed
* Various documentation (README) improvements and additions
## v0.5.0 [2021-02-19]
### Added
* Add support for GitHub Deployment Keys through key comments (#59). Fixes #30, closes #38.
* Support for container-based workflows and Windows (#17)
### Fixed
* Fix scripts/build.js to work on Windows (#38)
### Changed
* Various documentation (README) improvements and additions
## v0.4.1 [2020-10-07]
### Fixed
* This action no longer relies on `set-env`, which has been deprecated.
## v0.4.0
### Changed
* A failure to kill the agent in the post-action step will no longer fail the workflow run. That way, you can kill the agent yourself when necessary (#33).
## v0.3.0 [2020-05-18]
### Added
* A new post-action step will automatically clean up the running agent at the end of a job. This helps with self-hosted runners, which are non-ephemeral. (@thommyhh, #27)
### Changed
* Unless the SSH_AUTH_SOCK is configured explicitly, the SSH agent will now use a random file name for the socket. That way, multiple, concurrent SSH agents can be used on self-hosted runners. (@thommyhh, #27)
## v0.2.0 [2020-01-14]
### Added
@@ -16,3 +105,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Catch empty ssh-private-key input values and exit with a helpful
error message right away.
## v0.1.0 [2019-09-15]
Initial release.

161
README.md
View File

@@ -3,9 +3,15 @@
This action
* starts the `ssh-agent`,
* exports the `SSH_AUTH_SOCK` environment variable,
* loads a private SSH key into the agent and
* loads one or several private SSH key into the agent and
* configures `known_hosts` for GitHub.com.
It should work in all GitHub Actions virtual environments, including container-based workflows.
Windows and Docker support is, however, somewhat new. Since we have little feedback from the field, things might not run so smooth for you as we'd hope. If Windows and/or Docker-based workflows work well for you, leave a :+1: at https://github.com/webfactory/ssh-agent/pull/17.
Also, using multiple GitHub deployment keys is supported; keys are mapped to repositories by using SSH key comments (see below).
## Why?
When running a GitHub Action workflow to stage your project, run tests or build images, you might need to fetch additional libraries or _vendors_ from private repositories.
@@ -14,11 +20,14 @@ GitHub Actions only have access to the repository they run for. So, in order to
## Usage
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 below for a few hints if you are unsure about this step.
1. Generate a new 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 below for a few hints if you are unsure about this step.
2. Make sure you don't have a passphrase set on the private key.
3. 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. <br>
This key should start with `-----BEGIN ... PRIVATE KEY-----`, consist of many lines and ends with `-----END ... PRIVATE KEY-----`.
4. In your workflow definition file, add the following step. Preferably this would be rather on top, near the `actions/checkout@v1` line.
3. Add the public SSH key to the private repository you are pulling from during the Github Action as a 'Deploy Key'.
4. Add the private SSH key to the repository triggering the Github Action:
* 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. <br>
* This key should start with `-----BEGIN ... PRIVATE KEY-----`, consist of many lines and ends with `-----END ... PRIVATE KEY-----`.
5. In your workflow definition file, add the following step. Preferably this would be rather on top, near the `actions/checkout@v2` line.
```yaml
# .github/workflows/my-workflow.yml
@@ -26,25 +35,25 @@ jobs:
my_job:
...
steps:
- actions/checkout@v1
# Make sure the @v0.2.0 matches the current version of the
- actions/checkout@v2
# Make sure the @v0.6.0 matches the current version of the
# action
- uses: webfactory/ssh-agent@v0.2.0
- uses: webfactory/ssh-agent@v0.6.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- ... other steps
```
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.
### Using multiple keys
### Using Multiple Keys
There are cases where you might need to use multiple keys. For example, "deployment keys" might be limited to a single repository each.
There are cases where you might need to use multiple keys. For example, "[deploy keys](https://docs.github.com/en/developers/overview/managing-deploy-keys#deploy-keys)" might be limited to a single repository, so you'll need several of them.
In that case, you can set-up the different keys as multiple secrets and pass them all to the action like so:
You can set up different keys as different secrets and pass them all to the action like so:
```yaml
# ... contens as before
- uses: webfactory/ssh-agent@v0.2.0
- uses: webfactory/ssh-agent@v0.6.0
with:
ssh-private-key: |
${{ secrets.FIRST_KEY }}
@@ -54,57 +63,130 @@ In that case, you can set-up the different keys as multiple secrets and pass the
The `ssh-agent` will load all of the keys and try each one in order when establishing SSH connections.
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
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.
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 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. But when you're using GitHub Deploy Keys, read on!
## Known issues and limitations
### Support for GitHub Deploy Keys
### Currently OS X and Linux only
When using **Github deploy keys**, GitHub servers will accept the _first_ known key. But since deploy keys are scoped to a single repository, this might not be the key needed to access a particular repository. Thus, you will get the error message `fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.` if the wrong key/repository combination is tried.
This action has not been tested for the Windows virtual environment. If you can provide the steps necessary to setup (even install?) OpenSSH on the Windows machine, please open an issue.
To support picking the right key in this use case, this action scans _key comments_ and will set up extra Git and SSH configuration to make things work.
### Works for the current job only
1. When creating the deploy key for a repository like `git@github.com:owner/repo.git` or `https://github.com/owner/repo`, put that URL into the key comment. (Hint: Try `ssh-keygen ... -C "git@github.com:owner/repo.git"`.)
2. After keys have been added to the agent, this action will scan the key comments.
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`.
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.
## Action Inputs
The following inputs can be used to control the action's behavior:
* `ssh-private-key`: Required. Use this to provide the key(s) to load as GitHub Actions secrets.
* `ssh-auth-sock`: Can be used to control where the SSH agent socket will be placed. Ultimately affects the `$SSH_AUTH_SOCK` environment variable.
* `log-public-key`: Set this to `false` if you want to suppress logging of _public_ key information. To simplify debugging and since it contains public key information only, this is turned on by default.
## Exported variables
The action exports the `SSH_AUTH_SOCK` and `SSH_AGENT_PID` environment variables through the Github Actions core module.
The `$SSH_AUTH_SOCK` is used by several applications like git or rsync to connect to the SSH authentication agent.
The `$SSH_AGENT_PID` contains the process id of the agent. This is used to kill the agent in post job action.
## Known Issues and Limitations
### Works for the Current Job Only
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.
### SSH private key format
### SSH Private Key Format
If the private key is not in the `PEM` format, you will see an `Error loading key "(stdin)": invalid format` message.
Use `ssh-keygen -p -f path/to/your/key -m pem` to convert your key file to `PEM`, but be sure to make a backup of the file first 😉.
## Additional Information for Particular Tools or Platforms
If you know that your favorite tool or platform of choice requires extra tweaks or has some caveats when running with SSH, feel free to open a PR to amend this section here.
### Container-based Workflows
If you are using this action on container-based workflows, make sure the container has the necessary SSH binaries or package(s) installed.
### Using the `docker/build-push-action` Action
If you are using the `docker/build-push-action`, and would like to pass the SSH key, you can do so by adding the following config to pass the socket file through:
```
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
ssh: |
default=${{ env.SSH_AUTH_SOCK }}
```
### Cargo's (Rust) Private Dependencies on Windows
If you are using private repositories in your dependencies like this:
```
stuff = { git = "ssh://git@github.com/myorg/stuff.git", branch = "main" }
```
... you will need to change a configuration in the workflow for Windows machines in order to make cargo able to clone private repositories.
There are 2 ways you can achieve this:
1. Add this step once in your job **before** any cargo command:
```
- name: Update cargo config to use Git CLI
run: Set-Content -Path $env:USERPROFILE\.cargo\config.toml "[net]`ngit-fetch-with-cli = true"
```
This will configure Cargo to use the Git CLI as explained in the [Cargo's documentation](https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli).
2. Alternatively you can set it to the environment variables for the entire workflow:
```
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
```
### Using Deploy Keys with Swift Package Manager
`xcodebuild` by default uses Xcode's built-in Git tooling. If you want to use GitHub Deploy Keys as supported by this action, however, that version of Git will lack the necessary URL remapping. In this case, pass `-scmProvider system` to the `xcodebuild` command, as mentioned in [Apple's documentation](https://developer.apple.com/documentation/swift_packages/building_swift_packages_or_apps_that_use_them_in_continuous_integration_workflows#3680255).
## What this Action *cannot* do for you
The following items are not issues, but beyond what this Action is supposed to do.
### Work on remote machines
### Work on Remote Machines
When using `ssh` to connect from the GitHub Action worker node to another machine, you *can* forward the SSH Agent socket and use your private key on the other (remote) machine. However, this Action will not configure `known_hosts` or other SSH settings on the remote machine for you.
### Provide the SSH key as a file
### Provide the SSH Key as a File
This Action is designed to pass the SSH directly into `ssh-agent`; that is, the key is available in memory on the GitHub Action worker node, but never written to disk. As a consequence, you _cannot_ pass the key as a build argument or a mounted file into Docker containers that you build or run on the worker node. You _can_, however, mount the `ssh-agent` Unix socket into a Docker container that you _run_, set up the `SSH_AUTH_SOCK` env var and then use SSH from within the container (see #11).
This Action is designed to pass the SSH key directly into `ssh-agent`; that is, the key is available in memory on the GitHub Action worker node, but never written to disk. As a consequence, you _cannot_ pass the key as a build argument or a mounted file into Docker containers that you build or run on the worker node. You _can_, however, mount the `ssh-agent` Unix socket into a Docker container that you _run_, set up the `SSH_AUTH_SOCK` env var and then use SSH from within the container (see https://github.com/webfactory/ssh-agent/issues/11).
### Run `ssh-keyscan` to add host keys for additional hosts
### Run `ssh-keyscan` to Add Host Keys for Additional Hosts
If you want to use `ssh-keyscan` to add additional hosts (that you own/know) to the `known_hosts` file, you can do so with a single shell line in your Action definition. You don't really need this Action to do this for you.
As a side note, using `ssh-keyscan` without proper key verification is susceptible to man-in-the-middle attacks. You might prefer putting your _known_ SSH host key in your own Action files to add it to the `known_hosts` file. The SSH host key is not secret and can safely be committed into the repo.
## Creating SSH keys
## Creating SSH Keys
In order to create a new SSH key, run `ssh-keygen -t ed25519 -a 100 -f path/to/keyfile`, as suggested in [this blog post](https://stribika.github.io/2015/01/04/secure-secure-shell.html).
If you need to work with some older server software and need RSA keys, tr `ssh-keygen -t rsa -b 4096 -o -f path/to/keyfile` instead.
If you need to work with some older server software and need RSA keys, try `ssh-keygen -t rsa -b 4096 -o -f path/to/keyfile` instead.
Both commands will prompt you for a key passphrase and save the key in `path/to/keyfile`.
In general, having a passphrase is a good thing, since it will keep the key encrypted on your disk. When using the key with this action, however, you need to make sure you don't
specify a passphrase: The key must be usable without reading the passphrase from input. Since the key itself is stored using GitHub's "Secret" feature, it should be fairly safe anyway.
## Authorizing a key
## Authorizing a Key
To actually grant the SSH key access, you can on GitHub use at least two ways:
* [Deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) can be added to individual GitHub repositories. They can give read and/or write access to the particular repository. When pulling a lot of dependencies, however, you'll end up adding the key in many places. Rotating the key probably becomes difficult.
* [Deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) can be added to individual GitHub repositories. They can give read and/or write access to the particular repository. When pulling a lot of dependencies, however, you'll end up adding the key in many places. Rotating the key probably becomes difficult. The deploy key needs to be added to the private repository that is being fetched as a private dependency.
* 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.
@@ -113,10 +195,27 @@ To actually grant the SSH key access, you can on GitHub use at least two
As a note to my future self, in order to work on this repo:
* Clone it
* Run `npm install` to fetch dependencies
* Run `yarn install` to fetch dependencies
* _hack hack hack_
* `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.
* Run `./node_modules/.bin/ncc build index.js` to update `dist/index.js`, which is the file actually run
* `node index.js`. Inputs are passed through `INPUT_` env vars with their names uppercased.
On *nix use:
```bash
env "INPUT_SSH-PRIVATE-KEY=\`cat file\`" node index.js
```
On Windows (cmd):
```cmd
set /P INPUT_SSH-PRIVATE-KEY=< file
node index.js
```
On Windows (PowerShell):
```ps
${env:INPUT_SSH-PRIVATE-KEY} = (Get-Content .\test-keys -Raw); node index.js
node index.js
```
* Run `npm run build` to update `dist/*`, which holds the files actually run
* Read https://help.github.com/en/articles/creating-a-javascript-action if unsure.
* Maybe update the README example when publishing a new version.
@@ -129,4 +228,4 @@ developer looking for new challenges, we'd like to hear from you!
- <https://www.webfactory.de>
- <https://twitter.com/webfactory>
Copyright 2019 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).
Copyright 2019 2022 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).

View File

@@ -6,10 +6,15 @@ inputs:
required: true
ssh-auth-sock:
description: 'Where to place the SSH Agent auth socket'
default: /tmp/ssh-auth.sock
log-public-key:
description: 'Whether or not to log public key fingerprints'
required: false
default: true
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'
post: 'dist/cleanup.js'
post-if: 'always()'
branding:
icon: loader
color: 'yellow'

12
cleanup.js Normal file
View File

@@ -0,0 +1,12 @@
const core = require('@actions/core');
const { execFileSync } = require('child_process');
const { sshAgent } = require('./paths.js');
try {
// Kill the started SSH agent
console.log('Stopping SSH agent');
execFileSync(sshAgent, ['-k'], { stdio: 'inherit' });
} catch (error) {
console.log(error.message);
console.log('Error stopping the SSH agent, proceeding anyway');
}

2846
dist/cleanup.js vendored Normal file

File diff suppressed because it is too large Load Diff

2762
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,12 @@
const core = require('@actions/core');
const child_process = require('child_process');
const fs = require('fs');
const crypto = require('crypto');
const { home, sshAgent, sshAdd } = require('./paths.js');
try {
const home = process.env['HOME'];
const homeSsh = home + '/.ssh';
const privateKey = core.getInput('ssh-private-key').trim();
const privateKey = core.getInput('ssh-private-key');
const logPublicKey = core.getBooleanInput('log-public-key', {default: true});
if (!privateKey) {
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.");
@@ -15,24 +14,78 @@ try {
return;
}
const homeSsh = home + '/.ssh';
console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`);
fs.mkdirSync(homeSsh, { recursive: true});
fs.mkdirSync(homeSsh, { recursive: true });
fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=\n');
fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl\n');
fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n');
fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-dss AAAAB3NzaC1kc3MAAACBANGFW2P9xlGU3zWrymJgI/lKo//ZW2WfVtmbsUZJ5uyKArtlQOT2+WRhcg4979aFxgKdcsqAYW3/LS1T2km3jYW/vr4Uzn+dXWODVk5VlUiZ1HFOHf6s6ITcZvjvdbp6ZbpM+DuJT7Bw+h5Fx8Qt8I16oCZYmAPJRtu46o9C2zk1AAAAFQC4gdFGcSbp5Gr0Wd5Ay/jtcldMewAAAIATTgn4sY4Nem/FQE+XJlyUQptPWMem5fwOcWtSXiTKaaN0lkk2p2snz+EJvAGXGq9dTSWHyLJSM2W6ZdQDqWJ1k+cL8CARAqL+UMwF84CR0m3hj+wtVGD/J4G5kW2DBAf4/bqzP4469lT+dF2FRQ2L9JKXrCWcnhMtJUvua8dvnwAAAIB6C4nQfAA7x8oLta6tT+oCk2WQcydNsyugE8vLrHlogoWEicla6cWPk7oXSspbzUcfkjN3Qa6e74PhRkc7JdSdAlFzU3m7LMkXo1MHgkqNX8glxWNVqBSc0YRdbFdTkL0C6gtpklilhvuHQCdbgB3LBAikcRkDp+FCVkUgPC/7Rw==\n');
console.log("Starting ssh-agent");
const authSock = core.getInput('ssh-auth-sock');
child_process.execFileSync('ssh-agent', ['-a', authSock]);
core.exportVariable('SSH_AUTH_SOCK', authSock);
console.log("Adding private key to agent");
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
child_process.execSync('ssh-add -', { input: key.trim() + "\n" });
const authSock = core.getInput('ssh-auth-sock');
const sshAgentArgs = (authSock && authSock.length > 0) ? ['-a', authSock] : [];
// Extract auth socket path and agent pid and set them as job variables
child_process.execFileSync(sshAgent, sshAgentArgs).toString().split("\n").forEach(function(line) {
const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(line);
if (matches && matches.length > 0) {
// This will also set process.env accordingly, so changes take effect for this script
core.exportVariable(matches[1], matches[2])
console.log(`${matches[1]}=${matches[2]}`);
}
});
console.log("Keys added:");
child_process.execSync('ssh-add -l', { stdio: 'inherit' });
console.log("Adding private key(s) to agent");
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {
child_process.execFileSync(sshAdd, ['-'], { input: key.trim() + "\n" });
});
console.log("Key(s) added:");
child_process.execFileSync(sshAdd, ['-l'], { stdio: 'inherit' });
console.log('Configuring deployment key(s)');
child_process.execFileSync(sshAdd, ['-L']).toString().split(/\r?\n/).forEach(function(key) {
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);
if (!parts) {
if (logPublicKey) {
console.log(`Comment for (public) key '${key}' does not match GitHub URL pattern. Not treating it as a GitHub deploy key.`);
}
return;
}
const sha256 = crypto.createHash('sha256').update(key).digest('hex');
const ownerAndRepo = parts[1].replace(/\.git$/, '');
fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });
child_process.execSync(`git config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://github.com/${ownerAndRepo}"`);
child_process.execSync(`git config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "git@github.com:${ownerAndRepo}"`);
child_process.execSync(`git config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);
const sshConfig = `\nHost key-${sha256}.github.com\n`
+ ` HostName github.com\n`
+ ` IdentityFile ${homeSsh}/key-${sha256}\n`
+ ` IdentitiesOnly yes\n`;
fs.appendFileSync(`${homeSsh}/config`, sshConfig);
console.log(`Added deploy-key mapping: Use identity '${homeSsh}/key-${sha256}' for GitHub repository ${ownerAndRepo}`);
});
} catch (error) {
if (error.code == 'ENOENT') {
console.log(`The '${error.path}' executable could not be found. Please make sure it is on your PATH and/or the necessary packages are installed.`);
console.log(`PATH is set to: ${process.env.PATH}`);
}
core.setFailed(error.message);
}

26
package-lock.json generated
View File

@@ -1,26 +0,0 @@
{
"name": "webfactory-action-ssh-agent",
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@actions/core": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.0.tgz",
"integrity": "sha512-KKpo3xzo0Zsikni9tbOsEQkxZBGDsYSJZNkTvmo0gPSXrc98TBOcdTvKwwjitjkjHkreTggWdB1ACiAFVgsuzA==",
"dev": true
},
"@zeit/ncc": {
"version": "0.20.5",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.20.5.tgz",
"integrity": "sha512-XU6uzwvv95DqxciQx+aOLhbyBx/13ky+RK1y88Age9Du3BlA4mMPCy13BGjayOrrumOzlq1XV3SD/BWiZENXlw==",
"dev": true
},
"child_process": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/child_process/-/child_process-1.0.2.tgz",
"integrity": "sha1-sffn/HPSXn/R1FWtyU4UODAYK1o=",
"dev": true
}
}
}

View File

@@ -2,13 +2,15 @@
"name": "webfactory-action-ssh-agent",
"repository": "git@github.com:webfactory/ssh-agent.git",
"description": "GitHub Action to set up ssh-agent with a private SSH key",
"version": "0.1.0",
"version": "0.6.0",
"main": "index.js",
"author": "webfactory GmbH <info@webfactory.de>",
"license": "MIT",
"devDependencies": {
"@actions/core": "^1.1.0",
"@zeit/ncc": "^0.20.5",
"child_process": "^1.0.2"
"@actions/core": "^1.9.1",
"@zeit/ncc": "^0.20.5"
},
"scripts": {
"build": "node scripts/build.js"
}
}

18
paths.js Normal file
View File

@@ -0,0 +1,18 @@
const os = require('os');
module.exports = (process.env['OS'] != 'Windows_NT') ? {
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
// Action runs, where $HOME is different from the pwent
home: os.userInfo().homedir,
sshAgent: 'ssh-agent',
sshAdd: 'ssh-add'
} : {
home: os.homedir(),
sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe',
sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe'
};

41
scripts/build.js Normal file
View File

@@ -0,0 +1,41 @@
const { execSync } = require('child_process')
const path = require('path')
const fs = require('fs')
const process = require('process')
const buildDir = path.join(process.cwd(), 'build')
const distDir = path.join(process.cwd(), 'dist')
const buildIndexJs = path.join(buildDir, 'index.js')
const distIndexJs = path.join(distDir, 'index.js')
const distCleanupJs = path.join(distDir, 'cleanup.js')
var ncc = `./node_modules/.bin/ncc`;
if (process.platform === "win32") {
ncc = `.\\node_modules\\.bin\\ncc.cmd`;
}
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir)
}
// Build the main index.js file
console.log('Building index.js...')
execSync(`${ncc} build index.js -q -o ${buildDir}`)
if (fs.existsSync(distIndexJs)) {
fs.unlinkSync(distIndexJs)
}
fs.renameSync(buildIndexJs, distIndexJs)
// Build the cleanup.js file
console.log('Building cleanup.js...')
execSync(`${ncc} build cleanup.js -q -o ${buildDir}`)
if (fs.existsSync(distCleanupJs)) {
fs.unlinkSync(distCleanupJs)
}
fs.renameSync(buildIndexJs, distCleanupJs)
console.log('Cleaning up...')
fs.rmdirSync(buildDir)
console.log('Done')

33
yarn.lock Normal file
View File

@@ -0,0 +1,33 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@actions/core@^1.9.1":
"integrity" "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA=="
"resolved" "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz"
"version" "1.9.1"
dependencies:
"@actions/http-client" "^2.0.1"
"uuid" "^8.3.2"
"@actions/http-client@^2.0.1":
"integrity" "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw=="
"resolved" "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz"
"version" "2.0.1"
dependencies:
"tunnel" "^0.0.6"
"@zeit/ncc@^0.20.5":
"integrity" "sha512-XU6uzwvv95DqxciQx+aOLhbyBx/13ky+RK1y88Age9Du3BlA4mMPCy13BGjayOrrumOzlq1XV3SD/BWiZENXlw=="
"resolved" "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.20.5.tgz"
"version" "0.20.5"
"tunnel@^0.0.6":
"integrity" "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
"resolved" "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz"
"version" "0.0.6"
"uuid@^8.3.2":
"integrity" "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
"resolved" "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz"
"version" "8.3.2"