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.
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.
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Until NetOrk/netork#1039,
_sudotypedecho '<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.confand/etc/apt/apt.conf.d/00proxyto the login user.LinuxDrivernow offers the count and the cleanup through napalm-device-types'SudoHistoryMixin.Changes
napalm_linux/_sudo_history.py:LinuxSudoHistoryMixinnames what to look for, the marker| sudo -S -pand the two files;LinuxDrivermixes it in.get_history_sudo_lines()andremove_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._privileged's docstring points at_as_rootinstead of restating it, solinux.pystays within the ratchet's line count.Merge order
Needs NAPALM/napalm-device-types
feat/sudo-history-cleanupmerged 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_sudotyped, 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 --covwith napalm-device-types from its branch: 259 passed; napalm-openmediavault 21 passed, napalm-qnap-qts 46 passed (1 xfailed);ruff,mypy,bandit,napalm-standard checkandratchetclean.