chef / chef-apply

The ad-hoc execution tool for the Chef ecosystem.
https://www.chef.sh/
Apache License 2.0
14 stars 14 forks source link

chef-run on windows 10 ignore build-in ssh config for key #157

Open herz0g opened 4 years ago

herz0g commented 4 years ago

Description

Hi, when I start chef-run I got error messages that my ssh config file isn't setup correctly. I have a ssh config file in my home folder which one is working if I use build-in ssh - it will connect to the definied server and ask for the definied key within my config file:

PS C:\Users\chg> ssh mailsrv
Enter passphrase for key '.\.ssh\id_rsa':
...

But it is not working if I use chef-run:

PS C:\Users\chg\Documents\chef-repo\cookbooks\debian10_sec\recipes> chef-run mailsrv default.rb
 [✔] Packaging cookbook... done!
 [✔] Generating local policyfile... exporting... done!
[✖] Applying debian10_sec::default from C:/Users/chg/Documents/chef-repo/cookbooks/debian10_sec to target.              |__ [✖] [mailsrv] No authentication methods available.                                                                  
No authentication methods available.
Try...
- Provide a password with "--password PASSWORD"
- Provide a key with "-identity-file PATH/TO/FILE"
- Enable ssh-agent and add keys
- Add a host entry to your ssh configuration

Additional instructions can be found in the troubleshooting documentation:
https://www.chef.sh/docs/chef-workstation/troubleshooting/#error-code-cheftrn007

Where do chef-run search for the config file?

Chef Workstation Version

Chef Workstation version: 0.11.21 Chef Infra Client version: 15.4.45 Chef InSpec version: 4.18.0 Chef CLI version: 2.0.0 Test Kitchen version: 2.3.4 Cookstyle version: 5.10.13 chef-run: 0.4.6

Platform Version

Windows 10 Pro (1909)

stack-trace:

--------------------------------------------------------------------------------
2019-11-25 16:24:24 +0100: Error encountered while running the following:
  mailsrv default.rb
Backtrace:
ChefApply::TargetHost::ConnectionFailure: ChefApply::TargetHost::ConnectionFailure
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-apply-0.4.6/lib/chef_apply/target_host.rb:131:in `rescue in connect!'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-apply-0.4.6/lib/chef_apply/target_host.rb:114:in `connect!'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-apply-0.4.6/lib/chef_apply/cli.rb:334:in `do_connect'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-apply-0.4.6/lib/chef_apply/cli.rb:180:in `connect_target'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-apply-0.4.6/lib/chef_apply/cli.rb:165:in `block (2 levels) in render_converge'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-apply-0.4.6/lib/chef_apply/ui/terminal/job.rb:31:in `run'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-apply-0.4.6/lib/chef_apply/ui/terminal.rb:60:in `block (2 levels) in render_parallel_jobs'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/tty-spinner-0.9.1/lib/tty/spinner.rb:225:in `execute_job'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/tty-spinner-0.9.1/lib/tty/spinner/multi.rb:150:in `block (2 levels) in auto_spin'
Caused by: Train::ClientError: Your SSH Agent has no keys added, and you have not specified a password or a key file
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/train-core-3.1.4/lib/train/transports/ssh.rb:106:in `validate_options'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/train-core-3.1.4/lib/train/transports/ssh.rb:76:in `connection'
    C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-apply-0.4.6/lib/chef_apply/target_host.rb:118:in `connect!'
    ... 7 more
herz0g commented 4 years ago

Update

I had to remove my password for the key file, after that I was able to use the -i argument and got my key accepted. But it isn't working with my config file or ssh-add. Booth ways are ignored when I run chef-run. I think chef-run don't search for the config file in ~.ssh\config, seems that it is try to find the keys within another path?

/Update

Also:

added my key with ssh-add after enabling ssh-agent -> not working, same error like above

added the key file with argument -i for chef-run -> error:

2019-11-25 21:56:20 +0100: Error encountered while running the following:
  mailsrv -i C:\Users\chg\.ssh\id_rsa default.rb
Backtrace:
Caused by: Train::Transports::SSHFailed: SSH command failed (the given identity is known, but the private key could not be loaded: OpenSSL::PKey::PKeyError (Could not parse PKey: no start line))
afiune commented 4 years ago

Hello @herz0g - Thank you for reporting this issue, we have confirmed that this is a bug and we will investigate what are the complication on Windows systems. We will keep you posted of any discovery or fixes we do.