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
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:
1 parent
5070c249f8
commit
a3964e845a
5 files changed
+72
-3
No files matched your search
@@ -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()
|
||||
Reference in new issue
Block a user