open_stream(privileged=True) with a sudo password wrote the password first,
for sudo -S. A sudo that does not prompt (NOPASSWD, a cached timestamp) left it
on stdin, where it reached the command as the first bytes of the stream: the
Podman API, over sudo podman system dial-stdio. The stream now asks sudo first
(sudo -n sh -c true) and runs the command through sudo -n when it needs no
password.
The driver cannot replace a device's configuration, and said so with a
load_replace_candidate that raised NotImplementedError. A method that only
raises still looks like a replace to anyone who asks whether the driver has
one: netOrk offered a config restore for these devices that could only fail.
None is how a driver switches off a method, the convention netOrk's
capability checks and napalm-device-types follow, so asking now says no.
Nothing in the driver calls it.
perf, python3-perf and bpftool are built from the kernel's source rpm, and
Red Hat's VEX lists them in every kernel CVE: 18 532 findings on an Oracle
Linux 9 host's three kernel tools alone. The rpm query now reads
%{SOURCERPM}, and each package carries its name as `source_rpm` (`perf` ->
`kernel`), absent where rpm names none (`gpg-pubkey`).
Not dpkg's `source_package`: netOrk reads that as the name a distribution
files its verdicts under, which holds for Debian and not for Oracle or Red
Hat, whose records name the binary (NetOrk/netork#2394).
linux.py had grown past its recorded size with the firewalld rule. The
snmpd.conf rendering, the install commands and the firewalld rule now
live in _snmp_agent.py; linux.py shrinks to 2014 lines and the baseline
records that.
On a host running firewalld, iptables is installed too, so the SNMP fix
inserted an iptables ACCEPT. firewalld keeps its own nftables table, whose
reject wins over it, and the step reported the port open while SNMP
stayed blocked.
With firewalld active, the step now adds a rich rule per allowed source to
the default zone (which takes interfaces in no zone, such as a WireGuard
interface) and to every active zone, at runtime and permanently, each only
when missing. No reload, which would drop rules others keep at runtime.
Closes#77
On an rpm host a package's version now carries its epoch where it has
one (1:6.2.0-13.el9), as on a dpkg host: Oracle's and Red Hat's fixes
name it, and without it an epoch-1 fix read as newer than every
installed build. get_installed_advisory_cves() reads, as root and from
the cache, the CVEs the installed security advisories close, through
napalm-device-types 4.37.0; dnf only (NetOrk/netork#2394).
netOrk aligns every device's NTP servers and time zone with the site's
(NetOrk/netork#2360). A Linux host gets get_time_sync() and
configure_time_sync() from napalm-device-types 4.35.0's
PosixTimeSyncMixin (#2361): one reading as the login user, the zone by
timedatectl, chrony's servers in a file of their own with every other
source commented out, systemd-timesyncd's in a drop-in. The driver only
carries the commands across run_command.
The mixin comes in with PosixScheduledJobsMixin through LinuxPosixMixin,
the implementations napalm-device-types makes for any POSIX host, so
linux.py does not grow. OpenMediaVault and QNAP inherit both.
netOrk holds a host's restart after patching while a backup runs on it
(NetOrk/netork#2318) and asks right before the restart. On a Linux host a
file-level backup is a process of a backup tool, started by a timer, a cron
line or by hand, so get_running_backups() (napalm-device-types 4.34.0) reads
the processes, the clock and each process's cgroup in one round trip as the
login user. What a tool does comes from its subcommand: restic backup is a
backup, restic forget a prune, restic mount none; borg serve counts, as the
receiving end of another host's backup. The systemd service a backup runs
in is its job, the timer's service netOrk shows as its scheduled job.
A ps without etimes (busybox) fails the reading rather than report nothing.
linux.py is over the file size limit and may not grow (quality ratchet).
Listening sockets and log sources share one transport -- through sudo where
the driver can, else as the login user -- so both move to _readings.py as
LinuxProcessReadingsMixin; linux.py shrinks from 2048 to 2039 lines.
Refs NetOrk/netork#2049
The driver mixes in napalm-device-types' LogSourcesMixin (4.30.0) and
carries its command: as root through sudo where it can, else what the
login user may see. OpenMediaVault and QNAP inherit it.
Refs NetOrk/netork#2049
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 usermod -p '*', which
leaves the expiry (the lock) alone and keeps the key login working with
and without PAM, where an empty password or a '!' would not.
See NetOrk/netork#2013
get_scheduled_jobs reads /etc/crontab, /etc/cron.d, the user crontabs,
run-parts, anacron and every systemd timer 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.
get_cron_jobs goes: it read without root, missed most of what a host
schedules, and nothing called it.
Requires napalm-device-types 4.26.0.
Closes#67
The running check looked for "active" anywhere in the answer, and
systemctl answers "inactive" for a stopped lldpd, so lldpctl was asked
anyway. The check now prints one word, running or stopped, and is
compared whole. With lldpd running, lldpctl runs as napalm-device-types'
LLDPCTL_KEYVALUE_COMMAND: a failure (socket out of the login's reach, a
daemon restarting) raises with lldpctl's message instead of reading as
a host without neighbours. A missing or stopped lldpd still answers {}.
Closes#66
napalm-device-types' lldp_neighbors now carries the chassis MAC as mac
when the chassis id is a MAC address, the rule this driver applied
itself. The getter uses the projection, so linux and openwrt report
neighbours the same way.
iproute2 prints an IPv4 route with an IPv6 next hop (RFC 8950, BGP
unnumbered) as "via inet6 fe80::1", and the next hop was read as the
literal "inet6". The family word after "via" is now skipped, for
multipath next hops as well.
With the address in place, get_route_to would have reported such a
route as ipv6, because it took the family from the next hop too. The
family is now the destination's alone. The test fixture is ip's output
(iproute2 6.1.0) recorded in a network namespace set up with these
routes.
Closes#65
The FRR enrichment in get_route_to completed every prefix without a
length with /32. An IPv6 host route became a different, much larger
/32 prefix, so it missed the kernel's /128 entry for the same host
(stored that way since #6) and added a bogus one instead.
with_length() in _routes.py completes a prefix by its family, /32 or
/128. The protocol attributes move onto IpRoute, which keeps the import
in linux.py on one line; get_route_to shrinks and the baseline records
it.
Closes#64
Quoting keeps a value one word, but ping still reads a word starting
with "-" as one of its options: ping(destination="-f") sent a flood
ping option instead of a host, and a source "-f" did the same after -I.
No address or hostname starts with "-", so ping_command now refuses
such a destination or source with ValueError before anything is sent.
Closes#63
lldpctl -f keyvalue was grouped by interface, so a second neighbour on a
port overwrote the first. The driver looked for chassis.id.value and
port.id.value, keys lldpd never prints (it names an id by its type,
chassis.mac, port.local), so the chassis MAC was never reported and a
port given by MAC or local id came back empty; and eth0.100 was cut at
its dot. The output now goes through napalm-device-types'
parse_lldpctl_keyvalue, which splits neighbours at their via line and
keeps the interface name whole; the floor on napalm-device-types rises
to 4.24.0 for it.
Closes#58
get_route_to took the first word of every "ip route show" line as the
destination. For unreachable, blackhole, prohibit and throw routes that
word is the route type, so they came back as "unreachable/32" and the
like; a multipath route's continuation lines became "nexthop/32"
routes, and the route itself had no next hop.
The type word is now read as the type and reported in
protocol_attributes, without a next hop or outgoing interface for the
types that forward nothing (IPv6 names lo for them). nexthop lines
attach to the route before them, one entry per next hop. The test
fixture is ip's output (iproute2 6.1.0) recorded in a network
namespace set up with these routes.
Closes#57
Without a root login and without a sudo password, _run_privileged typed
"sudo -n <command>" into the interactive shell. sudo covered only the
first simple command of the line, and dnf's and yum's advisory query,
which starts with a brace group, did not parse at all: no status marker
ever arrived, so netmiko waited out the 120 s read timeout and
get_available_updates() failed. This is the default path for netOrk's
own NOPASSWD account.
The command now goes to "sudo -n sh -c" as one argument, as _as_root
already does with a password. A status echo at its end stays outside
sh -c: it reports sh's status, which is the command's, and still
arrives when sudo refuses.
Closes#56
ping() typed its arguments into the interactive shell as they came, so a
destination such as "1.2.3.4; id" ran the command after the semicolon as
the login user. destination and source now go through shlex.quote, and
count, timeout, size and ttl are coerced with int(), which refuses
anything that is not a number before a command is sent.
The command is built in _ping.py, next to its parser, which keeps
linux.py within its recorded length.
Closes#55
`dnf check-update` and `yum check-update`, and yum's security query, download
the repositories' metadata first whenever the cached copy has expired. On an
Oracle Linux host on OCI that outlasted netOrk's 120 s poll on every run, and
the device went offline. They now run with --cacheonly, as apt's read uses its
local index; refresh_available_updates (`dnf makecache`) still refreshes it.
Without a cache the read fails at once and says to refresh the index. The
README row claimed check-update ran unprivileged; it runs as root.
dnf's security query is NAPALM/napalm-device-types#76.
Closes#59
get_route_to read "ip -4 route show && ip -6 route show" as one output
and mapped "default" to 0.0.0.0/0; the "default6" branch meant for IPv6
never matches, because ip -6 also prints "default". A dual-stack host
showed two 0.0.0.0/0 routes, one of them family ipv6. Each family is now
read with its own command, so "default" becomes ::/0 for IPv6 and a host
route without a prefix length a /128 there instead of a /32.
The line parse moves to napalm_linux/_routes.py.
Closes#6
ping() only knew the iputils summary. BusyBox, the ping on Alpine,
writes "2 packets received", so every target came back as an error and
the ping sweep counted it as down. Its probe lines ("seq=") and every
IPv6 reply were dropped by an IPv4-only per-probe pattern, and its
"round-trip min/avg/max" line without a deviation was not read.
The parse moves to napalm_linux/_ping.py and accepts both summaries
(also iputils' with "+N errors"), both RTT lines, IPv6 and named
replies. The shared Unix ping parser is still open as
NAPALM/napalm-device-types#12.
Closes#15
dpkg-query -W also lists packages that were removed but whose
configuration dpkg keeps (state rc), and the driver marked every line
installed: old kernels and a removed agent showed up as installed
software. The query now asks for db:Status-Abbrev and drops packages
that are not installed or only left their configuration; held, unpacked
and half-configured packages keep counting, their files are on disk.
The dpkg query and its parse move to napalm_linux/_dpkg.py, a pure
function under strict mypy, which keeps linux.py inside its line count.
Closes#17
get_processes split each ps line into 11 parts, but lstart is five
words, so started held only the weekday and command began with the rest
of the date. The line is now split into 15 parts, started joins the five
date words and command is the remainder. ps runs under LC_ALL=C: only
there are the weekday and month one word each on every host.
Closes#21
get_vpn_tunnels keyed a peer as wireguard-<iface>-<pubkey[:8]>. Base64
uses "/" and "+", and the key is used as a URL path segment; a "/"
breaks the route even percent-encoded. The prefix now maps "+" to "-"
and "/" to "_", as napalm-opnsense does (NAPALM/napalm-opnsense#32).
Affected peers change their key once.
Closes#43
install_package searched the output of `... || true` for words such as
"failed", the pattern uninstall_package left behind for netork#267: a
postinst that only mentions a failure read as a failed install, and a
failure phrased without those words read as success. It now runs through
_sudo_status like the removal and falls back to the keywords only when
the channel gave no exit status.
The ruff findings named in the issue are gone since the driver adopted
the standard; strict mypy for linux.py is held by the quality ratchet,
and the None-vs-dict package contract is NAPALM/napalm-device-types#36.
Closes#4
expect_for and STATUS_ECHO_RE say when netmiko's interactive shell has
finished printing a command's output, next to PROMPT_RE they build on.
Moving them out keeps linux.py within its line count now that it mixes in
the personal accounts; the baseline goes down to 2265.
OpenSSH 9.8+ closes every connection from a source it has just
penalised, before its banner, for seconds to minutes. open() now wraps
netmiko's ConnectHandler in napalm-device-types' retry_refused, so the
connection is tried again after 1, 3, 7 and 15 s instead of failing.
Needs NAPALM/napalm-device-types#63.
LinuxDriver mixes in napalm-device-types' LocalAccountsMixin with
useradd -m -s /bin/bash, usermod and gpasswd -d. A locked account is an
expired one (usermod -L -e 1): PAM refuses it a key login too, where a
"!" in front of the password stops only the password. Opening it again
lifts the expiry and gives the old password back.
Checked on Debian 13 and Rocky Linux 9 containers with sshd and sudo:
key login works after adding, is refused after locking and works again
after reopening; the sudo rule takes effect with the person's password;
membership of sudo/wheel goes when sudo is not wanted.
Until NetOrk/netork#1039, _sudo typed `echo '<password>' | sudo -S -p ""
<command>` into netmiko's interactive shell, so the login user's history
kept the password once per command, and the part after the first `&&` ran
without root, leaving snmpd.conf and apt's 00proxy to the login user.
LinuxDriver mixes in napalm-device-types' SudoHistoryMixin and names what
to look for: the marker "| sudo -S -p " and those two files.
get_history_sudo_lines() and remove_history_sudo_lines() run on the exec
channel; OpenMediaVault and QNAP inherit both.
The _privileged docstring points at _as_root instead of restating it, so
linux.py does not grow.
Requires the napalm-device-types release with SudoHistoryMixin.
ip neigh has no age, and a STALE entry may be hours old, so get_arp_table
reports ARP_AGE_UNKNOWN instead of 0.0 ("confirmed just now").
NetOrk/netork#1327
netOrk could save a Linux host's new name but not apply it: the driver had
no set_hostname(), so apply-hostname answered "The driver linux does not
support set_hostname()".
HostnameMixin.set_hostname() takes a bare name or an FQDN. The short name
goes to hostnamectl, or to /etc/hostname and hostname(1) without systemd.
/etc/hosts follows: every line naming the old name, else the 127.0.1.1
line; a file with neither is left alone. A cloud-init host gets
preserve_hostname: true, or its next boot restores the image's name.
Names that are not RFC 1123 hostnames are refused before anything runs.
Files are staged unprivileged and installed by root
(_install_file_as_root), never written from privileged stdin.
It lives in its own module because linux.py may not grow (quality
ratchet); the two lines it adds there are offset by a stale comment and
an import that fits on one line, so the baseline drops to 2286.
The prompt-hook step (#41) pushed linux.py past its line count in the
quality baseline. The three steps that make netmiko's fresh shell fit to
read - history off, prompt hooks off, no line wrap - and the prompt
pattern move to napalm_linux/_shell.py, under strict mypy. linux.py
shrinks below where it was; the baseline follows.
systemd 258 (Ubuntu 26.04) ships /etc/profile.d/80-systemd-osc-context.sh:
an interactive bash wraps every command in OSC 3008 sequences from PS0 and
PROMPT_COMMAND, each with a fresh UUID. They ended up in every value read
through netmiko's shell, and because the prompt never looked the same twice,
the prompt line stayed in the output too. os_version grew past 255
characters and netOrk could not store the poll.
The session now unsets PS0 and PROMPT_COMMAND right after switching the
history off and reads its prompt anew; _send() strips terminal codes from
what it returns.
Version 0.15.1.
get_package_proxy() is what apt-config dump says, not 00proxy alone: a
proxy in 90curtin-aptproxy or /etc/apt/apt.conf wins over it and was
missed. The driver now supplies only the transports: reads on the exec
channel, root commands through _root_outcome, the file through the staged
_install_file_as_root. New: get_package_proxy_report() and
check_package_proxy(). configure_package_proxy() also comments out other
proxy lines, reads the result back and fetches through the proxy.
Requires napalm-device-types 4.22.0; version 0.14.0.
- CI moves to .gitea/workflows/ci.yml and calls the shared driver workflow
of NAPALM/driver-standard; napalm-device-types comes from git until it is
on PyPI.
- requires-python >=3.10 (napalm-device-types needs it), LICENSE file,
py.typed, SPDX license string, links to git.netork.io.
- mypy strict for the package; napalm_linux.linux is exempt for now (21
errors), recorded in the quality baseline with its long functions and
the 2200-line module. Coverage floor 58 % (measured 58.23 %).
- Long shell command lines are split into adjacent string literals.
- get_os_users: a first loop over /etc/group filled a map nobody read;
it is gone, the output is unchanged.
- The five except Exception: pass now log at debug level (B110), so a
swallowed failure leaves a trace.
- nosec for the staging path on the device (B108) and the sudo hint
message (B105); both are false positives.
- tests: raise ... from exc, unused loop variable.
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.
Mixes in napalm-device-types' HostFirewallMixin. The transport runs the shared
read-only command as root on an exec channel: nft prints the whole ruleset as
one line of JSON, longer than the PTY takes reliably, and both nft and
iptables-save need CAP_NET_ADMIN. Requires napalm-device-types 4.21.0;
version 0.13.0.