fix: network checking triggering fail2ban
This commit is contained in:
@@ -87,49 +87,36 @@ def check_machine_ssh_reachable(
|
|||||||
f"Checking SSH reachability for {remote.target} on port {remote.port or 22}",
|
f"Checking SSH reachability for {remote.target} on port {remote.port or 22}",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Use ssh with ProxyCommand to check through SOCKS5
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ssh",
|
"nc",
|
||||||
]
|
]
|
||||||
|
|
||||||
# If using SOCKS5 proxy, add ProxyCommand
|
# If using SOCKS5 proxy, add -x
|
||||||
if remote.socks_port:
|
if remote.socks_port:
|
||||||
cmd.extend(
|
cmd.extend(
|
||||||
[
|
[
|
||||||
"-o",
|
"-X",
|
||||||
f"ProxyCommand=nc -X 5 -x localhost:{remote.socks_port} %h %p",
|
"5",
|
||||||
|
"-x",
|
||||||
|
f"localhost:{remote.socks_port}",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd.extend(
|
cmd.extend(
|
||||||
[
|
[
|
||||||
"-o",
|
"-z",
|
||||||
"BatchMode=yes",
|
"-w",
|
||||||
"-o",
|
str(opts.timeout),
|
||||||
"StrictHostKeyChecking=no",
|
str(remote.address.strip()),
|
||||||
"-o",
|
|
||||||
"UserKnownHostsFile=/dev/null",
|
|
||||||
"-o",
|
|
||||||
f"ConnectTimeout={opts.timeout}",
|
|
||||||
"-o",
|
|
||||||
"PreferredAuthentications=none",
|
|
||||||
"-p",
|
|
||||||
str(remote.port or 22),
|
str(remote.port or 22),
|
||||||
f"dummy@{remote.address.strip()}",
|
|
||||||
"true",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = run(cmd, options=RunOpts(timeout=opts.timeout, check=False))
|
res = run(cmd, options=RunOpts(timeout=opts.timeout, check=False))
|
||||||
|
|
||||||
# SSH will fail with authentication error if server is reachable
|
if "succeeded" in res.stderr:
|
||||||
# Check for SSH-related errors in stderr
|
return
|
||||||
if (
|
|
||||||
"Permission denied" in res.stderr
|
|
||||||
or "No supported authentication" in res.stderr
|
|
||||||
):
|
|
||||||
return # Server is reachable, auth failed as expected
|
|
||||||
|
|
||||||
msg = "Connection failed: SSH server not reachable"
|
msg = "Connection failed: SSH server not reachable"
|
||||||
raise ClanError(msg)
|
raise ClanError(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user