feat: count and remove the sudo password the old _sudo left in histories (NetOrk/netork#1090) #48

Merged
christianmanivong merged 1 commits from feat/sudo-history-cleanup into main 2026-10-30 20:52:36 +00:00
Owner

Summary

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 /etc/snmp/snmpd.conf and /etc/apt/apt.conf.d/00proxy to the login user. LinuxDriver now offers the count and the cleanup through napalm-device-types' SudoHistoryMixin.

Changes

  • napalm_linux/_sudo_history.py: LinuxSudoHistoryMixin names what to look for, the marker | sudo -S -p and the two files; LinuxDriver mixes it in. get_history_sudo_lines() and remove_history_sudo_lines() run on the exec channel (no history, nothing typed into the shell); root's step takes no stdin but the sudo password.
  • OpenMediaVault and QNAP inherit both (their tests pass against this branch).
  • _privileged's docstring points at _as_root instead of restating it, so linux.py stays within the ratchet's line count.
  • README and CHANGELOG (Unreleased).

Merge order

Needs NAPALM/napalm-device-types feat/sudo-history-cleanup merged first: CI pre-installs napalm-device-types from git main, so this PR's CI is red until then. The dependency floor goes up with the next napalm-device-types release, as for the earlier mixins.

Related Issue

NetOrk/netork#1090

Testing

  • tests/test_sudo_history.py: the marker matches what the old _sudo typed, the two files, counting as the login user without stdin and without the interactive shell, and the owner fix as root with only the password on stdin.
  • pytest --cov with napalm-device-types from its branch: 259 passed; napalm-openmediavault 21 passed, napalm-qnap-qts 46 passed (1 xfailed); ruff, mypy, bandit, napalm-standard check and ratchet clean.
## Summary 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 `/etc/snmp/snmpd.conf` and `/etc/apt/apt.conf.d/00proxy` to the login user. `LinuxDriver` now offers the count and the cleanup through napalm-device-types' `SudoHistoryMixin`. ## Changes - `napalm_linux/_sudo_history.py`: `LinuxSudoHistoryMixin` names what to look for, the marker `| sudo -S -p ` and the two files; `LinuxDriver` mixes it in. `get_history_sudo_lines()` and `remove_history_sudo_lines()` run on the exec channel (no history, nothing typed into the shell); root's step takes no stdin but the sudo password. - OpenMediaVault and QNAP inherit both (their tests pass against this branch). - `_privileged`'s docstring points at `_as_root` instead of restating it, so `linux.py` stays within the ratchet's line count. - README and CHANGELOG (Unreleased). ## Merge order Needs NAPALM/napalm-device-types `feat/sudo-history-cleanup` merged first: CI pre-installs napalm-device-types from git main, so this PR's CI is red until then. The dependency floor goes up with the next napalm-device-types release, as for the earlier mixins. ## Related Issue NetOrk/netork#1090 ## Testing - `tests/test_sudo_history.py`: the marker matches what the old `_sudo` typed, the two files, counting as the login user without stdin and without the interactive shell, and the owner fix as root with only the password on stdin. - `pytest --cov` with napalm-device-types from its branch: 259 passed; napalm-openmediavault 21 passed, napalm-qnap-qts 46 passed (1 xfailed); `ruff`, `mypy`, `bandit`, `napalm-standard check` and `ratchet` clean.
christianmanivong added 1 commit 2026-10-30 20:09:56 +00:00
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
fbaded5913
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.
christianmanivong merged commit 7550b884b0 into main 2026-10-30 20:52:36 +00:00
christianmanivong deleted branch feat/sudo-history-cleanup 2026-10-30 20:52:36 +00:00
Sign in to join this conversation.