feat(log-sources): which logs the host writes, through LogSourcesMixin
driver / standard (pull_request) Failing after 18s
driver / lint (pull_request) Successful in 16s
driver / test (3.12) (pull_request) Failing after 46s
driver / types (pull_request) Failing after 1m3s
driver / test (3.13) (pull_request) Failing after 40s
driver / lowest (pull_request) Failing after 23s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Failing after 1m1s
CI / driver (pull_request) Failing after 2m22s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Failing after 18s
driver / lint (pull_request) Successful in 16s
driver / test (3.12) (pull_request) Failing after 46s
driver / types (pull_request) Failing after 1m3s
driver / test (3.13) (pull_request) Failing after 40s
driver / lowest (pull_request) Failing after 23s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Failing after 1m1s
CI / driver (pull_request) Failing after 2m22s
driver / publish (pull_request) Skipped
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
This commit is contained in:
1 parent
249046512d
commit
2b153cd61c
4 files changed
+68
-1
No files matched your search
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- `get_log_sources()` through napalm-device-types' `LogSourcesMixin` (4.30.0): the units
|
||||
journald holds entries for and the log files running processes hold open, with the service
|
||||
or container writing each, as root, and without root what the login user may see
|
||||
(NetOrk/netork#2049). OpenMediaVault and QNAP inherit it.
|
||||
- A deleted key can take the password with it (NetOrk/netork#2033): through
|
||||
napalm-device-types' `remove_local_account_keys(..., clear_password=True)` the keys go
|
||||
as the person, the password goes (`usermod -p '*'`), and so do the sudo rule and the
|
||||
|
||||
@@ -40,6 +40,7 @@ from napalm_device_types import (
|
||||
KernelFactsMixin,
|
||||
ListeningSocketsMixin,
|
||||
LldpNeighborDict,
|
||||
LogSourcesMixin,
|
||||
OpenSshServerMixin,
|
||||
OSDriver,
|
||||
PosixScheduledJobsMixin,
|
||||
@@ -304,6 +305,7 @@ class LinuxDriver(
|
||||
KernelFactsMixin,
|
||||
ServicePackagesMixin,
|
||||
ListeningSocketsMixin,
|
||||
LogSourcesMixin,
|
||||
HostFirewallMixin,
|
||||
VirtualIpsMixin,
|
||||
ServiceClustersMixin,
|
||||
@@ -1098,6 +1100,15 @@ class LinuxDriver(
|
||||
return self._run_privileged(command, 60)
|
||||
return self._send(command, read_timeout=60)
|
||||
|
||||
def _run_log_sources_command(self, command: str, *, privileged: bool) -> str:
|
||||
"""The transport for ``LogSourcesMixin.get_log_sources``.
|
||||
|
||||
Read-only either way; root only so that every process shows its open files.
|
||||
"""
|
||||
if privileged:
|
||||
return self._run_privileged(command, 60)
|
||||
return self._send(command, read_timeout=60)
|
||||
|
||||
def _run_host_firewall_command(self, command: str, *, privileged: bool) -> str:
|
||||
"""The transport for ``HostFirewallMixin.get_host_firewall``: an exec channel.
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ classifiers = [
|
||||
]
|
||||
dependencies = [
|
||||
"napalm>=4.0",
|
||||
"napalm-device-types>=4.29.0",
|
||||
"napalm-device-types>=4.30.0",
|
||||
"netmiko>=4.0.0",
|
||||
"paramiko>=5.0.0", # CVE-2026-44405
|
||||
]
|
||||
|
||||
@@ -1955,6 +1955,58 @@ class TestGetListeningSockets:
|
||||
assert plain.startswith("sh -c '")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Log sources: journald units and the log files processes hold open (#2049)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_LOGS = (
|
||||
"LOGS_BEGIN\n[journald]\nnginx.service\n"
|
||||
"[open]\n/proc/900/fd/5 /var/log/nginx/access.log\n"
|
||||
"[stat]\n/proc/900/fd/5 2048 1762250200\n"
|
||||
"[cgroups]\n900 0::/system.slice/nginx.service\n"
|
||||
"[comm]\n900 nginx\n"
|
||||
"LOGS_END\n"
|
||||
)
|
||||
|
||||
|
||||
class TestGetLogSources:
|
||||
def _sent(self, driver) -> list[str]:
|
||||
return [c[0][0] for c in driver._device.send_command.call_args_list]
|
||||
|
||||
def test_it_reads_with_the_shared_command_as_root(self, driver):
|
||||
from napalm_device_types import LogSourcesMixin
|
||||
|
||||
assert isinstance(driver, LogSourcesMixin)
|
||||
driver._root = True
|
||||
driver._device.send_command.return_value = _LOGS
|
||||
|
||||
reading = driver.get_log_sources()
|
||||
|
||||
assert (reading["attributed"], reading["journald"]) == (True, True)
|
||||
access = [s for s in reading["sources"] if s["kind"] == "file"]
|
||||
assert [(s["path"], s["unit"]) for s in access] == [("/var/log/nginx/access.log", "nginx")]
|
||||
assert self._sent(driver)[0].startswith("sh -c '")
|
||||
|
||||
def test_without_a_sudo_password_the_whole_script_runs_under_sudo_n(self, driver):
|
||||
driver._root = False
|
||||
driver._device.send_command.return_value = _LOGS
|
||||
|
||||
driver.get_log_sources()
|
||||
|
||||
assert self._sent(driver)[0].startswith("sudo -n sh -c '")
|
||||
|
||||
def test_when_sudo_refuses_it_reads_what_the_user_may_see(self, driver):
|
||||
driver._root = False
|
||||
driver._device.send_command.side_effect = ["sudo: a password is required", _LOGS]
|
||||
|
||||
reading = driver.get_log_sources()
|
||||
|
||||
assert reading["attributed"] is False
|
||||
refused, plain = self._sent(driver)
|
||||
assert refused.startswith("sudo -n sh -c '")
|
||||
assert plain.startswith("sh -c '")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_system_identity (napalm-device-types SystemIdentityMixin)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user