miloserdow / capistrano-deploy

Github Actions for Capistrano
MIT License
127 stars 43 forks source link

Capistrano commands fail with bad authentication #67

Open jbrodie opened 9 months ago

jbrodie commented 9 months ago

I am trying to get this action to work but am having an issue. This is running on a self hosted worker. Once i get it to setup and run it fails on the capistrano commands as bad authentication, but the access keys are being decrypted, setup and connected to the agent properly as I can ssh in to the target deployment box without issue from the runner box.

Run miloserdow/capistrano-deploy@master
  with:
    target: production
    deploy_key: ***
    enc_rsa_key_pth: config/power@deploy_enc
    capistrano_commands: ["deploy"]
/usr/bin/openssl version
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
/usr/bin/openssl enc -d -aes-256-cbc -md sha512 -salt -in config/power@deploy_enc -out config/deploy_id_rsa -k *** -a -pbkdf2
/usr/bin/chmod 0600 config/deploy_id_rsa
/usr/bin/ssh-agent -a /tmp/ssh-auth.sock
SSH_AUTH_SOCK=/tmp/ssh-auth.sock; export SSH_AUTH_SOCK;
SSH_AGENT_PID=78309; export SSH_AGENT_PID;
echo Agent pid 78309;
/usr/bin/ssh-add config/deploy_id_rsa
Identity added: config/deploy_id_rsa (power@deploy)
/home/rails/actions-runner/_work/_tool/Ruby/3.1.4/arm64/bin/bundle exec cap production deploy
#<Thread:0x0000ffff9231efb0 /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
/home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as rails@[deploy-target-ip]: Authentication failed for user rails@[deploy-target-ip] (SSHKit::Runner::ExecuteError)
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/net-ssh-7.2.0/lib/net/ssh.rb:273:in `start': Authentication failed for user rails@[deploy-target-ip] (Net::SSH::AuthenticationFailed)
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/connection_pool.rb:63:in `call'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/connection_pool.rb:63:in `with'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/netssh.rb:177:in `with_ssh'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/netssh.rb:130:in `execute_command'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
    from <internal:kernel>:90:in `tap'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/abstract.rb:61:in `test'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/capistrano-rbenv-install-1.2.0/lib/capistrano/tasks/rbenv_install.rake:17:in `block (3 levels) in <top (required)>'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/backends/abstract.rb:31:in `run'
    from /home/rails/actions-runner/_work/**repo-name**/**repo-name**/vendor/bundle/ruby/3.1.0/gems/sshkit-1.21.6/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as rails@[deploy-target-ip]: Authentication failed for user rails@[deploy-target-ip]

I have connected to the instance and confirmed that the agent is running, and I can ssh to the target box without supplying the additional options for the ssh key.

mufid commented 8 months ago

Facing the same issue as well

mufid commented 8 months ago

hey @jbrodie looks like adding these lines solve my problem:

gem 'capistrano', ' ~> 3.18.0'
gem 'net-ssh', ' ~> 7.0.0'
gem 'ed25519'
gem 'bcrypt_pbkdf'
alexandrule commented 4 months ago

Thanks, @mufid. It works.