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

SSH config resolving for host:port is flawed #87

Closed
kke opened this issue Jan 25, 2023 · 0 comments · Fixed by #186
Closed

SSH config resolving for host:port is flawed #87

kke opened this issue Jan 25, 2023 · 0 comments · Fixed by #186
Labels
bug Something isn't working

Comments

@kke
Copy link
Contributor

kke commented Jan 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant