Add SSH connection validation for settings
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user