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.
20 lines
922 B
Python
20 lines
922 B
Python
"""What the old ``_sudo`` left on every host it reached (NetOrk/netork#1090).
|
|
|
|
Until NetOrk/netork#1039, ``_sudo`` typed ``echo '<password>' | sudo -S -p ""
|
|
<command>`` into netmiko's interactive shell, and only the part before the first
|
|
``&&`` ran as root. napalm-device-types' ``SudoHistoryMixin`` counts and deletes
|
|
those lines and gives the files back to root; this says what to look for.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from napalm_device_types import AptProxyMixin, SudoHistoryMixin
|
|
|
|
|
|
class LinuxSudoHistoryMixin(SudoHistoryMixin):
|
|
#: Every line the old ``_sudo`` typed carries it, with the sudo password before it.
|
|
SUDO_HISTORY_MARKER = "| sudo -S -p "
|
|
#: Written as the login user where the part that should have been root's came
|
|
#: after the first ``&&``: snmpd.conf (``configure_snmp_agent``) and apt's proxy.
|
|
SUDO_ROOT_FILES = ("/etc/snmp/snmpd.conf", AptProxyMixin.APT_PROXY_FILE)
|