Subject: bug#74832: guix copy incorrectly assumes port is 22

From: Tomas Volf <[email-masked]>
Date: Thu, 19 Dec 2024 10:30:39 +0100

Maxim Cournoyer <[email-masked]> writes:

> Hi Tomas,
>
> Tomas Volf <[email-masked]> writes:
>
>> After update to guile-ssh 0.18.0, options passed to the `make-session'
>> procedure now take precedence over the configuration file.  In few places we
>> however had code like `(or port 22)' leading to (in absence of alternative
>> port being specified) always using port 22, ignoring the configuration file.
>>
>> Due to that for example following command fails:
>>
>>     guix copy hello --to=name
>>
>> Name is reachable, but ssh server listens on port 2222.  That is correctly
>> configured in ~/.ssh/config, and the invocation used to succeed until the
>> upgrade.
>
> That is curious, because I had reported the exact same problem 6 years
> ago (!) in bug#33266 (now merged with this one), with a similar
> solution:
>
> Subject: [PATCH] Revert "copy: Default to port 22."
>
> This reverts commit cc1dfc202f2fefb6c2eb9467d1fc90a9154550c9.  Specifying a
> default port had the undesirable effect of disregarding a port specification
> for a given host in the ~/.ssh/config that would otherwise have been honored
> at the time `open-ssh-session' calls the `session-parse-config!' method.
>
> In any case, `make-session' will default the port value of the created session
> to 22 if left unspecified.
>
>
> But, Ludovic had mentioned that without it,
>
> [...] "%p" would be "0" when using "ProxyCommand" in ~/.ssh/config.
>
> So it'd perhaps regress in another way; I want to retry the test I had
> done then but I need to setup at least a VM with SSH to test.  If you
> can beat me to that, all the better :-).

I wonder whether VM is necessary.  I added the following to my
~/.ssh/config file:

--8<---------------cut here---------------start------------->8---
host name
port 2222
proxycommand echo %p >/tmp/port
--8<---------------cut here---------------end--------------->8---

Then I executed guix copy:

--8<---------------cut here---------------start------------->8---
$ guix copy hello --to=name
guix copy: error: SSH connection to 'name' port 2222 failed: Socket error: Connection reset by peer
--8<---------------cut here---------------end--------------->8---

And after that I checked /tmp:

--8<---------------cut here---------------start------------->8---
$ cat /tmp/port 
2222
--8<---------------cut here---------------end--------------->8---

So it seems to work fine?  Would not hurt if someone double checked
(with the patch above applied).

Tomas

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.