Add SSH connection validation for settings

This commit is contained in:
2026-05-07 18:31:49 +02:00
parent 2219a5730f
commit 84dc2bd2f6
9 changed files with 235 additions and 5 deletions
@@ -22,7 +22,7 @@ def _host_alias(host: str, port: int) -> str:
return host if int(port or 22) == 22 else f"[{host}]:{int(port or 22)}"
def _fetch_server_key(host: str, port: int, timeout: int = 10) -> paramiko.PKey:
def _fetch_server_key(host: str, port: int, timeout: int = 30) -> paramiko.PKey:
sock = socket.create_connection((host, int(port or 22)), timeout=timeout)
transport = paramiko.Transport(sock)
try:
@@ -31,6 +31,11 @@ def _fetch_server_key(host: str, port: int, timeout: int = 10) -> paramiko.PKey:
if key is None:
raise RuntimeError(f"Unable to read SSH host key for {host}:{port}")
return key
except Exception as exc:
raise RuntimeError(
f"Unable to read SSH protocol banner from {host}:{port}. "
"Confirm the host is running an SSH server on that port and is reachable from the backend."
) from exc
finally:
transport.close()
sock.close()