webfactory / ssh-agent

GitHub Action to setup `ssh-agent` with a private key
MIT License
1.23k stars 256 forks source link

Unable to get this action to work #8

Closed KevinGimbel closed 4 years ago

KevinGimbel commented 5 years ago

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/ssh-agent@v0.1.1
    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 https://github.com/webfactory/ssh-agent/issues/6#issuecomment-543247008 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!

mpdude commented 4 years ago

Could you try to remove synoa/github-action-git-exec and just try to SSH into your host? Maybe that way we can narrow down where the problem comes from.

KevinGimbel commented 4 years ago

Very weird, it is working now. I tried to just run an SSH command, e.g. ssh user@host ls -l before and it didn't work but now it does.

As the issue seems to be gone I'll close this issue; Maybe it was a hiccup in GitHub's System 🤷‍♂