Merge remote-tracking branch 'origin/main' into feat/local-accounts

# Conflicts:
#	CHANGELOG.md
This commit is contained in:
Christian Manivong committed 2026-11-01 00:48:02 +01:00
commit 9ce915a8b9
3 files changed
+45 -13

No files matched your search

+5
View File
@@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
and gives the old password back. Checked on Debian 13 and Rocky Linux 9 with sshd and and gives the old password back. Checked on Debian 13 and Rocky Linux 9 with sshd and
sudo. OpenMediaVault (Debian) inherits it; QNAP QTS opts out in napalm-qnap-qts. sudo. OpenMediaVault (Debian) inherits it; QNAP QTS opts out in napalm-qnap-qts.
Requires the napalm-device-types release with `LocalAccountsMixin`. Requires the napalm-device-types release with `LocalAccountsMixin`.
- `open()` tries the connection again after 1, 3, 7 and 15 s when sshd closes it before
its banner -- what OpenSSH 9.8+ does to a source it has just penalised
(`PerSourcePenalties`), e.g. after a security scanner's probes. Needs
napalm-device-types' `retry_refused` (NAPALM/napalm-device-types#63,
NetOrk/netork#1800).
- The sudo password the old `_sudo` left in shell histories (NetOrk/netork#1090), through - The sudo password the old `_sudo` left in shell histories (NetOrk/netork#1090), through
napalm-device-types' `SudoHistoryMixin`. Until NetOrk/netork#1039 every privileged command napalm-device-types' `SudoHistoryMixin`. Until NetOrk/netork#1039 every privileged command
was typed into the interactive shell as `echo '<password>' | sudo -S -p "" …`, so the was typed into the interactive shell as `echo '<password>' | sudo -S -p "" …`, so the
+13 -13
View File
@@ -67,7 +67,7 @@ from napalm_device_types.models import (
UpdateDict, UpdateDict,
UserDict, UserDict,
) )
from napalm_device_types.ssh_host_keys import HostKeyCheck from napalm_device_types.ssh_host_keys import HostKeyCheck, retry_refused
from netmiko import ConnectHandler from netmiko import ConnectHandler
from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutException from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutException
@@ -393,19 +393,19 @@ class LinuxDriver(
"""Open the SSH connection and detect the package manager.""" """Open the SSH connection and detect the package manager."""
try: try:
with self._host_key.netmiko(self.netmiko_optional_args) as netmiko_args_: with self._host_key.netmiko(self.netmiko_optional_args) as netmiko_args_:
self._device = ConnectHandler( self._device = retry_refused( # waits out sshd's penalty (NetOrk/netork#1800)
device_type=self.NETMIKO_DEVICE_TYPE, lambda: ConnectHandler(
host=self.hostname, device_type=self.NETMIKO_DEVICE_TYPE,
username=self.username, host=self.hostname,
password=self.password, username=self.username,
port=self.port, password=self.password,
secret=self._secret, port=self.port,
timeout=self.timeout, secret=self._secret,
**netmiko_args_, timeout=self.timeout,
**netmiko_args_,
)
) )
except NetmikoAuthenticationException as exc: except (NetmikoAuthenticationException, NetmikoTimeoutException) as exc:
raise ConnectionException(str(exc)) from exc
except NetmikoTimeoutException as exc:
raise ConnectionException(str(exc)) from exc raise ConnectionException(str(exc)) from exc
self._host_key.observe(self._device.remote_conn_pre.get_transport()) self._host_key.observe(self._device.remote_conn_pre.get_transport())
+27
View File
@@ -86,3 +86,30 @@ def test_a_changed_key_is_refused():
driver.open() driver.open()
assert driver._device is None assert driver._device is None
assert seen[0]["accepted"] is False assert seen[0]["accepted"] is False
def test_a_connection_sshd_turns_away_is_tried_again(monkeypatch):
"""OpenSSH 9.8+ closes every connection from a source it has just penalised,
before its banner; the penalty ends after seconds (NetOrk/netork#1800)."""
from napalm_device_types import ssh_host_keys
slept: list[float] = []
monkeypatch.setattr(ssh_host_keys.time, "sleep", slept.append)
attempts: list[int] = []
def turned_away(**kwargs):
attempts.append(1)
if len(attempts) < 3:
try:
raise paramiko.SSHException("Error reading SSH protocol banner")
except paramiko.SSHException as exc:
raise NetmikoTimeoutException(f"A paramiko SSHException occurred: {exc}") from exc
return _device()
driver = _driver([])
with patch("napalm_linux.linux.ConnectHandler", side_effect=turned_away):
driver.open()
assert driver._device is not None
assert len(attempts) == 3
assert slept == list(ssh_host_keys.REFUSED_RETRY_WAITS[:2])