Bug 475638 - using include in ssh config doesn't traverse all includes, only the first
Summary: using include in ssh config doesn't traverse all includes, only the first
Status: CONFIRMED
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: SFTP (show other bugs)
Version: 23.08.1
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-15 00:41 UTC by andreas
Modified: 2024-02-08 15:38 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description andreas 2023-10-15 00:41:28 UTC
SUMMARY
In order to make my `~/.ssh/` cleaner, I looked for ways to use multiple files in different folders together. I found Include and then set it all up in a structured way. When I tested the setup in the terminal to ssh into whatever host from any included config file, I'm able to connect no issue. When I then tried to move some files from one ssh host to another in dolphin, using sftp://, I only got connection to one, the other showed an `Authentication failed` error.
These two targets are in different files, both included from `~/.ssh/config`. After some testing, I found out, that only the first Include actually gets parsed, not any other include in the same file, as when I changed the order of includes, suddenly the one that initially worked, didn't anymore, while the other now worked like nothing happened.


STEPS TO REPRODUCE
1. set up the ssh config like so, with your own testing data, having the same config for both a and b, only with different names, to make it as simple as possible:

~/.ssh/config:
# start
Include ~/.ssh/a/config
Include ~/.ssh/b/config
# end

~/.ssh/a/config
# start
Host ahost
    HostName 192.168.0.48
    User "root"
    IdentityFile ~/.ssh/a/akey
# end

~/.ssh/b/config
# start
Host bhost
    HostName 192.168.0.48
    User "root"
    IdentityFile ~/.ssh/b/bkey
# end

2. validate both `ssh ahost` and `ssh bhost` work as expected
3. try connection to `sftp://ahost` and `sftp://bhost`
4. reverse the order of includes in `~/.ssh/config`
5. try step 3 again


OBSERVED RESULT
Only the host from the file included first will connect, the other will error with the following message:
`Failed to resolve hostname bhost (Name or service not known)` (this is from the initial include order)


EXPECTED RESULT
Both hosts connect without any issue, similar to how the both work using `ssh host`.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
(from the About this System panel)
KDE Plasma Version: 5.27.8
KDE Frameworks Version: 5.110.0
Qt Version: 5.15.11

ADDITIONAL INFORMATION
Comment 1 Pedro V 2024-02-08 15:38:11 UTC
Can confirm, likely an upstream (libssh) issue, although it seems to be capable of processing multiple includes, and I'm really not seeing what's the logical problem preventing it.

Suspecting a corrupt state returning from include directive processing and looking for some extra noise between the 2 includes, ended up with the following config:
```
Include ~/.ssh/config0
Host test
	HostKeyAlias test
Include ~/.ssh/config1
```

Running `KIO_SFTP_LOG_VERBOSITY=10 KDE_FORK_SLAVES=1 QT_LOGGING_RULES="log_kio_sftp=true;kf.kio.workers.sftp=true;" krusader` , got the following output:
```
kf.kio.workers.sftp: list directory:  QUrl("sftp://test1")
kf.kio.workers.sftp: checking cache: info.username = "" , info.url = "sftp://test1"
kf.kio.workers.sftp: 
kf.kio.workers.sftp: Creating the SSH session and setting options
kf.kio.workers.sftp: [ ssh_config_parse_file ] ( 3 )  ssh_config_parse_file: Reading configuration data from /home/user/.ssh/config
kf.kio.workers.sftp: [ local_parse_file ] ( 3 )  local_parse_file: Reading additional configuration data from /home/user/.ssh/config0
kf.kio.workers.sftp: [ ssh_config_parse_line ] ( 2 )  ssh_config_parse_line: Unsupported option: HostKeyAlias, line: 3
```

SOC_INCLUDE appears to be correctly excluded from the seen[opcode] check, suspecting the parsing variable to be handled silly.
Looking for a way to reset it, I cooked up:
```
Include ~/.ssh/config0
Match user user
	HostKeyAlias test
Include ~/.ssh/config1
```

With that, connecting to sftp://user@test1 (note the inclusion of the username!) succeeds as the parsing of the second inclusion isn't skipped anymore:
```
kf.kio.workers.sftp: [ ssh_config_parse_file ] ( 3 )  ssh_config_parse_file: Reading configuration data from /home/user/.ssh/config
kf.kio.workers.sftp: [ local_parse_file ] ( 3 )  local_parse_file: Reading additional configuration data from /home/user/.ssh/config0
kf.kio.workers.sftp: [ ssh_config_parse_line ] ( 4 )  ssh_config_parse_line: line 2: Processing Match keyword 'user'
kf.kio.workers.sftp: [ ssh_config_match ] ( 4 )  ssh_config_match: Matched 'user' against pattern 'user' (ok=1)
kf.kio.workers.sftp: [ ssh_config_parse_line ] ( 2 )  ssh_config_parse_line: Unsupported option: HostKeyAlias, line: 3
kf.kio.workers.sftp: [ local_parse_file ] ( 3 )  local_parse_file: Reading additional configuration data from /home/user/.ssh/config1
```