feat(logins): get_login_accounts through napalm-device-types' LoginAccountsMixin (NetOrk/netork#2707)

The transport runs the shared, read-only command on an exec channel, as root
first for the lock, the expiry and the failed logins, and as the login user
where root is refused.
This commit is contained in:
Christian Manivong committed 2026-11-28 03:46:50 +01:00
1 parent 963f6d2736
commit ae71047f7f
3 files changed
+95 -4

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
"""Who can log in to the host, and how they do: napalm-device-types' ``LoginAccountsMixin``
(NetOrk/netork#2707).
The command and its parse are napalm-device-types'; this is only how the command
reaches the host. An exec channel, as for the hardening: the report can run to
thousands of lines on a host whose btmp is full, more than netmiko's PTY reads
reliably. Read-only either way; root for the lock, the expiry and the failed logins,
and the mixin falls back to the login user, for the last logins only, where root is
refused.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from napalm_device_types import CommandResult, LoginAccountsMixin
#: Seconds the reading may take: ``lastb`` reads all of btmp, which a host on the
#: internet fills quickly.
_READ_TIMEOUT = 120
class LinuxLoginAccountsMixin(LoginAccountsMixin):
"""The transport for ``get_login_accounts``."""
if TYPE_CHECKING: # pragma: no cover - the driver's own, declared for type checkers
def run_command(
self,
command: str,
*,
privileged: bool = False,
timeout: float = 60,
stdin: bytes | None = None,
) -> CommandResult: ...
def _run_login_accounts_command(self, command: str, *, privileged: bool) -> str:
return self.run_command(command, privileged=privileged, timeout=_READ_TIMEOUT).stdout
+7 -4
View File
@@ -10,7 +10,8 @@ NetOrk/netork#2700) are read as root only: a reading of the login user's own pro
would read as clean. It is one fixed command and reads no stdin.
The running backups need no root: every process's command line and cgroup are
readable to the login user (``_running_backups``). How the host is hardened
(``_hardening``) is read as root first, as the login user where root is refused.
(``_hardening``) and who can log in to it (``_logins``, NetOrk/netork#2707) are read
as root first, as the login user where root is refused.
"""
from __future__ import annotations
@@ -20,6 +21,7 @@ from typing import TYPE_CHECKING
from napalm_device_types import ListeningSocketsMixin, LogSourcesMixin, ServicesRestartMixin
from napalm_linux._hardening import LinuxHardeningMixin
from napalm_linux._logins import LinuxLoginAccountsMixin
from napalm_linux._running_backups import LinuxRunningBackupsMixin
#: Seconds either reading may take; a busy host lists thousands of descriptors.
@@ -32,11 +34,12 @@ class LinuxProcessReadingsMixin(
ServicesRestartMixin,
LinuxRunningBackupsMixin,
LinuxHardeningMixin,
LinuxLoginAccountsMixin,
):
"""The transports for ``get_listening_sockets``, ``get_log_sources`` and
``get_services_need_restart``, and ``get_running_backups`` and ``get_hardening``
(``_hardening``, NetOrk/netork#2706), which ride along here rather than lengthen
``linux.py``."""
``get_services_need_restart``, and ``get_running_backups``, ``get_hardening``
(``_hardening``, NetOrk/netork#2706) and ``get_login_accounts`` (``_logins``,
NetOrk/netork#2707), which ride along here rather than lengthen ``linux.py``."""
if TYPE_CHECKING: # pragma: no cover - the driver's own, declared for type checkers