netenglabs / suzieq

Using network observability to operate and design healthier networks
https://www.stardustsystems.net/
Apache License 2.0
787 stars 104 forks source link

Postpone ssh config parsing file when connecting to device for doing … #812

Open FloLaco opened 1 year ago

FloLaco commented 1 year ago

Related Issue

Fixes https://github.com/ronf/asyncssh/issues/520

Description

When using variables in ssh config file like %h or %p, asyncssh is doing token substitution with host address and port. But since suzieq is creating an asyncssh options before trying to connect to device, asyncssh is not aware about host and port info.

Type of change

New Behavior

The goal is to postpone ssh config file parsing at the asyncssh.connect() time, where host and port is known. There is another way, explained in the comments section.

...

Contrast to Current Behavior

Actually, when building the options, substitution look like this : nc -X 5 -x 127.0.0.1:2226 '' 22 Instead of nc -X 5 -x 127.0.0.1:2226 X.X.X.X 22 ...

Discussion: Benefits and Drawbacks

It's very usefull for supporting multiplexing ssh session with OpenSSH options without adding such feature to suzieq

...

Proposed Release Note Entry

...

Comments

There's two way to fix this issue, the other way is to provide host and port information to asyncssh when building ssh options. I tested both and it works, but I prefer the way to postpone config parsing in the asyncssh.connect() call instead of doing parsing before and pass the result to asyncssh.connect().

Second way like this :

        if self.ssh_config_file:
            options = asyncssh.SSHClientConnectionOptions(
                host=self.address,
                port=self.port,
                options=options,
                config=[self.ssh_config_file],
            )

Example of ssh config file :

host  jumpserver
   IdentityFile   /home/suzieq/parquet/ssh_cred_conf/id_rsa
   IdentitiesOnly   yes
   user   username
   hostname   Y.Y.Y.Y
   Protocol  2
   Port  22
   StrictHostKeyChecking   no
   DynamicForward 127.0.0.1:2226

host * !jumpserver
   Protocol  2
   StrictHostKeyChecking  no
   ProxyCommand nc -X 5 -x 127.0.0.1:2226 %h %p

Double Check

ryanmerolle commented 2 months ago

Is this something still useful?

ddutt commented 2 months ago

Is this something still useful?

Not sure, no one's ever asked for this but this user, and since the method he was pursuing was not a scalable answer, and he didn't address the comments, we haven't merged it