[ISSUE] - Multiple Host Configuration Inheritance not working as expected
Hi all,
First of all, thanks for the tool, it's really helpfull! :)
With the rewrite of the code, it seems that sshs is not parsing the ssh configuration as before and does not work like OpenSSH does.
My file structure looks like this :
.ssh
├── config
└── zones
├── infra1
├── infra2
└── cust
├── cust1
└── cust2
With a simple ssh config file that contains Include to other ssh config files located in the `zones' subdirectory. This allow me, like many people, to structure and separate ssh configuration for every different infrastructure.
My ssh zones files looks like this:
Host device01.domain.tld
Hostname 10.0.0.1
Host device02.domain.tld
Hostname 10.0.0.2
Host device03.domain.tld
Hostname 10.0.0.3
Host *.domain.tld
User bob
ProxyJump jump01
IdentityFile ~/path/to/private/key/cust1_id_ed25519
In version 3.4.0, this configuration was handled correctly and all the Host matching block where read by sshs and I was able to connect to device01.domain.tld using the proper user, ssh key, cipher, command and proxy jump.
Since version 4.0.0 and more specifically with 4.1.0, sshs to device01.domain.tld will not read other Host block and will only apply the configuration of the individual Host block. This mean that using sshs to connect to device01.domain.tld will not use bob as user, not use the specified IdentityFile neither the Proxy Jump configuration.
To make it works in version 4.1.0 my ssh zone file need to look like this:
Host device01.domain.tld
Hostname 10.0.0.1
User bob
ProxyJump jump01
IdentityFile ~/path/to/private/key/cust1_id_ed25519
Host device02.domain.tld
Hostname 10.0.0.2
User bob
ProxyJump jump01
IdentityFile ~/path/to/private/key/cust1_id_ed25519
Host device03.domain.tld
Hostname 10.0.0.3
User bob
ProxyJump jump01
IdentityFile ~/path/to/private/key/cust1_id_ed25519
It works, but it makes the configuration heavier and more complex to maintain.
Looks like a bug in the parser as it does not read any other Host blocks.
Thanks for your help :) Saldru
Hey! Sorry to hear that, it will work well this way:
Host *.domain.tld
User bob
ProxyJump jump01
IdentityFile ~/path/to/private/key/cust1_id_ed25519
Host device01.domain.tld
Hostname 10.0.0.1
Host device02.domain.tld
Hostname 10.0.0.2
Host device03.domain.tld
Hostname 10.0.0.3
I thought wildcards would only be applied to future hosts but seems like I'm wrong, thanks for reporting the issue.
Before opening an issue I wanted to followup I found a way throw off the the parser but weidly enough only in wsl2 (arch 5.10, sshs compiled from source) the sshconfig works perfectly in powershell (installed via chocolatey)
.ssh/config :
# SSH Configuration File
# Location: C:\Users\<YourUsername>\.ssh\config
# ============================
# Global defintition
# ============================
#Global JumpHost config
#jumphost-access read-only
Host jumphost.*-ro
IdentityFile ~/.ssh/id_rsa
#jumphost-access read-write
Host jumphost.*-rw
IdentityFile ~/.ssh/id_rsa-adm
#jumphos global configuration
Host jumphost*
IdentitiesOnly yes
ForwardAgent yes
#
# Global prehistorical equipement ssh specification
# swiib global configuration ond for old tech
Host swiib* rc* rh* rv*
KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
HostKeyAlgorithms +ssh-rsa,ssh-dss
PubkeyAcceptedAlgorithms +ssh-rsa,ssh-dss
MACs +hmac-sha1,hmac-sha1-96
#
# password authentication hosts
Host r* sw* fw* proxy* syslog*
PreferredAuthentications password
# USER Definition
# Replace YourUsernames here! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
######################################################################
# ro rw
Host *-ro
User usr01
Host *-rw
User adm.usr01
Host *-local
User local
######################################################################
#starship user specification
Host starship*
PreferredAuthentications password
User admin
# isp-adm user
Host *-isp
User isp
#
# oob access or admin
Host *-oob *-admin
User admin
#
# Port Definition
#default
Host *
Port 22
# snip rests of hosts#
I have narrowed down the issue to this block
Host swiib* rc* rh* rv*
KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
HostKeyAlgorithms +ssh-rsa,ssh-dss
PubkeyAcceptedAlgorithms +ssh-rsa,ssh-dss
MACs +hmac-sha1,hmac-sha1-96
unless I comment it out or change the host match it to example -old- the parser goes haye wire and throws an 'expected \n, at pos xxx' where pos is like way off my file length.
I pretty sure issue might on my side on condition mixup and me missunderstanding how your parsing logic. But the fact that it works on the preloaded one from choco (in powershell) vs the compiled one encouraged me reporting it here