feat: count and remove the sudo password the old _sudo left in histories (NetOrk/netork#1090)
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m3s
driver / test (3.12) (pull_request) Successful in 1m4s
driver / test (3.13) (pull_request) Successful in 1m10s
driver / lowest (pull_request) Successful in 59s
driver / build (pull_request) Successful in 38s
driver / security (pull_request) Successful in 1m30s
CI / driver (pull_request) Successful in 3m6s
driver / publish (pull_request) Skipped

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.
This commit is contained in:
Christian Manivong committed 2026-10-30 21:09:33 +01:00
1 parent 4cd1710e19
commit fbaded5913
5 files changed
+181 -5

No files matched your search

+9
View File
@@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- 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
was typed into the interactive shell as `echo '<password>' | sudo -S -p "" …`, so the
login user's history kept the password once per command. `get_history_sudo_lines()`
counts those lines with `grep -c`, without reading them; `remove_history_sudo_lines()`
deletes exactly them and gives `/etc/snmp/snmpd.conf` and `/etc/apt/apt.conf.d/00proxy`
back to `root:root` where the old partial sudo left them to the login user (a regular
file, never a symbolic link). OpenMediaVault and QNAP inherit both. Requires the
napalm-device-types release with `SudoHistoryMixin`.
- `set_hostname()` (#45): netOrk could save a Linux host's new name but not apply it
("The driver linux does not support set_hostname()"). The host now takes the short
name through `hostnamectl`, or `/etc/hostname` and `hostname(1)` without systemd;