Repository navigation
Description
At my place of work, there is an admittedly weird network configuration that causes the first few addresses returned by getaddrinfo for a certain host to yield EACCES ("Permission denied") errors when trying to connect:
smheidrich@host:~$ ssh -v CENSORED_USER@CENSORED_HOST
OpenSSH_7.4p1 Debian-10+deb9u2, OpenSSL 1.0.2l 25 May 2017
debug1: Reading configuration data /home/smheidrich/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to CENSORED_HOST [CENSORED_IPV6_ADDRESS1] port 22.
debug1: connect to address CENSORED_IPV6_ADDRESS1 port 22: Permission denied
debug1: Connecting to CENSORED_HOST [CENSORED_IPV6_ADDRESS2] port 22.
debug1: connect to address CENSORED_IPV6_ADDRESS2 port 22: Permission denied
debug1: Connecting to CENSORED_HOST [CENSORED_IPV6_ADDRESS3] port 22.
debug1: connect to address CENSORED_IPV6_ADDRESS3 port 22: Permission denied
debug1: Connecting to CENSORED_HOST [CENSORED_IPV6_ADDRESS4] port 22.
debug1: connect to address CENSORED_IPV6_ADDRESS4 port 22: Permission denied
debug1: Connecting to CENSORED_HOST [CENSORED_IPV6_ADDRESS5] port 22.
debug1: connect to address CENSORED_IPV6_ADDRESS5 port 22: Permission denied
debug1: Connecting to CENSORED_HOST [CENSORED_IPV6_ADDRESS6] port 22.
debug1: Connection established.As you can see, OpenSSH's client just keeps iterating over addresses returned by getaddrinfo when this happens, until it finally finds one that doesn't yield an error. The relevant section of the code is sshconnect.c, ll. 433-475, from which it is evident - as far as I can tell - that it only ever breaks out of the loop if a connection attempt was successful.
Paramiko, on the other hand, gives up as soon as a connection attempt yields something other than ECONNREFUSED or EHOSTUNREACH (relevant line: client.py, l. 344), which means I can't use it to connect to the host in question:
>>> import paramiko
>>> client = paramiko.SSHClient()
>>> client.load_system_host_keys()
>>> client.connect("CENSORED_HOST", username="CENSORED_USER")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/smheidrich/.local/lib/python3.5/site-packages/paramiko/client.py", line 338, in connect
retry_on_signal(lambda: sock.connect(addr))
File "/home/smheidrich/.local/lib/python3.5/site-packages/paramiko/util.py", line 279, in retry_on_signal
return function()
File "/home/smheidrich/.local/lib/python3.5/site-packages/paramiko/client.py", line 338, in <lambda>
retry_on_signal(lambda: sock.connect(addr))
PermissionError: [Errno 13] Permission deniedSo I would like to propose either adding EACCES to the list of "allowed" errors in client.py, l. 344, or perhaps even doing what OpenSSH does and continuing the iteration over addresses no matter what kinds of errors occur - as long as they are related in any way to the socket, of course. Or is there a problem I'm not seeing here?
Unfortunately, I can't give you a way to reproduce this (trying to induce the situation artificially at home with iptables didn't work out), but I hope the argument that Paramiko's behaviour differs from OpenSSH's is convincing enough.
Thanks in advance!
Version info:
- Python 3.5.3
- Paramiko 2.4.0, c43202d
Activity
[-]Connection attempts aborted prematurely due to EACCES while iterating over addresses[/-][+]Connection attempts aborted prematurely due to unforeseen EWHATEVERS while iterating over addresses[/+]bitprophet commentedon Aug 1, 2018
This seems to have come up on IRC too, in a slightly different wrinkle:
Sounds real similar - IPv6 is causing errors besides
ECONNREFUSED/EHOSTUNREACHto pop up, and Paramiko not knowing that these errors are effectively also recoverable/skip-overable, results in exceptions instead of "🙄 ok, sure thing OS, let's just try the next one eh?"Of course at this point I wonder if the original code is in fact way too paranoid and we should be a lot more lenient about what we consider ignorable/continue-able (this is probably very old code, for one thing). But let's take it one step at a time, probably.