feat(logins): optional keys for another platform's login accounts and sessions (NetOrk/netork#2895)
LoginAccountDict may carry sid, administrator and remote_desktop; uid stays an int and is the RID where a SID is given. LoginAccountsDict may carry groups (LoginGroupDict, LoginGroupMemberDict, LOGIN_GRANTS): the groups that grant administering the host or a remote desktop login, with every member. LoginSessionsDict may carry records_since, the oldest entry the record still holds. All optional: the Linux reading and every driver that builds one are unchanged.
This commit is contained in:
1 parent
2df46741f2
commit
a825d48c19
7 files changed
+176
-11
No files matched your search
@@ -267,9 +267,12 @@ from napalm_device_types.log_sources import (
|
||||
)
|
||||
from napalm_device_types.login_accounts import (
|
||||
LOGIN_ACCOUNTS_COMMAND,
|
||||
LOGIN_GRANTS,
|
||||
LoginAccountDict,
|
||||
LoginAccountsDict,
|
||||
LoginAccountsMixin,
|
||||
LoginGroupDict,
|
||||
LoginGroupMemberDict,
|
||||
login_capable,
|
||||
parse_login_accounts,
|
||||
)
|
||||
@@ -660,6 +663,9 @@ __all__ = [
|
||||
"LoginAccountDict",
|
||||
"LoginAccountsDict",
|
||||
"LoginAccountsMixin",
|
||||
"LOGIN_GRANTS",
|
||||
"LoginGroupDict",
|
||||
"LoginGroupMemberDict",
|
||||
"login_capable",
|
||||
"parse_login_accounts",
|
||||
"LOGIN_SESSIONS_COMMAND",
|
||||
|
||||
@@ -21,6 +21,13 @@ host that is every account with a shell, not only the ones an application create
|
||||
One fixed command, read-only, the same on every Linux host; ``LC_ALL=C`` keeps the tools'
|
||||
dates in one format. **Not read is None, never "no":** read as the login user, the lock,
|
||||
the expiry and the failures are ``None``, not "unlocked" or "none failed".
|
||||
|
||||
**Another platform** (NetOrk/netork#2895) fills the same reading from its own sources and
|
||||
may add the optional keys: an account's ``sid`` (Windows' security identifier, whose last
|
||||
part, the RID, is then its ``uid``), whether it can administer the host (``administrator``)
|
||||
and log in at a remote desktop (``remote_desktop``), and the reading's ``groups`` -- the
|
||||
host's groups that grant one of :data:`LOGIN_GRANTS`, with every member, a directory's
|
||||
included. The Linux reading sets none of them.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -102,10 +109,35 @@ _MUST_CHANGE = "password must be changed"
|
||||
_Sections = dict[tuple[str, str | None], list[str]]
|
||||
|
||||
|
||||
class LoginAccountDict(TypedDict):
|
||||
#: What a group in :class:`LoginGroupDict` grants its members: administering the host, and
|
||||
#: logging in at a remote desktop.
|
||||
LOGIN_GRANTS = ("administrator", "remote_desktop")
|
||||
|
||||
|
||||
class _PlatformLoginAccountDict(TypedDict, total=False):
|
||||
"""The keys of :class:`LoginAccountDict` only another platform than Linux sets.
|
||||
|
||||
A base of their own, as ``total=False``: ``NotRequired`` under postponed annotations
|
||||
is not seen by the class at runtime.
|
||||
"""
|
||||
|
||||
#: The account's security identifier (Windows); its ``uid`` is then the RID, the
|
||||
#: SID's last part.
|
||||
sid: str
|
||||
#: Can administer the host: a member of its Administrators (``S-1-5-32-544``) on
|
||||
#: Windows. None: not read.
|
||||
administrator: bool | None
|
||||
#: May log in at a remote desktop: the host takes such logins, and the account holds
|
||||
#: the right to (Windows: ``SeRemoteInteractiveLogonRight``, not denied). None: not
|
||||
#: read.
|
||||
remote_desktop: bool | None
|
||||
|
||||
|
||||
class LoginAccountDict(_PlatformLoginAccountDict):
|
||||
"""One login-capable account. ``None`` in a field: could not be read."""
|
||||
|
||||
name: str
|
||||
#: The POSIX UID; on Windows the RID (the last part of ``sid``).
|
||||
uid: int
|
||||
home: str
|
||||
shell: str
|
||||
@@ -114,7 +146,7 @@ class LoginAccountDict(TypedDict):
|
||||
last_login: str | None
|
||||
last_login_from: str | None # the remote host; None for a console login
|
||||
last_login_port: str | None # the terminal: "pts/0", "tty1", ":0"
|
||||
last_login_source: str | None # one of LOGIN_SOURCES
|
||||
last_login_source: str | None # one of LOGIN_SOURCES; "sam" on Windows
|
||||
password: str | None # "set", "locked" or "none" (passwd -S)
|
||||
password_changed: str | None # ISO date; None: never set, or not read
|
||||
password_expires: str | None # ISO date, "never" or "must_change"
|
||||
@@ -127,13 +159,47 @@ class LoginAccountDict(TypedDict):
|
||||
failed_logins_capped: bool
|
||||
|
||||
|
||||
class LoginAccountsDict(TypedDict):
|
||||
class LoginGroupMemberDict(TypedDict):
|
||||
"""One member of a :class:`LoginGroupDict`, as the host names it."""
|
||||
|
||||
#: ``DOMAIN\\name``, the host's own name for its own accounts; the SID where the
|
||||
#: host can no longer resolve it.
|
||||
name: str
|
||||
sid: str | None
|
||||
#: An account or group of the host itself; False: a directory's (a domain, Entra
|
||||
#: ID). None: not known.
|
||||
local: bool | None
|
||||
#: A group, whose own members hold what it grants too. None: not known.
|
||||
group: bool | None
|
||||
|
||||
|
||||
class LoginGroupDict(TypedDict):
|
||||
"""A group of the host that grants its members one of :data:`LOGIN_GRANTS`."""
|
||||
|
||||
#: As the host names it, in its language ("Administratoren").
|
||||
name: str
|
||||
sid: str | None
|
||||
#: Of :data:`LOGIN_GRANTS`.
|
||||
grants: list[str]
|
||||
members: list[LoginGroupMemberDict]
|
||||
|
||||
|
||||
class _PlatformLoginAccountsDict(TypedDict, total=False):
|
||||
"""The keys of :class:`LoginAccountsDict` only another platform than Linux sets."""
|
||||
|
||||
#: The groups that grant administering the host or a remote desktop login, with every
|
||||
#: member, a directory's too: who holds it beside the host's own accounts.
|
||||
groups: list[LoginGroupDict]
|
||||
|
||||
|
||||
class LoginAccountsDict(_PlatformLoginAccountsDict):
|
||||
"""What :meth:`LoginAccountsMixin.get_login_accounts` read."""
|
||||
|
||||
accounts: list[LoginAccountDict]
|
||||
#: The sources of the last logins the host has, of LOGIN_SOURCES; empty: none.
|
||||
#: The sources of the last logins the host has, of LOGIN_SOURCES (Windows: "sam");
|
||||
#: empty: none.
|
||||
login_sources: list[str]
|
||||
#: "lastb" or "faillock"; None: neither could be read.
|
||||
#: "lastb" or "faillock" (Windows: "sam"); None: neither could be read.
|
||||
failed_logins_source: str | None
|
||||
#: Read as root: the lock, the expiry and the failures are known.
|
||||
privileged: bool
|
||||
|
||||
@@ -95,8 +95,9 @@ _Sections = dict[tuple[str, str | None], list[str]]
|
||||
class LoginSessionDict(TypedDict):
|
||||
"""One interactive login the host recorded."""
|
||||
|
||||
#: The account; on Windows ``DOMAIN\\name`` for a directory's account.
|
||||
user: str
|
||||
tty: str # "pts/0", "tty1", "ttyS0"
|
||||
tty: str # "pts/0", "tty1", "ttyS0"; on Windows "console" or "rdp"
|
||||
#: Where it came from, an IP address as the record has it (IPv6 compressed), or the
|
||||
#: name sshd recorded where the tool could not give the address; None for a login at
|
||||
#: the host's own console.
|
||||
@@ -107,11 +108,24 @@ class LoginSessionDict(TypedDict):
|
||||
ended: str | None
|
||||
|
||||
|
||||
class LoginSessionsDict(TypedDict):
|
||||
class _PlatformLoginSessionsDict(TypedDict, total=False):
|
||||
"""The key of :class:`LoginSessionsDict` only another platform than Linux sets.
|
||||
|
||||
A base of its own, as ``total=False``: ``NotRequired`` under postponed annotations is
|
||||
not seen by the class at runtime.
|
||||
"""
|
||||
|
||||
#: The oldest entry the record the sessions came from still holds, ISO 8601 in UTC
|
||||
#: (Windows' Security log, which rotates by size). Later than the window's start, a
|
||||
#: login before it is unknown, not absent. None: the record is empty.
|
||||
records_since: str | None
|
||||
|
||||
|
||||
class LoginSessionsDict(_PlatformLoginSessionsDict):
|
||||
"""What :meth:`LoginSessionsMixin.get_login_sessions` read."""
|
||||
|
||||
#: The address the reading's own SSH session comes from; None when the host does not
|
||||
#: say (no ``SSH_CONNECTION``).
|
||||
#: The address the reading's own SSH session comes from (on Windows: its WinRM
|
||||
#: session); None when the host does not say (no ``SSH_CONNECTION``).
|
||||
own_address: str | None
|
||||
#: Newest first, the reading's own left out.
|
||||
sessions: list[LoginSessionDict]
|
||||
|
||||
Reference in new issue
Block a user