sake icon indicating copy to clipboard operation
sake copied to clipboard

Be aware of `~/.ssh/config`

Open DannyBen opened this issue 3 years ago • 5 comments

I was trying to configure a server in sake.yaml, by simply using the hostname as it is written in my ~/.ssh/config, but realized this does not work.

Example sake.yaml:

servers:
  myserver:
    host: myserver

Example ~/.ssh/config:

Host myserver
  Hostname 123.123.123.123
  User root

Can this be made to work?

DannyBen avatar Jun 16 '22 10:06 DannyBen

It sounds like a good idea, initially, I didn't want to introduce another config (keep the state in one location), but it might be helpful to resolve hosts.

alajmo avatar Jun 17 '22 15:06 alajmo

Well, it is a matter of perspective I guess.

The ~/.ssh/config is the standard place for SSH related configuration, and not only for host resolution. In particular, my SSH config has also users, and wildcards to enforce some other SSH nuances across multiple configuration blocks - such as SSH agent forwarding etc. I wonder if the SSH library used by sake already has a way to load the native SSH config.

DannyBen avatar Jun 17 '22 15:06 DannyBen

Two libraries come to mind to help with this, https://github.com/mikkeloscar/sshconfig and https://github.com/kevinburke/ssh_config. I'm not using any 3rd party SSH library, but the crypto/ssh library provided by go (they only provide agent and knownhosts capability).

One interesting note would be to allow regular hosts defined in ssh_config (only for exact hostnames), so you could skip defining anything at all in the servers section in sake.

alajmo avatar Jun 17 '22 17:06 alajmo

The current config also does not allow everything possible with ssh alone. For example I'm using JumpProxy ("-J"-Option). That is currently not possible (at least haven't found it).

eppixx avatar Jul 19 '22 13:07 eppixx

Bastion/Jumphost is not yet supported but is next on the list to implement, and I'll look at more ssh options configs to support.

alajmo avatar Jul 20 '22 20:07 alajmo

Should be fixed now with v0.10.3.

alajmo avatar Aug 26 '22 19:08 alajmo

The current config also does not allow everything possible with ssh alone. For example I'm using JumpProxy ("-J"-Option). That is currently not possible (at least haven't found it).

Should work now with https://github.com/alajmo/sake/releases/tag/v0.11.0

alajmo avatar Sep 16 '22 18:09 alajmo

I am sorry - I must be missing something. The original topic of this ticket does not seem to work still.

The error I am getting is something like this:

myserver | myserver | root | 22   | dial tcp: lookup myserver on 127.0.0.53:53: server misbehaving

DannyBen avatar Sep 16 '22 19:09 DannyBen

So it seems to resolve to the correct IP (~also I assume you mistyped earlier, should be HostName and not Hostname~ - seems ssh lowercase in the backend, didn't know this)? Are you trying to connect to a K8s node? If so, perhaps this could help you

  • https://stackoverflow.com/questions/63326973/unable-to-connect-to-the-server-dial-tcp-lookup-masterip-on-127-0-0-5353-ser
  • https://github.com/kelseyhightower/kubernetes-the-hard-way/issues/630

So, try changing the port to :6443

alajmo avatar Sep 16 '22 19:09 alajmo

Well - not trying to connect to a k8s host. Just a plain old remote server. If ssh sometjing works, I expect sake to be able to accept just something as a server name, and inherit everything my ~/.ssh/config had to say.

However, I totally understand if this is not the design intention.

DannyBen avatar Sep 16 '22 20:09 DannyBen

I would like it to work with everything that's supported in ssh (and I try to follow their semantics as much as possible), and will try to implement as much as possible, but since I'm relying on Go's crypto/ssh library, some things are not yet available, like (like ControlMaster https://github.com/golang/go/issues/32958). I've also filed a bug with IP6 addresses in known hosts https://github.com/golang/go/issues/53463#issuecomment-1165748226).

Concerning your issue, I haven't been able to replicate it, if you could paste the ssh configs which impact how you connect (and try replacing Hostname with HostName, that's a separate issue that I need to fix), it would be of great help.

alajmo avatar Sep 16 '22 23:09 alajmo

With HostName capitalization, it works.

DannyBen avatar Sep 17 '22 06:09 DannyBen

Great, thanks for the feature suggestion and finding another small issue with the capitalization.

alajmo avatar Sep 17 '22 07:09 alajmo

Fixed to support lowercase (as ssh does) attributes.

alajmo avatar Oct 09 '22 21:10 alajmo