Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Host key verification failed." when using rsync #17

Open
ograr opened this issue Mar 25, 2021 · 3 comments
Open

"Host key verification failed." when using rsync #17

ograr opened this issue Mar 25, 2021 · 3 comments

Comments

@ograr
Copy link

ograr commented Mar 25, 2021

This seems to be a slightly different issue than #16 or #2 so I'm making a new one, hope that's ok. My current setup (with SSH_KNOWN_HOSTS) seems to work fine just up until Deployer tries to rsync to the server.

Perhaps the problem is that SSH_PRIVATE_KEY isn't exposed to the rsync over SSH tunnel? Or am I doing something wrong?

Below is my setup, inspired by https://atymic.dev/blog/github-actions-laravel-ci-cd/.

deploy.php:

<?php
namespace Deployer;

require 'recipe/common.php';
require 'recipe/rsync.php';

// Project name
set('application', 'SECRET');

set('allow_anonymous_stats', false);

// Hosts
$hosts = ['dev' => 'staging', 'prod' => 'production'];
foreach ($hosts as $host => $stage) {
  host($host)
    ->hostname(getenv('SSH_HOST'))
    ->port(getenv('SSH_PORT'))
    ->stage($stage)
    ->user(getenv('SSH_USER'))
    ->set('deploy_path', getenv('DEPLOY_PATH'));
}

// Tasks
task('deploy', [
    'deploy:info',
    'deploy:prepare',
    'deploy:release',
    'rsync',
    'deploy:symlink',
    'cleanup',
    'success'
]);

deploy.dev.yml:

name: Deploy to dev

on:
  push:
    branches: develop

jobs:
  deploy:
    name: Deploy to dev
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/develop'
    steps:
      - uses: actions/checkout@v2
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 7.4
      - name: Install Deployer
        uses: atymic/deployer-php-action@master
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
          ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
      - name: Get Deployer version
        run: dep -V
      - name: Deploy to dev
        run: dep deploy dev -vvv
        env:
          SSH_HOST: ${{ secrets.DEV_SSH_HOST }}
          SSH_PORT: ${{ secrets.DEV_SSH_PORT }}
          SSH_USER: ${{ secrets.DEV_SSH_USER }}
          DEPLOY_PATH: ${{ secrets.DEV_DEPLOY_PATH }}

Log excerpt from Github Actions:

Run dep -V
Deployer v6.8.0

Run dep deploy dev -vvv
[localhost] > git rev-parse --abbrev-ref HEAD
[localhost] < develop
✈︎ Deploying develop on dev
• done on [dev]
➤ Executing task deploy:prepare
[dev] > echo $0
[dev] < ssh multiplexing initialization
[dev] < bash
[dev] > if [ ! -d *** ]; then mkdir -p ***; fi
[dev] > if [ ! -L ***/current ] && [ -d ***/current ]; then echo 'true'; fi
[dev] > cd *** && if [ ! -d .dep ]; then mkdir .dep; fi
[dev] > cd *** && if [ ! -d releases ]; then mkdir releases; fi
[dev] > cd *** && if [ ! -d shared ]; then mkdir shared; fi
• done on [dev]
✔ Ok [6s 482ms]
➤ Executing task deploy:release
[dev] > cd *** && (if [ -h release ]; then echo 'true'; fi)
[dev] < true
[dev] > cd *** && (rm -rf "$(readlink release)")
[dev] > cd *** && (rm release)
[dev] > cd *** && (if [ -d releases ] && [ "$(ls -A releases)" ]; then echo 'true'; fi)
[dev] > cd *** && (if [ -d ***/releases/1 ]; then echo 'true'; fi)
[dev] > cd *** && (date +"%Y%m%d%H%M%S")
[dev] < 20210325205814
[dev] > cd *** && (echo '20210325205814,1' >> .dep/releases)
[dev] > cd *** && (mkdir ***/releases/1)
[dev] > cd *** && (if [[ $(man ln 2>&1 || ln -h 2>&1 || ln --help 2>&1) =~ '--relative' ]]; then echo 'true'; fi)
[dev] < true
[dev] > cd *** && (ln -nfs --relative ***/releases/1 ***/release)
• done on [dev]
✔ Ok [3s 556ms]
➤ Executing task rsync
[dev] > if [ -h ***/release ]; then echo 'true'; fi
[dev] < true
[dev] > readlink ***/release
[dev] < releases/1
[localhost] > rsync -rz -e 'ssh -p*** -A -p ***' --delete --exclude='.git' --exclude='deploy.php' '/home/runner/.composer/vendor/deployer/recipes/recipe/' '***@***:***/releases/1/'
[localhost] < Host key verification failed.
[localhost] < rsync: connection unexpectedly closed (0 bytes received so far) [sender]
[localhost] < rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]
➤ Executing task deploy:failed
• done on [dev]
✔ Ok [0ms]

In Process.php line 267:
                                                                               
  [Symfony\Component\Process\Exception\ProcessFailedException]                 
  The command "rsync -rz -e 'ssh -p*** -A -p ***' --delete --exclude='.git'  
   --exclude='deploy.php' '/home/runner/.composer/vendor/deployer/recipes/rec  
  ipe/' '***@***:***/releases/1/'" fa  
  iled.                                                                        
                                                                               
  Exit Code: 255(Unknown error)                                                
                                                                               
  Working directory: /home/runner/work/hittaratt/hittaratt                     
                                                                               
  Output:                                                                      
  ================                                                             
                                                                               
                                                                               
  Error Output:                                                                
  ================                                                             
  Host key verification failed.                                                
  rsync: connection unexpectedly closed (0 bytes received so far) [sender]     
  rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]        
                                                                               

Exception trace:
  at /home/runner/.composer/vendor/symfony/process/Process.php:267
 Symfony\Component\Process\Process->mustRun() at /home/runner/.composer/vendor/deployer/deployer/src/Utility/ProcessRunner.php:56
 Deployer\Utility\ProcessRunner->run() at /home/runner/.composer/vendor/deployer/deployer/src/functions.php:329
 Deployer\runLocally() at /home/runner/.composer/vendor/deployer/recipes/recipe/rsync.php:144
 Deployer\Deployer::Deployer\{closure}() at n/a:n/a
 call_user_func() at /home/runner/.composer/vendor/deployer/deployer/src/Task/Task.php:105
 Deployer\Task\Task->run() at /home/runner/.composer/vendor/deployer/deployer/src/Executor/SeriesExecutor.php:60
 Deployer\Executor\SeriesExecutor->run() at /home/runner/.composer/vendor/deployer/deployer/src/Console/TaskCommand.php:144
 Deployer\Console\TaskCommand->execute() at /home/runner/.composer/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /home/runner/.composer/vendor/symfony/console/Application.php:971
 Symfony\Component\Console\Application->doRunCommand() at /home/runner/.composer/vendor/deployer/deployer/src/Console/Application.php:133
 Deployer\Console\Application->doRunCommand() at /home/runner/.composer/vendor/symfony/console/Application.php:290
 Symfony\Component\Console\Application->doRun() at /home/runner/.composer/vendor/symfony/console/Application.php:166
 Symfony\Component\Console\Application->run() at /home/runner/.composer/vendor/deployer/deployer/src/Deployer.php:326
 Deployer\Deployer::run() at /home/runner/.composer/vendor/deployer/deployer/bin/dep:137
@ograr
Copy link
Author

ograr commented Mar 25, 2021

I just discovered that I forgot to set this in my deploy.php:

set('rsync_src', function () {
    return __DIR__;
});

Hence the strange rsync source in the log above. Still not working though (still getting the "Host key verification failed." error).
I've also tried running the same rsync command locally after adding my private key with ssh-add and that works as expected.
Is this perhaps a problem with https://github.com/deployphp/deployer?

@ograr
Copy link
Author

ograr commented Mar 26, 2021

rsync works if I'm doing this in my Github Action instead:

name: Deploy to dev

on:
  push:
    branches: develop

jobs:
  deploy:
    name: Deploy to dev
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/develop'
    steps:
      - uses: actions/checkout@v2
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 7.4
      - name: Install SSH key
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
      - name: Install Composer dependencies
        run: composer install --prefer-dist --no-interaction --no-progress
      - name: Get Deployer version
        run: vendor/bin/dep -V
      - name: Deploy to dev
        run: vendor/bin/dep deploy dev -vvv
        env:
          SSH_HOST: ${{ secrets.DEV_SSH_HOST }}
          SSH_PORT: ${{ secrets.DEV_SSH_PORT }}
          SSH_USER: ${{ secrets.DEV_SSH_USER }}
          DEPLOY_PATH: ${{ secrets.DEV_DEPLOY_PATH }}

That is, I'm using https://github.com/shimataro/ssh-key-action to install the SSH key and "local" composer version of Deployer.

My current conclusion is that atymic/deployer-php-action somehow isn't exposing the SSH key and/or known hosts for rsync.

@rudenav
Copy link

rudenav commented May 7, 2021

The same error when I try to use the upload function.

task('upload:assets', function () {
    upload('public/', '{{release_path}}/public');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants