Skip to content

SSH config resolving for host:port is flawed #87

Closed

Description

@kke

Rig is trying to be too clever with getting host settings from the ssh config by first querying for host:port and if that fails, by trying host only.

The alias/pattern/key in ssh config is not host:port. In fact, you can have something like:

Host 127.0.0.1:33
  HostName 127.0.0.1
  Port 45

==>

$ ssh -v 127.0.0.1:33
debug1: Reading configuration data /Users/kimmo/.ssh/config
debug1: /Users/kimmo/.ssh/config line 7: Applying options for 127.0.0.1:33
debug1: /Users/kimmo/.ssh/config line 18: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 45.

The port is only parsed from -p:

$ ssh -v root@127.0.0.1:33 -p 2222
debug1: Reading configuration data /Users/kimmo/.ssh/config
debug1: /Users/kimmo/.ssh/config line 7: Applying options for 127.0.0.1:33
debug1: /Users/kimmo/.ssh/config line 13: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to 127.0.0.1 port 2222.

$ ssh -v 127.0.0.1:12345 -p33
debug1: Reading configuration data /Users/kimmo/.ssh/config
debug1: /Users/kimmo/.ssh/config line 13: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: resolve_canonicalize: hostname 127.0.0.1:12345 is an unrecognised address
debug1: Connecting to 127.0.0.1:12345 port 33.

So, in the case of config like this:

ssh:
  address: 127.0.0.1
  port: 40
  user: bob

And ssh config like this:

Host 127.0.0.1
  Port 45
Host local
  Port 40
  HostName 127.0.0.1
  User foo

What should rig do?

  1. query for 127.0.0.1 in the config and discard anything found in there unless port is 40 and user is bob also in ssh config?
  2. query for 127.0.0.1 in the config and overwrite any rig settings with the ones from ssh config?
  3. query for 127.0.0.1 in the config and overwrite any ssh config values with what is in rig config?
  4. query for 127.0.0.1 in the config and error out if there's a mismatch between rig and ssh config?
  5. query for all hosts, find one with HostName 127.0.0.1, user bob and port 40?
  6. introduce something like ssh.host and overwrite anything received with what is in rig config?

I think the best choice is number 3. It's pretty close to what command line ssh does without losing any ssh config functionality unless specifically using the host field in 6.

Activity

  1. added
    bug
    on Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions