Skip to content

ProxyJump doesn't use modified Config.default_files #587

Open

Description

@rosenfeld

Hi, once I was able to use the ProxyJump local configuration in project/.ssh/config, but today I tried using this project again (through sshkit) and was getting this error: "#497".

It works if I run "ssh -F .ssh/config somehost". There's something like this in the configuration:

Host proxied
  Hostname 10.0.0.1
  ProxyJump root@100.100.100.100:22
  # this works, but it would be good to get the above working too:
  #ProxyCommand ssh -i /project/sshkeys/id_rsa -W %h:%p -p 22 root@100.100.100.100

Host *
  User root
  IdentityFile /project/sshkeys/id_rsa

It looks like the identity file wasn't being to both hosts. By the way, both 100.100.100.100 and 10.0.0.1 would be the same host. This may not make much sense but it simplifies some settings in our deployment scripts. Is there something wrong with the configuration above? I used to have it this way by the time the support for ProxyJump was introduced to net-ssh, but maybe something has changed since then.

Activity

  1. mfazekas commented on Mar 21, 2018

    @mfazekas
    Collaborator

    @rosenfeld thanks for the bugreport, not sure what changed. If you can write a reprodicable testcase that might make it easier fixing the issue.

  2. rosenfeld commented on Mar 21, 2018

    @rosenfeld
    Author

    Ok, today I'm in a hurry, but I'll see if I can get such test case tomorrow. Thanks

  3. rosenfeld commented on Mar 21, 2018

    @rosenfeld
    Author

    It help if you could provide a working testcase so that I could check myself and perform any changes to reproduce the problem. I've never worked directly with net-ssh. Would it be okay to provide a testcase project involving sshkit instead?

  4. mfazekas commented on Mar 22, 2018

    @mfazekas
    Collaborator

    Sure sshkit shoul be fine, ideal is an net-ssh only

  5. rosenfeld commented on Mar 22, 2018

    @rosenfeld
    Author

    Hi, I could finally find some time to investigate this. I wasn't able to reproduce it using net-ssh only. So I guess it could be an issue with sshkit. I have to leave soon, but hopefully tomorrow I would have some time to try on sshkit. I'm closing this issue for now as I suspect it's not net-ssh's fault.

    Thanks!

  6. rosenfeld commented on Mar 22, 2018

    @rosenfeld
    Author

    I could not reproduce it with a simple example with sshkit either. I guess it will require more time before I'm able to provide an example where it fails...

  7. rosenfeld commented on Mar 22, 2018

    @rosenfeld
    Author

    Actually, I was able to reproduce this issue using net-ssh only but it worked when I was testing against localhost. But against the real server it doesn't work for some reason I still don't understand. I'll let you know if I can get more details on how to reproduce it.

  8. rosenfeld commented on Mar 22, 2018

    @rosenfeld
    Author

    Ok, I was able to track down what's happening. I use an entry such as "Host *" in order to specify the IdentityFile. When using "ssh -F .ssh/config myhost" it will use that IdentityFile for the ProxyJump as well, but it doesn't happen with net-ssh. If I remove the "Host *" configuration and put the IdentityKey directly in the "myhost" entry, then the behavior is the same as net-ssh.

    Is it possible for net-ssh to handle "Host *" just like the ssh client does? That's fine if you want to keep the current behavior, but at least now I understand the reason why ProxyJump isn't working for this project. For the other project I have it probably works because the id_rsa is copied to the gateway's server at /root/.ssh/id_rsa. At least it's all clear to me right now :)

  9. mfazekas commented on Mar 23, 2018

    @mfazekas
    Collaborator

    @rosenfeld sorry can you clarify it for me?

    ProxyJump does pass config files you've specifed via config: option to net-ssh, doesn't it?

    See https://github.com/net-ssh/net-ssh/pull/500/files

  10. rosenfeld commented on Mar 23, 2018

    @rosenfeld
    Author

    Yes, but the ssh client behavior is different from net-ssh when "Host *" is used. If you have an IdentityFile specified under "Host *" the ssh client will use that when proxy jumping as well. I mean: "ssh -F .ssh/config myhost" would work fine because the IdentityFile would be used both to connect to the gateway and from the gateway to the final server. However, net-ssh will only use the IdentityFile to connect to the gateway and will then fail to connect to the final server. Please let me know if my explanation is still confusing.

  11. mfazekas commented on Mar 23, 2018

    @mfazekas
    Collaborator

    Net-ssh should be calling ssh -F .ssh/config ... for proxy jump, if you invoked net-ssh with config: ".ssh/config"

    Can you show your net-ssh script, and the way it invoked ssh for the proxy jump and what options do you think it should be passing to it instead?

    However, net-ssh will only use the IdentityFile to connect to the gateway and will then fail to connect to the final server.

    So the proxy jump raw ssh command does use the correct config file? But net-ssh doesn't interpret IdentityFile when connecting to target through proxy jump?

  12. rosenfeld commented on Mar 23, 2018

    @rosenfeld
    Author

    test-case.rb:

    require 'net/ssh'
    
    Net::SSH::Config.default_files << File.expand_path('.ssh/config', __dir__)
    
    Net::SSH.start('myhost', 'rodrigo') do |ssh|
      puts ssh.exec! 'hostname'
    end

    So the proxy jump raw ssh command does use the correct config file?

    Yes, while connecting to the gateway.

    But net-ssh doesn't interpret IdentityFile when connecting to target through proxy jump?

    Exactly

  13. rosenfeld commented on Mar 23, 2018

    @rosenfeld
    Author

    Here's how .ssh/config would look like:

    Host myhost
      Hostname 127.0.0.1
      ProxyJump rodrigo@127.0.0.1
      User rodrigo
    
    Host *
      # renamed ~/.ssh/id_rsa to ~/.ssh/id_rsa2, or otherwise it would work fine with net-ssh
      IdentityFile /home/rodrigo/.ssh/id_rsa2
    
  14. mfazekas commented on Mar 23, 2018

    @mfazekas
    Collaborator

    @rosenfeld can you show the log file demonstrating that net-ssh does not use the /home/rodrigo/.ssh/id_rsa2 when connecting?

    Just use Net::SSH.start('myhost', 'rodrigo', verbose: :debug) do |ssh|

  15. rosenfeld commented on Mar 23, 2018

    @rosenfeld
    Author

    How do I generate a log file?

  16. mfazekas commented on Mar 23, 2018

    @mfazekas
    Collaborator

    Just use Net::SSH.start('myhost', 'rodrigo', verbose: :debug) do |ssh| that should log a lot of stuff to stdout.

  17. rosenfeld commented on Mar 23, 2018

    @rosenfeld
    Author

    I had tried verbose: true and it didn't work, so I was reading the source when you suggested verbose: :debug and it worked :)

    ruby test-case.rb 
    D, [2018-03-23T08:38:05.279047 #28188] DEBUG -- net.ssh.transport.session[2ae9eacee4d4]: establishing connection to 127.0.0.1:22 through proxy
    rodrigo@127.0.0.1's password:
    Traceback (most recent call last):
            6: from test-case.rb:7:in `<main>'
            5: from /home/rodrigo/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh.rb:237:in `start'
            4: from /home/rodrigo/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh.rb:237:in `new'
            3: from /home/rodrigo/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/transport/session.rb:67:in `initialize'
            2: from /home/rodrigo/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/jump.rb:31:in `open'
            1: from /home/rodrigo/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/command.rb:57:in `open'
    /home/rodrigo/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/command.rb:68:in `rescue in open': command timed out: ssh -l rodrigo -W 127.0.0.1:22 127.0.0.1 (Net::SSH::Proxy::ConnectError)
    
  18. mfazekas commented on Mar 23, 2018

    @mfazekas
    Collaborator

    The default_files are not passed to the ssh process started by proxy jump.

    require 'net/ssh'
    
    Net::SSH::Config.default_files << File.expand_path('.ssh/config', __dir__)
    
    Net::SSH.start('myhost', 'rodrigo') do |ssh|
      puts ssh.exec! 'hostname'
    end

    This should work:

    require 'net/ssh'
    
    Net::SSH.start('myhost', 'rodrigo', config: File.expand_path('.ssh/config', __dir__)) do |ssh|
      puts ssh.exec! 'hostname'
    end
  19. rosenfeld commented on Mar 23, 2018

    @rosenfeld
    Author

    Yes, it works when the config is passed as an option, but shouldn't it also work with default configs?

    The sshkit gem overrides default_files to always include pwd/.ssh/config, for example. That means for this to work with sshkit I'd have to convince it to change their mind about the current implementation, but before I do that I'd like to confirm that net-ssh has no intention to make it also work with default_files. Is that the case?

  20. mfazekas commented on Mar 23, 2018

    @mfazekas
    Collaborator

    @rosenfeld I guess it would be possible to pass default_files with -F to the command started by ProxyJump.

    PR-s are welcome

  21. changed the title [-]ProxyJump support seems to be broken[/-] [+]ProxyJump doesn't use modified Config.default_files[/+] on Mar 23, 2018
  22. rosenfeld commented on Mar 23, 2018

    @rosenfeld
    Author

    Ok, great. I'm really with a tight deadline for a few months at least, and it would take a while before I understand how net-ssh works in order to create a PR. I'll discuss this issue with the sshkit team and see if anyone there would be willing to provide such a patch to net-ssh or if they would be willing to accept a patch in sshkit to use the :config option instead of default_files until this is supported by net-ssh. I feel it would be much simpler/quicker for me to change sshkit rather than trying to understand how net-ssh works. I'll talk to them and will let you know. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions