Giter VIP home page Giter VIP logo

ssh-agent's Introduction

ssh-agent GitHub Action

This action

  • starts the ssh-agent,
  • exports the SSH_AUTH_SOCK environment variable, and
  • loads one or several private SSH key into the agent.

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 ๐Ÿ‘ at #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.

GitHub Actions only have access to the repository they run for. So, in order to access additional private repositories, create an SSH key with sufficient access privileges. Then, use this action to make the key available with ssh-agent on the Action worker node. Once this has been set up, git clone commands using ssh URLs will just work. Also, running ssh commands to connect to other servers will be able to use the key.

Usage

  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. 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.
    • 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@v4 line.
# .github/workflows/my-workflow.yml
jobs:
    my_job:
        ...
        steps:
            - uses: actions/checkout@v4
            # Make sure the @v0.9.0 matches the current version of the action
            - uses: webfactory/[email protected]
              with:
                  ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
            # ... other steps
  1. 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

There are cases where you might need to use multiple keys. For example, "deploy keys" might be limited to a single repository, so you'll need several of them.

You can set up different keys as different secrets and pass them all to the action like so:

# ... contents as before
            - uses: webfactory/[email protected]
              with:
                  ssh-private-key: |
                        ${{ secrets.FIRST_KEY }}
                        ${{ secrets.NEXT_KEY }}
                        ${{ secrets.ANOTHER_KEY }}

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. But when you're using GitHub Deploy Keys, read on!

Support for GitHub Deploy Keys

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.

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.

  1. When creating the deploy key for a repository like [email protected]:owner/repo.git or https://github.com/owner/repo, put that URL into the key comment. (Hint: Try ssh-keygen ... -C "[email protected]: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. It will redirect git requests to URLs starting with either https://github.com/owner/repo or [email protected]:owner/repo to a fake hostname/URL like [email protected]...: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.
  • ssh-agent-cmd: Optional. Use this to specify a custom location for the ssh-agent binary.
  • ssh-add-cmd: Optional. Use this to specify a custom location for the ssh-add binary.
  • git-cmd: Optional. Use this to specify a custom location for the git binary.

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 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

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.

Building Docker Images and/or Using the docker/build-push-action Action

When you are building Docker images with docker build or docker compose build and need to provide the SSH keys to the build, don't forget to pass --ssh default=${{ env.SSH_AUTH_SOCK }} on the command line to pass the SSH agent socket through. See the Docker documentation for more information on this option.

If you are using the docker/build-push-action, you can do so by adding the following config.

      - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          ssh: |
            default=${{ env.SSH_AUTH_SOCK }}

Make sure not to miss the next section, though.

Using Multiple Deploy Keys Inside Docker Builds

When you pass the SSH agent socket to the Docker build environment and want to use multiple GitHub deploy keys, you need to copy the Git and SSH configuration files to the build environment as well. This is necessary in addition to forwarding the SSH agent socket into the build process. The config files are required so that Git can pick the right one from your deployment keys.

This requires an additional step in the workflow file after the ssh-agent step and before the Docker build step. You also need two additional lines in the Dockerfile to actually copy the configs.

The following example will:

  • collect the necessary Git and SSH configuration files in a directory that must be part of the Docker build context so that...
  • ... the files can be copied into the Docker image (or an intermediate build stage).

Workflow:

      - name: ssh-agent setup
        ...

      - name: Collect Git and SSH config files in a directory that is part of the Docker build context
        run: |
          mkdir root-config
          cp -r ~/.gitconfig  ~/.ssh root-config/
  
      - name: Docker build 
        # build-push-action | docker [compose] build | etc.
        ...

Dockerfile:

# Copy the two files in place and fix different path/locations inside the Docker image
COPY root-config /root/
RUN sed 's|/home/runner|/root|g' -i.bak /root/.ssh/config

Keep in mind that the resulting Docker image now might contain these customized Git and SSH configuration files! Your private SSH keys are never written to files anywhere, just loaded into the SSH agent and forwarded into the container. The config files might, however, give away details about your build or development process and contain the names and URLs of your (private) repositories. You might want to use a multi-staged build to make sure these files do not end up in the final image.

If you still get the error message: fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists., you most likely forgot one of the steps above.

Cargo's (Rust) Private Dependencies on Windows

If you are using private repositories in your dependencies like this:

stuff = { git = "ssh://[email protected]/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.

  1. 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.

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

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

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 #11).

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

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. 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

To actually grant the SSH key access, you can โ€“ on GitHub โ€“ use at least two ways:

  • 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 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.

Hacking

As a note to my future self, in order to work on this repo:

  • Clone it

  • Run yarn install to fetch dependencies

  • hack hack hack

  • node index.js. Inputs are passed through INPUT_ env vars with their names uppercased.

    On *nix use:

    env "INPUT_SSH-PRIVATE-KEY=\`cat file\`" node index.js

    On Windows (cmd):

    set /P INPUT_SSH-PRIVATE-KEY=< file
    node index.js

    On Windows (PowerShell):

    ${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.

Credits, Copyright and License

This action was written by webfactory GmbH, Bonn, Germany. We're a software development agency with a focus on PHP (mostly Symfony). If you're a developer looking for new challenges, we'd like to hear from you!

Copyright 2019 โ€“ 2023 webfactory GmbH, Bonn. Code released under the MIT license.

ssh-agent's People

Contributors

ad-m avatar archen avatar benzado avatar bigearsenal avatar camilo-celis avatar cecton avatar dependabot[bot] avatar dilumaluthge avatar dwalkes avatar felix-seifert avatar j-riebe avatar jieter avatar jmandel avatar johnhamelink avatar jrmash avatar kjarkur avatar koshieguchi avatar maciejp-ro avatar mjhipp avatar mpdude avatar npwolf avatar ochococo avatar prhiggins avatar rorcores avatar ryanzidago avatar sebastiankugler avatar shashank11p avatar the-mikedavis avatar thommyhh avatar typeoneerror avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ssh-agent's Issues

Command failed: ssh-add -

Hi, I have been having issue today with this error Command failed: ssh-add -. I have been using this action for long time and never had a problem, could you help me debug what's wrong?

Here my workflow file:

name: Test Registry packace

on:
  push:
    branches:
      - master
  repository_dispatch:

jobs:
  publish:
    runs-on: ubuntu-latest
    name: Publish on the server
    steps:
      - name: Check out the repo
        uses: actions/[email protected]

      - name: Login to GitHub Packages Docker Registry
        uses: docker/login-action@v1
        with:
          registry: docker.pkg.github.com
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Set SSH key for remote host
        uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.DO_SSH_KEY }}

      - name: Create a docker context for remote machine
        run: docker context create digital_ocean --docker="host=${{secrets.DO_HOST}}"

      - name: Launch new configuration
        run: docker-compose --context digital_ocean -f docker-compose.prod.yml up -d --build --force-recreate

      - name: Logout from docker
        run: docker logout

And here the error I got.

Screenshot 2020-11-27 at 21 02 27

Error: spawnSync ssh-agent ENOENT

Hi, any idea why i have this error ?

Adding GitHub.com keys to /github/home/.ssh/known_hosts
Starting ssh-agent
Error: spawnSync ssh-agent ENOENT

Thank you !

Leaks private key in build logs

When I build I get the following text in the actions log:

Adding private key(s) to agent
Key(s) added:
3072 SHA256:sgR7...Z7qM [email protected] (RSA)
Configuring deployment key(s)
Comment for key 'ssh-rsa AA...iNk= [email protected]' does not match GitHub URL pattern. Not treating it as a GitHub deploy key.

The key was added to ssh-agent and functionality is correct (I'm not using it as a deploy key), but the full text of the private key is leaked in the build logs. Please fix?

What is the proper private key format?

Hi there,

I'm trying to fetch private repo as a dependency in GitHub Actions for an Elixir/Phoenix application.

  • I created a new public/private key pair with the ssh-keygen -t ed25519 -a 100 -f /home/ryan/.ssh/github_actions command and without any passphrase
  • I copied the private key using xclip -sel clip < ~/.ssh/github_actions and pasted the content in the secret config of the GitHub repository where I wish to run the GitHub Actions with the title SSH_PRIVATE_KEY
  • I copied the public key using xclip -sel clip < ~/.ssh/github_actions.pub and pasted the content in the deploy_key config of GitHub under the title GITHUB_ACTIONS_DEPLOY_KEYS
  • I added these lines in my workflow definition file:
- uses: webfactory/[email protected]
              with:
                  ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
  • then I commited the changes/pushed the changes to the repo and let GHA works. However, I get the following error message when the steps for fetching dependencies is triggered:
Load key "/home/runner/.ssh/id_rsa": invalid format
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
** (Mix) Command "git --git-dir=.git fetch --force --quiet --progress" failed
##[error]Process completed with exit code 1.

Apparently, the key format is wrong. Which key format should be used?

Deploy keys do not work on Windows

Using GitHub deploy keys as described in the README file does not work in Windows. Using "plain" keys (i. e. without the repo mapping provided in the comment) works, but you might be limited in how many of these keys can be tried before the remote server aborts the connection.

When deploy keys are used, this action writes the public key information (as shown by ssh-add -L) into a file, and configures SSH via IdentityFile to use this identity when connecting to the host. Also, IdentitiesOnly is turned on to try only the particular key.

On Linux systems (at least, the Ubuntu-based virtual action environments) and OS X, this works: It identifies the key to use via the public key part, but fetches the key from the SSH Agent.

On Windows, it fails. Here's the output from the ssh -v level:

debug1: Will attempt key: C:\\Users\\runneradmin/.ssh/5965bf89ab6e2900262e3f6802dfb4d65cb0de539d0fbb97d381e7130a4ba7e9 ED25519 SHA256:phogSrSHUbBX0b8klUZDZrXx68sb1gat5rDrA67VX4Y explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: C:\\Users\\runneradmin/.ssh/5965bf89ab6e2900262e3f6802dfb4d65cb0de539d0fbb97d381e7130a4ba7e9 ED25519 SHA256:phogSrSHUbBX0b8klUZDZrXx68sb1gat5rDrA67VX4Y explicit
debug1: Server accepts key: C:\\Users\\runneradmin/.ssh/5965bf89ab6e2900262e3f6802dfb4d65cb0de539d0fbb97d381e7130a4ba7e9 ED25519 SHA256:phogSrSHUbBX0b8klUZDZrXx68sb1gat5rDrA67VX4Y explicit
Load key "C:\\Users\\runneradmin/.ssh/5965bf89ab6e2900262e3f6802dfb4d65cb0de539d0fbb97d381e7130a4ba7e9": invalid format

As you can see, SSH on Windows complains that the key is in an invalid format. This is because the file contains the public key part, but IdentityFile should point to a private key file.

There is a bug report over at PowerShell/Win32-OpenSSH#1550 which describes that IdentitiesOnly will make SSH ignore keys from the SSH Agent. However, since removing IdentitiesOnly in this action here does not solve or work around the issue. So, the two things might be related, but it's not exactly the same problem.

One way of working around this would be to write the private key files to disk (at least under Windows), so that ssh can pick the right identity from the file. Writing keys to disk or file, however, is something this action has tried to avoid in the first place: With keys on disk, any subsequent action or process might read/steal the key. With the current action design, the private keys are passed right from GitHub Secrets into the ssh-agent process and cannot be recovered from there later on. So, I'm a bit reluctant to make this change.

I can raise an issue over at https://github.com/PowerShell/Win32-OpenSSH/, however I have no idea if this is the right place to report, how quickly the issue could be fixed and when an update would make it into virtual Windows environments.

fatal: Could not read from remote repository

This might be obvious, but I'm having a lot of trouble using an SSH key (a deploy key) using this action. I have the following workflow (fragment):

      - uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.DeployKey }}

      - name: Checkout the other repository
        run: |
          git clone [email protected]:Org/RepoName.git

However that gives me:

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I know the deploy key works, and I also know it's correctly inserted as a secret. Any idea why this might be happening?

ssh-agent not starting on container based workflow

I am running a workflow on ubuntu-20.04 with container centos:7.

job-name:
    runs-on: ubuntu-20.04
    container:
      image: centos:7
    steps:
      - uses: webfactory/[email protected]
        with:
          ssh-private-key: |
            ${{ secrets.SSH_KEY }}
            ${{ secrets.SSH_KEY_2 }}

I get this error while starting the ssh-agent.

Adding GitHub.com keys to /root/.ssh/known_hosts
Starting ssh-agent
Error: spawnSync ssh-agent ENOENT

Can someone help me fix this?

Unable to find version v0.4.1

Hy @mpdude,

I am trying to use v0.4.1 but it is unable to find by github actions then I tried for the previous version v0.4.0 but it is not working also because --set-env: is being deprecated by github.

Make this action work on Windows as well

When using this github action on windows it's not happy as off two days ago.

I currently get the error

unable to start ssh-agent service, error :1058

I am currently trying to figure out what changed on windows 2019 on github actions ...

Still got error fatal: repository not found

Hello,
I am still facing with fatal error after use webfactory/ssh-agent

fatal: repository 'https://github.com/mycompany/mycompany-package.git/' not found

This is my deploy flow

name: CI Dev

on:
  push:
    branches: [ develop ]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:

    - name: Set SSH Key Agent
      uses: webfactory/[email protected]
      with:
        ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

    - uses: actions/checkout@v2
        
    - name: Install node modules
      run: yarn

This is error
Screen Shot 0002-05-16 at 18 42 05

This is package.json

{
    ...
    "mycompany-package": "git+https://github.com/mycompany/mycompany-package.git",
    ....
}

Please help!

SCP Workflow on Windows

Thanks for providing this action, I am a very happy user!

I have recently stumbled across an issue on Windows with one of my use cases: I am using the action to set up a private key, which I then use to copy large, non-public files with scp from a VM hosted at my institution to the GitHub runner. The workflow works fine on Linux. On Windows, the action itself is successful, but the scp operation in a subsequent step fails with Permission denied (publickey)..

After reading carefully through #63 I was able to actually fix the problem by replacing my plain usage of scp on Windows with c://progra~1//git//usr//bin//scp.exe. I am happy to have found this fix, but I really do not like it. I would prefer it if this action could modify the environment such that the correct versions of SSH-related executables are picked up. I can imagine this in both an implicit way (like modifying path variables) or an explicit way (like export e.g. an SCP_BIN environment variable for the user to use).

Feel free to ignore and close this if you consider it out of scope of the action.

Example Usage is Unclear

It's unclear how to issue a command on the host once an ssh connection is established. Please provide an example. In the example below, I'd like to run the php command on the host, rather than the action environment.

    - name: SSH Into Env
      uses: webfactory/[email protected]
      with:
        ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
    - name: Remotely Create Symbolic Link for Storage
      run: php artisan storage:link

image

Fail to build image with yarn install calling other repo

Hi,

I'm trying to build my docker image (it runs like a charm locally). Locally, i pass docker build args with my private and public key (this key is on the second repo). When yarn install calls the private repo, i get an "not authorized".

My config:

name: Docker Image CI (posts@v1)

on: [push]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: webfactory/ssh-agent
  uses: webfactory/[email protected]
  with:
      ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Build the Docker image
  run: docker build --build-arg ssh_prv_key="$(cat key)" --build-arg ssh_pub_key="$(cat key.pub)" . --file Dockerfile --tag mydockerimage/image:$(date +%s)

This action above fails.

This action below, fails too.

  • name: Build the Docker image
    run: docker build . --file Dockerfile --tag mydockerimage/image:$(date +%s)

What i did wrong?

Thanks

Fabio

Go compatibility

I struggled to get Go private modules working and wanted to share my workaround in case it's helpful or the changes can be incorporated. Basically the default .gitconfig generated when using commented keys doesn't seem to work with go get and related commands.

The tl;dr is I need the config to go from this:

[url "git@d5ec..:my-org/my-repo.git"]
	insteadOf = https://github.com/my-org/my-repo.git
        ...

to

[url "ssh://git@d5ec.../my-org/my-repo"]
	insteadOf = https://github.com/my-org/my-repo
	...

The key differences being:

  • urls do not end with .git
  • url needs to be ssh:// formatted. i.e., first : -> /, and the scheme.

The reason for this seems to be that go interacts with git by specifying the origin as https://github.com/my-org/my-repo, which works, but won't match the longer (arguably more correct) URL you've put in the config. e.g., internally go is doing git remote add origin -- https://github.com/my-org/my-repo without a trailing slash or .git.

I'm currently working around this with this sed script:

          sed -i.bak -re '
          s|(insteadOf.*https://.*)\.git$|\1|g
          s|\[url "(git@[^:]*]?):(.*?)\.git"\]$|[url "ssh://\1/\2"]|g' ~/.gitconfig

NOTE: For anyone else trying to get this working, you will also need GOPRIVATE=github.com/my-org/* as an environment variable.

Run inside a Docker container

It took me forever to figure out, why this action doesn't work if I run the whole workflow inside a container.
The problem is that the Github Action somehow changes/sets the HOME variable inside the container so that the ~/.ssh/known_hosts file is at a wrong location.
This action puts the Github PubKeys inside ~/.ssh/known_hosts which is in the home path of the runner. But the running container normally runs as root so ssh looks for /root/.ssh/known_hosts which doesn't exist.
Copying the known_hosts to this location if the workflow is running inside Docker solves the problem. As I am a total Node noob I just played around with the dist/index.js file, but putting the following snippet after creating the known_hosts file the SSH agent also works inside docker:

    if(fs.existsSync('/.dockerenv') && child_process.execFileSync('id', ['-u']).toString().trim() === '0') {
        fs.mkdirSync('/root/.ssh', { recursive: true});
        fs.copyFileSync(`${homeSsh}/known_hosts`, '/root/.ssh/known_hosts');
    }

I'm not sure if that somehow breaks running the action in Windows because in Windows there is no id command. But that shouldn't be a problem because Github Actions currently doesn't allow running non-Linux containers. Also, I don't know if the root check is even necessary because probably all containers run as root.

Would it be possible to add this snippet to your action so Docker users can also use it? :)

Invalid Home Directory

When I want to use your action on macOS environment it produces the following error.

Run webfactory/[email protected]
   with:
    ssh-private-key: ***
  
    ssh-auth-sock: /tmp/ssh-auth.sock
Adding GitHub.com keys to /home/runner/ssh_known_hosts
##[error]ENOENT: no such file or directory, mkdir '/home/runner/.ssh'
##[error]Node run failed with exit code 1

Multiple Deploy Keys within npm/node application failing to authenticate with Private Repos

Hi there,

I'm trying to fetch multiple private repos as dependencies in GitHub Actions for an node/npm application. I'll be upfront, I'm not very knowledgable on ssh keys and ssh authentication in general but I have done a lot of testing to try to debug where I'm going wrong. I'll outline steps I've taken and troubleshooting and results:

Steps taken so far:

  1. Generated key for Private Repo A using: ssh-keygen -t ed25519 -a 100 -f ~/.ssh/keys/A - this was generated without passphrase - I ran into that issue at first
  2. Copied value from A.pub into the A repo's Deploy Keys and then added the url in the comment field instead of the local identifier that was added to the comments during the keygen process. So the value was something along the lines of ssh-ed25510 *redacted* https://github.com/organization/A
  3. Copied value from A into a secret within Repo C for Github Actions and named it A_PRIVATE_KEY
  4. keygen the same way for B
  5. Copied value from B.pub into B Deploy Keys and then added url to comment field resulting in something like: ssh-ed25510 *redacted* https://github.com/organization/B
  6. Copied value from B into a secret within Repo C for Github Actions and named it B_PRIVATE_KEY
  7. Added both keys per the docs (see code example 1)
  8. Github Action does an npm ci but fails with "ERROR: Repository not found." which I assume is specifically failing to authenticate

Code Example 1

    - uses: webfactory/[email protected]
      with:
        ssh-private-key: |
          ${{ secrets.A_PRIVATE_KEY }}
          ${{ secrets.B_PRIVATE_KEY }}

Troubleshooting/debugging:

  • I've tested with just a single key and depending on the key that is used, the errors will appropriately display (using A key, success with A repo but fails installing B repo.
  • I have found that the output messaging is not what I would expect it to be:
Key(s) added:
256 SHA256:/*redacted* [email protected] (ED25519)
256 SHA256:*redacted* [email protected] (ED25519)
Configuring deployment key(s)

Things that seem strange about this:

  • I have replaced the comment collinb@ with the url of each private repo in the public keys within each private dependency A and B.
  • I was expecting to see additional stdout for each key but nothing every shows other than Configuring deployment keys(s) and then it's sort of a silent failure. I did test the regex used to make sure I didn't have some sort of incorrect format and the format I was using https://github.com/organization/A was properly matching.
  • I added a test clone step (code example 2) to try to mirror what you are doing in your repo but this fails with fatal: could not read Username for 'https://github.com': No such device or address

Code Example 2

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: webfactory/[email protected]
      with:
        ssh-private-key: |
          ${{ secrets.B_PRIVATE_KEY }}
          ${{ secrets.A_PRIVATE_KEY }}
    - name: Test Clone
      run: |
        git clone https://github.com/organization/A.git test-fc-http
        git clone [email protected]:organization/A.git test-fc-git
        git clone ssh://[email protected]/organization/A.git test-fc-git-ssh

I have been able to successfully install doing

    - uses: webfactory/[email protected]
      with:
        ssh-private-key: ${{ secrets.A_PRIVATE_KEY }}
    - name: Debugging with Git Clone 1
       run: git clone ssh://[email protected]/organization/A.git test-a-http

in other repositories but for some reason I am really struggling to get the multiple deploy key setup to work for the private github repositories using npm install.

  • Tested out different combinations of manual install and keys and have noticed that it will fail to authenticate when I use the comment field for the url of the repo in the public key. But if I switch it back to the collinb@ it will authenticate. I am pretty confident my issue relies in how I've generated the keys or configured my keys with the url and am unsure of my mistake.

I'm wondering if you might have any insight or steps that I can try out to try to get this to work on my end or point to how I've miss-configured the keys?

Thanks so much!

git URLs with capitalized letters (e.g. GitHub repos) not processed by the script

The below regex does not allow capital letters:

const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/);

This, combined with no console output, can leave the script only performing part of its functionality which may leave some users confused.

I see a few potential remedies here but I'm less familiar with the tool, so wanted to get some input.

It seems we could:

  • Adjust the regex to allow capital letters
  • Call ToLower() on the key prior to processing it in the regex
  • Be explicit about keys not matching and ensuring that we publish a message stating why.

I'll submit PRs for all three options in case you have a preference for one or the other. Also, please let me know if I'm misunderstanding the problem here.

Support passphrases

The motivation for this issue is well related to #36.

In my case, having this action to support passphrases would allow me to use this action prior to running a binary (Terraform) that will clone additional Github Repositories. Those repositories are private and are in a organization that requires SSH keys to have passphrases as a SAML policy.

If supporting it is really out of scope, could you please shed me some light on workarounds for this scenario?

Thanks in advance and great job!

Comment for key does not match Github URL pattern

I want to access two different private repositories that contain packages for an App. I have created one ssh key for each of the two repos, added the private key to the secrets of the App-Repository and the public keys as deploy keys in the private package repositories.

My workflow looks as follow:

- uses: webfactory/[email protected]
      with:
          ssh-private-key: |
              ${{ secrets.SSH_PRIVATE_KEY_APISERVICE }}
              ${{ secrets.SSH_PRIVATE_KEY_WIDGETS }}
    
    - run: git clone [email protected]:[organization-name]/[repository-name1]
    
    - run: git clone [email protected]:[organization-name]/[repository-name2]

The public keys look like the following:

ssh-rsa AA[...]Gj 
[email protected]:[organization-name]/[repository-name1]

Running the workflow produces the following log:

Adding GitHub.com keys to /home/runner/.ssh/known_hosts
Starting ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-To1irqpM9o5v/agent.1571
SSH_AGENT_PID=1572
Adding private key(s) to agent
Identity added: (stdin) ((stdin))
Identity added: (stdin) ((stdin))
Key(s) added:
2048 SHA256:lF6[...]JsM (stdin) (RSA)
2048 SHA256:Wqc[...]FMbA8 (stdin) (RSA)
Configuring deployment key(s)
Comment for key 'ssh-rsa AA[...]Gj (stdin)' does not match GitHub URL pattern. Not treating it as a GitHub deploy key.
Comment for key 'ssh-rsa AA[...]Gb (stdin)' does not match GitHub URL pattern. Not treating it as a GitHub deploy key.
Comment for key '' does not match GitHub URL pattern. Not treating it as a GitHub deploy key.

Afterwards, the first git clone command works as excpected, the second one fails with the error:

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Process completed with exit code 128.

It's always the second clone command that fails, even if I swap the order in which the repositories are cloned.

I'm stuck and don't know if I am doing something wrong, or if this is some Bug with this Action. Any help is very appreciated!

Deploy key not "treated as deploy key"

I have followed the guide to setup a deploy key on a private git repo for a Swift Package.

I generated new SSH in the private SP repo using this command: ssh-keygen -b 4096 -t rsa -N "" -f key -C "[email protected]:my-org/my-swift-package-repo.git"
I have added the .ssh/key files (private/public) and the config file with GitHub.com host to the private SP repo.
I have added the public key as a deploy key on the private SP repo.
I have added the private key as a secret on the other repo that has an app using the SP as a dependency.

No matter what, I get this error:

Comment for key '' does not match GitHub URL pattern. Not treating it as a GitHub deploy key.

xcodebuild: error: Could not resolve package dependencies:
10
  The remote repository could not be accessed. Make sure a valid repository exists at the specified location and that the correct credentials have been supplied.

Here is my yaml:

      - name: Set SSH Key for remote host
        uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.SPM_SSH_PUBLIC_KEY }}

Any help would be greatly appreciated!

Post-run actions on multi-usage

First of all, thanks for this GH-Action :-)

I'm using this action twice in my workflow because using a ssh-agent with multiple keys doesn't seem to work with the Gradle-plugin I'm using to push some data to Git-Repositories over ssh.

[...]
      - uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.WORKFLOW_SSH_KEY }}
        continue-on-error: true
      - name: Push data, if there are any changes
        run: ./gradlew gitPublishPush --info

      - uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.WORKFLOW_SSH_KEY_ARCHIV_REPO }}
        continue-on-error: true
      - name: Archive the PDFs in a private repo
        run: ./gradlew -b archive.gradle.kts gitPublishPush --info

This works fine, but I have to use continue-on-error because otherwise, the second post-run-action (which belongs to the first ssh-agent) fails:

grafik

Can I somehow trigger the post-run action manually at an earlier step?

Otherwise, I suggest to check in cleanup.js, if the process is already killed.

execSync('kill ${SSH_AGENT_PID}', { stdio: 'inherit' })

Host key verification failed

By scanning through the README file and existing issues, I understand that this is probably not an issue with ssh-agent. However, I still couldn't make it work after several attempts.

I want to take advantage of this action to copy test data from my local server.
By following the procedures, first I have

    steps:
    - uses: actions/checkout@v2
    - uses: webfactory/[email protected]
      with:
        ssh-private-key: ${{ secrets.CI_PRIVATE_KEY }}
    - name: Reference data
      run: |
        scp -o 'ProxyCommand ssh [email protected] -W %h:%p' username@server2:filename .
        cat filename

The private keys should have been properly set, and public keys are added both to the proxy and actual servers.

The runlog first displays

Run webfactory/[email protected]
Adding GitHub.com keys to /home/runner/.ssh/known_hosts
Starting ssh-agent
Adding private key to agent
Identity added: (stdin) (username@legion5)
Keys added:
256 SHA256:JP1loMqqwOspXFAwP44oeAbuaUV/OlATxEPxrEwOcDs username@legion5 (ED25519)

and then

Run scp -o 'ProxyCommand ssh username@server1 -W %h:%p' username@server2:filename .
Host key verification failed.
ssh_exchange_identification: Connection closed by remote host
Error: Process completed with exit code 1.

After some search, the general suggestion I found for dealing with the Host key verification failed msg was by using ssh-keygen, but I had no luck in a successful attempt. Can you kindly offer me some help?

Thanks!

Host key verification failed

Hey again, seems like I keep on bumping to your actions ๐Ÿ‘‹๐Ÿป

I've tried adding this, and I get a successful message

Starting ssh-agent
Adding private key to agent
Identity added: (stdin)

However, when trying to do a clone or submodule init, I get this:

Host key verification failed.
fatal: Could not read from remote repository.

I've tried cloning the repo using the key, and it works on my machine. I've seen a note in keyscan but I'm not really sure if it's the correct command

I used this to no avail
ssh-keyscan -t rsa bitbucket.org | ssh-keygen -lf -

Clone Private Repo failed

actions config

runs-on: ubuntu-latest
container:
      image: elixir:1.9.1-slim
      env:
        MIX_ENV: test
steps:
  - name: Checkout
    uses: actions/checkout@v1
  - name: create SSH key
    uses: webfactory/[email protected]
    with:
      ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
  - name: Install Dependencies
    run: |
        git clone [email protected]:zhulinpinyu/sf.git

error log:

Run git clone [email protected]:zhulinpinyu/sf.git
  git clone [email protected]:zhulinpinyu/sf.git
  shell: sh -e {0}
  env:
    SSH_AUTH_SOCK: /tmp/ssh-auth.sock
Cloning into 'sf'...
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
##[error]Process completed with exit code 128.

Solution: #25 (comment)

Thanks @stevie-

LFS support for multiple repos

It works fine with multiple repos as documented. However, if there are repos with LFS, it would fail.

One work around is to disable LFS by setting GIT_LFS_SKIP_SMUDGE environment variable to 1.

But there are circumstances where LFS is really needed to obtain large files. Is there plan to support this?

set-env command is disabled

Today I started getting the following error when using ssh-agent to set an ssh-private-key:

Error: Unable to process command '::set-env name=SSH_AUTH_SOCK::/tmp/ssh-pt8h3REXijrf/agent.2441' successfully.
Error: The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
Error: Unable to process command '::set-env name=SSH_AGENT_PID::2442' successfully.
Error: The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

Will this action now no longer be able to work?

SSH fingerprint failed to verify

I have set up a Xcode project with a private repository as dependency using Swift Package Manager. Therefore I have to add the ssh key for the dependency. Cloning the repository in a Github Action step is working well, but when I try to build the app in a step with xcodebuild I get the following error:

xcodebuild: error: Could not resolve package dependencies: The server SSH fingerprint failed to verify.

Support non-ephemeral, self-hosted runners

subsequent builds fail with:

Run webfactory/[email protected]
##[error]Node run failed with exit code 1
Run webfactory/[email protected]
Adding GitHub.com keys to undefined/.ssh/known_hosts
Starting ssh-agent
bind: Address already in use
unix_listener: cannot bind to path: /tmp/ssh-auth.sock
##[error]Command failed: ssh-agent -a /tmp/ssh-auth.sock
bind: Address already in use
unix_listener: cannot bind to path: /tmp/ssh-auth.sock

##[error]Node run failed with exit code 1

This is on a local github-runners, which are not ephemeral. Cleaning up the /tmp/ssh-auth.sock manually resolves this problem temporarily.

Replace deprecated set-env and add-path commands with new syntax

A moderate security vulnerability has been identified in the GitHub Actions runner that can allow environment variable and path injection in workflows that log untrusted data to stdout.

Action authors who are using the toolkit should update the @actions/core package to v1.2.6 or greater to get the updated addPath and exportVariable functions.

Action and workflow authors who are setting environment variables via stdout should update any usage of the set-env and add-path workflow commands to use the new environment files.

https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

I didn't see anything on this repo discussing this, so I thought I'd bring this to your attention if you hadn't noticed yet. I noticed a warning on my builds regarding the use of this action and the set-env command it's doing.

Exposes sensitive variables in logs

I can't use this for our company, as it dumps potentially sensitive private keys straight to the logs.

Unfortunately, it not only exposes them, but also reformats them, meaning the inbuilt github secret masking doesn't catch it.

Self-Hosted Agent Problem

On a self-hosted Agent Instance there pop up some error after building once. The second build shows this:

Run webfactory/[email protected]
bind: Address already in use
Adding GitHub.com keys to /root/.ssh/known_hosts
unix_listener: cannot bind to path: /tmp/ssh-auth.sock
Starting ssh-agent
##[error]Command failed: ssh-agent -a /tmp/ssh-auth.sock
bind: Address already in use
unix_listener: cannot bind to path: /tmp/ssh-auth.sock

I dont know how i can solve it, do you have an idea?
Best Regards

Multiple Deploy Keys in docker build fails

Not exactly a bug, but I found it challenging to find a solution that works with docker build when using multiple deploy keys. The reason seems to be that the build container doesn't have the ssh and git config necessary to map the right key to the right repo.

For example:

      - name: Setup SSH
        uses: webfactory/[email protected]
        with:
          ssh-private-key: |
            ${{ secrets.DEPLOY_KEY_A }}
            ${{ secrets.DEPLOY_KEY_B }}
      - name: Works Well!
        run: |
          git clone github.com/me/private-repo-a
          git clone github.com/me/private-repo-b
      - name: Doesn't work :(
        run: |
          cat > Dockerfile <<EOF
          FROM debian
          RUN --mount=type=ssh git clone github.com/me/private-repo-a
          RUN --mount=type=ssh git clone github.com/me/private-repo-b
          EOF
          docker build --ssh default .

The docker build has access to the keys, but it doesn't use the right one for each repo, so one of the checkouts will fail.

My solution was to copy the config into the container:

run: |
  mkdir root-config
  cp -r ~/.gitconfig  ~/.ssh root-config/
  docker build ... .

And in my Dockerfile:

COPY root-config /root/
RUN sed 's|/home/runner|/root|g' -i.bak /root/.ssh/config

That works, but it feels pretty hacky. I was just wondering if anyone can come up with a better way/wanted to document a way to make it work.

Advised usage for docker integration

Hey there!

Thanks for the great action.
Do you have any opinion on the best way to use this action with docker volumes?

I'm doing this but would like to know if there is a better way?

on: push

name: "Test"

jobs:
  build:
    name: "Test"

    runs-on: ubuntu-latest

    steps:

      - name: "Install SSH Key"
        uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

      - name: "Test"
        run: |
          docker run --rm \
            -v $SSH_AUTH_SOCK:/ssh-agent -v ~/.ssh/known_hosts:/root/.ssh/known_hosts -e SSH_AUTH_SOCK=/ssh-agent \
            image \
            bash -c "ssh-add -l && ssh -T [email protected]"

Thanks!

Get it to work with pm2

I struggle to get this to work with pm2.

I have create a new SSH key, added it as deploy key in my repo where the action runs. Added it as a secret in the repo too.

Thats the output:

[PM2] Spawning PM2 daemon with pm2_home=/home/runner/.pm2
[PM2] PM2 Successfully daemonized
--> Deploying to production environment
--> on host xxxx
fatal: HEAD does not point to a branch
  โ—‹ deploying origin/master
  โ—‹ executing pre-deploy-local
  โ—‹ hook pre-deploy
Host key verification failed.
  โ—‹ fetching updates
  โ—‹ full fetch
Host key verification failed.


  fetch failed

The action's usage can be reviewed here

And my pm2 ecosystem file

id_rsa key file does not exist after adding it?

Not really clear if I'm doing something wrong but I can't push to my remote because key does not exist.
I would expect that key is added to /home/runner/.ssh/id_rsa and then used from there, but that doesn't seam to be the case.
Any help appreciated, below is my output.

Adding keys:

Run webfactory/[email protected]
4096 SHA256:Ogd8/KGgSFwKpL4mfmEZFBesrshP5P9SYSQzDBQMfHg (stdin) (RSA)
Run webfactory/[email protected]
  with:
    ssh-private-key: ***
Adding GitHub.com keys to /home/runner/.ssh/known_hosts
Starting ssh-agent
Adding private key to agent
Identity added: (stdin) ((stdin))
Keys added:
4096 SHA256:Ogd8/KGgSFwKpL4mfmEZFBesrshP5P9SYSQzDBQMfHg (stdin) (RSA)

Check if file exists in ~/.ssh/, not there..

Run ls -al  ~/.ssh/
total 12
drwxr-xr-x  2 runner docker 4096 Sep  7 10:05 .
drwxrwxrwx 11 runner docker 4096 Sep  7 10:05 ..
-rw-r--r--  1 runner docker  994 Sep  7 10:05 known_hosts

Check if file exists in /home/runner/.ssh/, not there..

Run ls -al /home/runner/.ssh/
total 12
drwxr-xr-x  2 runner docker 4096 Sep  7 10:05 .
drwxrwxrwx 11 runner docker 4096 Sep  7 10:05 ..
-rw-r--r--  1 runner docker  994 Sep  7 10:05 known_hosts

Runing git push host:branch

debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/runner/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/runner/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/runner/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/runner/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/runner/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/runner/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/runner/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/runner/.ssh/id_ed25519-cert type -1

Host key verification

Doesn't it make sense to add ability to add host keys to ~/.ssh/known_hosts? From what I can see the alternative solution allows this. And you add GitHub host keys to the file anyway.

A workaround:

    - name: Add the host key
      run: |
        line='example.com,xx.xxx.xx.xxx ssh-rsa AAAA...kMIR'
        echo "$line" >> ~/.ssh/known_hosts

passphrase support

Make sure you don't have a passphrase set on the private key.

Any thoughts on adding support keys with passphrases?

Unable to get this action to work

I've spent today trying to get this GitHub action working but no matter what I try it doesn't do anything.

It appears to me as if the steps are no longer connected. For completeness, here's my workflow file.

deploy.yml

[...]
  steps:
  - uses: actions/checkout@v1
  - uses: webfactory/[email protected]
    with:
      ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
  - name: 'SSH: trust host'
    run: for ip in $(dig @1.1.1.1 ${DEPLOY_HOST} +short); do ssh-keyscan ${DEPLOY_HOST},$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts
    env:
      DEPLOY_HOST: "my-private-host.com"
  - name: "synoa/github-action-git-exec"
    uses: synoa/github-action-git-exec@master
    with:
      git_cmd: "git push user@${DEPLOY_HOST}:/path/to/my/repo.git HEAD:master"           
    env:
      GIT_SSH_COMMAND: "ssh -vvv -o StrictHostKeyChecking=no"
      SSH_AUTH_SOCK: "/tmp/ssh-auth.sock"
      DEPLOY_HOST: "my-private-host.com"

synoa/github-action-git-exec just executes a shell command (see https://github.com/synoa/github-action-git-exec/blob/master/entrypoint.sh#L4).

I've attached an execution log from one of the failed executions:
github-action.log

I've had a lot of "Host verification failed" issues, which according to #6 (comment) can be fixed by adding a script that adds the Host to the known hosts file - this didn't work as well so I highly speculate that GitHub Actions no longer shares its "state" between steps.

When I change my Action to run the following script I can login and push to my remote server without any issues:

[...]
    - name: "synoa/github-action-git-exec"
      uses: synoa/github-action-git-exec@master
      with:
        git_cmd: "mkdir /root/.ssh && echo \"${{ secrets.SSH_PRIVATE_KEY }}\" >  /root/.ssh/id_rsa && chmod 400 /root/.ssh/id_rsa && git push synoa@${DEPLOY_HOST}:/path/to/my/repo.git HEAD:master"           
      env:
        GIT_SSH_COMMAND: "ssh -vvv -o StrictHostKeyChecking=no"
        DEPLOY_HOST: "my-private-host.com"

This command works fine, but adding the same key using this action does not work.

If I can help in any way, please let me know!

Can we use GitHub deploy keys to get dependencies from multiple private repositories

I am trying to install 2 or more private GitHub repositories as an NPM dependency to another project.

In my package.json file, I have dependencies from GitHub in the following format:

    "***-plugin": "git+ssh://[email protected]:***/******.git#1bdfa1248fe92b4ba239aca37c686c72898ccab5",

The following is a part of my github action yml file:

      - name: Setup SSH Keys and known_hosts
        uses: webfactory/[email protected]
        with:
          ssh-private-key: |
            ${{ secrets.SSH_PRIVATE_KEY }}
            ${{ secrets.ANOTHER_SSH_PRIVATE_KEY }}

The SSH_PRIVATE_KEYs are added as deploy keys to this repo.

In the next step, I try to run npm install.
Now based on the order of the private keys, only one of these dependencies installs successfully.
I have tried to change the order of these ssh keys, which changes the dependency that cannot be installed.

Is it possible to use deploy keys to access both the private repositories in this case?
Let me know if you need more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.