driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 16s
driver / lowest (pull_request) Successful in 41s
driver / test (3.12) (pull_request) Successful in 1m28s
driver / test (3.13) (pull_request) Successful in 1m16s
driver / types (pull_request) Successful in 1m33s
driver / security (pull_request) Successful in 1m0s
driver / build (pull_request) Successful in 30s
CI / driver (pull_request) Successful in 2m0s
driver / publish (pull_request) Skipped
The interactive logins the host recorded, napalm-device-types' command on an exec channel as the login user: wtmp is readable to everyone, and sudo would drop SSH_CONNECTION, which names the driver's own address.
44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
"""Who can log in to the host, and how they do: napalm-device-types' ``LoginAccountsMixin``
|
|
(NetOrk/netork#2707); and the interactive logins it recorded, ``LoginSessionsMixin``
|
|
(NetOrk/netork#2881).
|
|
|
|
The commands and their parses are napalm-device-types'; this is only how the commands
|
|
reach 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. The sessions are read as the login user only: the records are readable to
|
|
everyone, and sudo would drop ``SSH_CONNECTION``, which names the driver's own address.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from napalm_device_types import CommandResult, LoginAccountsMixin, LoginSessionsMixin
|
|
|
|
#: Seconds the reading may take: ``lastb`` reads all of btmp, which a host on the
|
|
#: internet fills quickly.
|
|
_READ_TIMEOUT = 120
|
|
|
|
|
|
class LinuxLoginAccountsMixin(LoginAccountsMixin, LoginSessionsMixin):
|
|
"""The transports for ``get_login_accounts`` and ``get_login_sessions``."""
|
|
|
|
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
|
|
|
|
def _run_login_sessions_command(self, command: str) -> str:
|
|
return self.run_command(command, timeout=_READ_TIMEOUT).stdout
|