napalm-device-types' ServicesRestartMixin reads needrestart or
/proc/<pid>/maps and names systemd units by cgroup; a BSD has none of
them. Without the method the caller shows the reading as not made, not as
clean. A FreeBSD reading of its own is #33.
open() handed the key file netOrk passes in key_file to paramiko as
key_filename. For a key file, SSHClient._auth tries the key as every key
type and keeps only the last error, so a host turning down an RSA or ECDSA
key raised "SSH to <host> failed: encountered RSA key, expected OPENSSH
key" instead of "Authentication failed.", which pointed at the key rather
than at the host that refused it. Ed25519 keys were not affected: they are
the last type tried.
The key is now loaded once with its own type (PKey.from_path) and passed
as pkey=, as netOrk's own SSH sessions do since NetOrk/netork#2480. A key
file that cannot be read raises ConnectionException before anything is
dialled.
Tested against an in-process SSH server on loopback, with RSA, ECDSA and
Ed25519 keys refused and accepted.
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
napalm-device-types 4.29.0 lets remove_local_account_keys clear the password and sudo too (NetOrk/netork#2033). This driver's _account_clear_password already does the work; a test pins the commands, and the floor rises to 4.29.0.
napalm-device-types 4.28.0 lets add_local_account remove the old keys
(replaces) and the password (clear_password), and adds
remove_local_account_keys. The key changes run through the mixin's own
key files as the person; the password goes with chpass -p '*', the
field pw useradd -w no writes, which sshd does not take for a lock.
See NetOrk/netork#2013
get_scheduled_jobs reads /etc/crontab and the user crontabs in
/var/cron/tabs, on FreeBSD also both cron.d directories and every
periodic script, in one round trip as root; manage_scheduled_job
enables, disables or runs one now; put_ and delete_scheduled_job write
and remove an application's own job (/etc/cron.d on FreeBSD, marked
lines in the user's crontab on OpenBSD).
A periodic script is what FreeBSD runs daily, weekly, monthly and for
the security run; it does its work only when its periodic.conf knob
says YES, so that knob is its enabled state, written with sysrc to
/etc/periodic.conf. A later periodic.conf that still overrides it is
reported instead of claimed as done. A script whose knob is not known
only runs; one whose knob is off does nothing when run and offers no run.
BSD su takes no shell (FreeBSD's -s is a MAC label) and -m starts
root's own shell, csh on many FreeBSD hosts, so another user's job goes
to /bin/sh on stdin. OpenBSD cron's -n/-q/-s flags are left off when a
line runs now. What the base system ships is platform: FreeBSD's
/etc/crontab and /etc/periodic, OpenBSD's newsyslog and
/etc/daily|weekly|monthly lines, which stay one job each.
get_cron_jobs goes: it read without root and missed cron.d, every other
user and periodic.
Requires napalm-device-types 4.26.0.
Closes#27
net-snmp on OpenBSD answers ssCpuIdle with 0 on an idle host (and
hrProcessorLoad with 100), so a reading of the standard OID shows every
OpenBSD host at 100 % CPU. The profile now marks the CPU unknown, and
the application reports no figure instead of a wrong one. Memory, swap
and load stay on the standard reading.
Closes#7
BsdDriver set no ROLE, so both drivers inherited OSDriver's "linux"
and an application that shows or branches on the role treated a BSD
host as a Linux one. One key for both systems.
Closes#10
When the root reading failed, get_listening_sockets ran the fallback
without root and parsed its output without looking at the exit status.
A failing sockstat or netstat returned an empty list, which a caller
reads as every port closed. The fallback now goes through the reader
check and raises with the command's error.
Closes#11
FreeBSDDriver mixes in napalm-device-types' LocalAccountsMixin: pw useradd
-m -w no, chpass -p for the password hash, pw lock/unlock and pw groupmod
-d. A locked account carries *LOCKED*, which sshd refuses a key login too
(nuageinit sets UsePAM no, so nothing else would). getpwnam(3) shows the
password field to root only, so the lock is read with getent as root and
only its prefix is looked at. The sudo rule goes to the sudo package's
/usr/local/etc/sudoers.d.
Checked on a FreeBSD 15.1 cloud image with the real driver over SSH and
sudo -S: key login works after adding and after reopening and is refused
after locking, sudo takes the person's password, wheel is left when sudo
is not wanted. OpenBSD is left out for now.
CI pre-installs napalm-device-types from main until the release with
LocalAccountsMixin is on PyPI.
get_arp_table reported the time until the entry expires (FreeBSD's
"expires in N seconds", OpenBSD's Expire column): an entry refreshed a
second ago looked 20 minutes old. It now reports ARP_AGE_UNKNOWN (-1.0).
NetOrk/netork#1327
netOrk runs every driver in its own containers on Python 3.12, so 3.10
and 3.11 are no longer supported or tested. requires-python, mypy and
ruff move to 3.12, along with what ruff's pyupgrade rules then rewrite.
- CI moves to .gitea/workflows/ci.yml and calls the shared driver workflow
of NAPALM/driver-standard; .github/ is gone.
- napalm-device-types >=4.21.1 from PyPI (the README no longer installs
it from git), py.typed, SPDX license string, setuptools>=77, version
floors on the dev extra, Issues and Changelog links on git.netork.io.
- mypy strict for the package; napalm_bsd.base, napalm_bsd.freebsd and
napalm_bsd.openbsd are exempt for now (28 errors, mostly getters typed
as plain dicts rather than the device-types TypedDicts), recorded in the
quality baseline with three complex parsers. parse.py is strict after a
one-line annotation.
- Coverage floor 94 % (measured 94.63 %).
- nosec for the staging path on the device (B108); it is a mktemp
template on the remote host, not a local temp file.
- The wildcard listen addresses parsed from sockstat/netstat are named
constants with a nosec (B104): reported data, never a bind. The output
is unchanged.
- ruff found nothing left after the mechanical pass.
Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM
driver uses (E, F, I, UP, B at line length 100, Python 3.10). What ruff
cannot fix comes in the next commit.
The driver accepted any SSH host key. It now verifies through
napalm-device-types' HostKeyCheck (>= 4.19.0): with a known key in
optional_args["ssh_host_keys"] any other key is refused before login, and
every key seen is reported to optional_args["ssh_host_key_observer"].
Without either argument it connects as before (first use).
fix_snmp wrote an application's snmpd.conf (community public, Managed
by netOrk, netork@localhost) and judged itself by a local snmpget.
The drivers implement napalm-device-types 4.13's SnmpAgentMixin steps
instead: net-snmp installed, snmpd.conf with one rocommunity line per
allowed source (staged without privilege, installed by root), snmpd
enabled and restarted. pf and ipfw rules stay the operator's. A
community or text that would break the file is refused. The caller
verifies with its own SNMP client.
Also get_management_peer() from SSH_CONNECTION, ensure_package from
the base package, and get_snmp_config no longer assumes "public".
BREAKING CHANGE: run_device_action is removed. Requires
napalm-device-types 4.13.
Part of #12 (the OpenBSD new_version text is still open).
run_command prepended the sudo password to the caller's stdin. A sudo
that does not prompt left it for the command, and fix_snmp's
'cat > snmpd.conf' wrote it as the configuration's first line before
making the file world-readable.
run_command now refuses stdin to a privileged command while a sudo
password is set. fix_snmp stages the configuration in a mktemp file
without privilege, and root installs it next to the target and renames
it over, so nothing root runs follows a symlink.
Closes#8
first_boot_pending() is true while /firstboot exists on FreeBSD. A FreeBSD
cloud image upgrades its base system on its first boot, starts sshd only
after that and restarts right away, and /etc/rc removes /firstboot just
before that restart. netOrk waits for this before it sets up a new VM
(NetOrk/netork#795).
OpenBSD has no such marker to ask yet, so it returns False there.
netOrk reads an empty update list as "no updates" and closes every patch
clock on the host. A refused sudo, a failing pkg, syspatch or freebsd-update,
or a pkg database pkg cannot read used to come back as that empty list. Each
of these now raises. Only pkg's "is not installed" still means no packages.
BsdDriver takes on napalm-device-types' HostStatusMixin. On FreeBSD it
reports a host whose installed kernel differs from the running one as
needing a reboot (device-types 4.1). OpenBSD stays unknown.
Closes#4