feat(ssh-server): say how sshd lets people log in, on FreeBSD and OpenBSD
driver / lint (pull_request) Successful in 12s
driver / standard (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m4s
driver / test (3.13) (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m11s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 56s
CI / driver (pull_request) Successful in 2m16s
driver / publish (pull_request) Skipped

BsdDriver mixes in napalm-device-types' SshServerAuthMixin:
get_ssh_server_auth() reads sshd -T as root and, on FreeBSD, the modules of
sshd's PAM auth stack. The floor on napalm-device-types rises to 4.32.0, the
release that brings the mixin.

Refs NetOrk/netork#662
This commit is contained in:
Christian Manivong committed 2026-11-07 15:09:50 +01:00
1 parent 5070c249f8
commit a3964e845a
5 files changed
+72 -3

No files matched your search

+4
View File
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- `get_ssh_server_auth()` on FreeBSD and OpenBSD, through napalm-device-types'
`SshServerAuthMixin` (4.32.0): whether sshd takes passwords, keyboard-interactive or keys,
its `AuthenticationMethods`, `PermitRootLogin` and, on FreeBSD, the modules of sshd's PAM
`auth` stack. Needs root for `sshd -T` (NetOrk/netork#662).
- Personal accounts on FreeBSD follow what the person changes (NetOrk/netork#2013):
`add_local_account(..., replaces=[...])` takes the old keys out of the account's key
files as the new one goes in, `remove_local_account_keys` takes deleted keys out and
+1
View File
@@ -41,6 +41,7 @@ provisions and manages BSD VMs (NetOrk/netork#792).
| `get_services`, `manage_service` | ✓ | ✓ | `service -e` + `service … status` / `service … <action>`; `rcctl ls on` + `rcctl check` / `rcctl <action>` |
| `run_device_action("fix_snmp")`, `get_snmp_config` | ✓ | ✓ | net-snmp from packages: `/usr/local/etc/snmp/snmpd.conf` + `service snmpd`; `/etc/snmp/snmpd.conf` + `rcctl … netsnmpd` |
| `get_host_status` | ✓ | unknown | napalm-device-types' host status: on FreeBSD `freebsd-version -k` vs `-r` (4.1+) |
| `get_ssh_server_auth` | ✓ | ✓ | napalm-device-types' `SshServerAuthMixin`: `sshd -T` as root, sshd's PAM `auth` stack from `/etc/pam.d` (FreeBSD; OpenBSD's sshd has no PAM) |
| `first_boot_pending` | ✓ | always `False` | whether `/firstboot` still exists |
`get_listening_sockets` has the shape of napalm-device-types'
+12 -2
View File
@@ -26,6 +26,7 @@ from napalm_device_types.channel import (
from napalm_device_types.host_status import HostStatusMixin
from napalm_device_types.models import FixStepOutcomeDict, SnmpAgentSettingsDict
from napalm_device_types.ssh_host_keys import HostKeyCheck, SshHostKeyMismatch
from napalm_device_types.ssh_server_auth import SshServerAuthMixin
from napalm_bsd import parse
from napalm_bsd.scheduled_jobs import BsdScheduledJobsMixin
@@ -89,9 +90,18 @@ def render_snmpd_conf(settings: SnmpAgentSettingsDict) -> str:
class BsdDriver(
BsdScheduledJobsMixin, SnmpAgentMixin, EnsurePackageMixin, HostStatusMixin, OSDriver
BsdScheduledJobsMixin,
SnmpAgentMixin,
EnsurePackageMixin,
HostStatusMixin,
SshServerAuthMixin,
OSDriver,
):
"""Base for the BSD drivers; a concrete one names the commands that differ."""
"""Base for the BSD drivers; a concrete one names the commands that differ.
``SshServerAuthMixin`` reads how sshd lets people log in (``sshd -T`` as root,
and sshd's PAM stack on FreeBSD); OpenBSD's sshd has no PAM.
"""
#: One role for FreeBSD and OpenBSD. It replaces OSDriver's "linux", which
#: would have the application treat a BSD host as a Linux one (#10).
+1 -1
View File
@@ -25,7 +25,7 @@ classifiers = [
]
dependencies = [
"napalm>=5.1", # older releases import pkg_resources, which a 3.12 venv lacks
"napalm-device-types>=4.29.0",
"napalm-device-types>=4.32.0",
"paramiko>=5.0.0", # CVE-2026-44405
]
+54
View File
@@ -7,6 +7,7 @@ from pathlib import Path
import pytest
from napalm.base import NetworkDriver
from napalm_device_types import OSDriver, primary_role_of, role_keys_of
from napalm_device_types.ssh_server_auth import PAM_FILES_COMMAND, SSHD_EFFECTIVE_COMMAND
from napalm_bsd import FreeBSDDriver, OpenBSDDriver, base
from napalm_bsd.base import BsdDriver
@@ -737,3 +738,56 @@ class TestFirstBoot:
driver = _channel(OpenBSDDriver, {})
assert driver.first_boot_pending() is False
assert driver.calls == []
#: The authentication lines of ``sshd -T`` on FreeBSD 15 as installed: PAM on,
#: keyboard-interactive on (PAM's password prompt), password authentication off.
_SSHD_T_FREEBSD = """\
port 22
usepam yes
permitrootlogin no
hostbasedauthentication no
pubkeyauthentication yes
passwordauthentication no
kbdinteractiveauthentication yes
authenticationmethods any
"""
#: FreeBSD's /etc/pam.d/sshd, abridged.
_PAM_SSHD_FREEBSD = """\
# auth
auth\t\trequired\tpam_unix.so\t\tno_warn try_first_pass
# account
account\t\trequired\tpam_nologin.so
account\t\trequired\tpam_unix.so
"""
class TestSshServerAuth:
"""How sshd lets people log in, through napalm-device-types' SshServerAuthMixin (NetOrk/netork#662)."""
def test_freebsd_reads_sshd_t_as_root_and_its_pam_stack(self):
driver = _channel(
FreeBSDDriver,
{
(SSHD_EFFECTIVE_COMMAND, True): _SSHD_T_FREEBSD,
PAM_FILES_COMMAND: f"==> /etc/pam.d/sshd <==\n{_PAM_SSHD_FREEBSD}",
},
)
auth = driver.get_ssh_server_auth()
assert auth["kbd_interactive_authentication"] is True
assert auth["password_authentication"] is False
assert [e["module"] for e in auth["pam_auth_stack"]] == ["pam_unix.so"]
assert driver.calls == [(SSHD_EFFECTIVE_COMMAND, True), (PAM_FILES_COMMAND, False)]
def test_openbsd_has_no_pam_to_read(self):
text = _SSHD_T_FREEBSD.replace("usepam yes\n", "")
driver = _channel(OpenBSDDriver, {(SSHD_EFFECTIVE_COMMAND, True): text})
auth = driver.get_ssh_server_auth()
assert auth["use_pam"] is None
assert auth["pam_auth_stack"] is None
assert driver.calls == [(SSHD_EFFECTIVE_COMMAND, True)]
def test_without_root_the_read_raises(self):
driver = _channel(FreeBSDDriver, {(SSHD_EFFECTIVE_COMMAND, True): ("", 1)})
with pytest.raises(RuntimeError, match="sshd -T"):
driver.get_ssh_server_auth()