Merge remote-tracking branch 'origin/feature/windows-logins-2895' into chore/merge-train-windows-depth
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
0a81b7ee99
7 files changed
+174
-11
No files matched your search
@@ -29,6 +29,19 @@ recorded here; their history is the git log.
|
||||
- `UserDict.sid` (optional): the account's security identifier on a host that names
|
||||
accounts by one (Windows, NetOrk/netork#2889). `uid` stays an int: there, the relative
|
||||
identifier, the SID's last part.
|
||||
- Login accounts and login sessions from another platform than Linux (NetOrk/netork#2895),
|
||||
for Windows hosts in the access review. All optional, so the Linux reading and every
|
||||
driver that builds one stay as they are:
|
||||
- `LoginAccountDict` may carry `sid` (Windows' security identifier; `uid` is then the
|
||||
RID, the SID's last part), `administrator` (a member of the host's Administrators) and
|
||||
`remote_desktop` (may log in at a remote desktop), each `None` where not read.
|
||||
- `LoginAccountsDict` may carry `groups`: the host's groups that grant administering it
|
||||
or a remote desktop login (`LoginGroupDict`: name, SID, `grants` of `LOGIN_GRANTS`,
|
||||
members), with every member as the host names it, a directory's accounts and groups
|
||||
included (`LoginGroupMemberDict`: name, SID, `local`, `group`).
|
||||
- `LoginSessionsDict` may carry `records_since`: the oldest entry the record the sessions
|
||||
came from still holds, so a log that rotated within the window does not read as
|
||||
"nobody logged in" before it.
|
||||
|
||||
## [4.55.0] - 2026-12-01
|
||||
|
||||
|
||||
@@ -190,7 +190,11 @@ knows, and where it came from; its lock and expiry from `passwd -S` and `chage -
|
||||
failed attempts since that login, from `lastb` (the newest 1000 per account) or else
|
||||
`pam_faillock`'s tally. Read as root first and, where root is refused, as the login user,
|
||||
when the lock, the expiry and the failures are `None`. A driver supplies
|
||||
`_run_login_accounts_command(command, privileged=)`.
|
||||
`_run_login_accounts_command(command, privileged=)`. Another platform fills the same reading
|
||||
from its own sources and may add optional keys (NetOrk/netork#2895): an account's `sid`
|
||||
(Windows; `uid` is then the RID), `administrator` and `remote_desktop`, and the reading's
|
||||
`groups` -- the host's groups that grant one of `LOGIN_GRANTS`, with every member, a
|
||||
directory's included.
|
||||
|
||||
`LoginSessionsMixin` (`get_login_sessions`) is mixed in the same way: the interactive logins
|
||||
the host recorded over the last seven days -- each with its account, terminal, the address
|
||||
@@ -204,7 +208,9 @@ connection. Which other sessions an application opened itself is the application
|
||||
A driver supplies `_run_login_sessions_command(command)`, run as the login user, never
|
||||
through `sudo`, which would drop `SSH_CONNECTION`; the records are readable to everyone. A
|
||||
host with no record the reading can read (BusyBox's `last`) raises
|
||||
`LoginSessionsUnavailable`, never "nobody logged in".
|
||||
`LoginSessionsUnavailable`, never "nobody logged in". Another platform may add
|
||||
`records_since`, the oldest entry its record still holds (Windows' Security log rotates by
|
||||
size): a login before it is unknown, not absent.
|
||||
|
||||
`ServicePackagesMixin` (`get_service_packages`) is mixed in the same way: which installed
|
||||
packages each systemd service is made of — the one shipping its unit file and the one
|
||||
|
||||
@@ -269,9 +269,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,
|
||||
)
|
||||
@@ -666,6 +669,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]
|
||||
|
||||
@@ -481,3 +481,46 @@ class TestTheCommand:
|
||||
reading = parse_login_accounts(out)
|
||||
|
||||
assert isinstance(reading["accounts"], list)
|
||||
|
||||
|
||||
class TestWhatAnotherPlatformAdds:
|
||||
"""Keys a Windows host fills (NetOrk/netork#2895), optional, so the Linux reading and
|
||||
every driver that builds one stay as they are."""
|
||||
|
||||
def test_the_account_keys_linux_fills_stay_required(self):
|
||||
from napalm_device_types.login_accounts import LoginAccountDict
|
||||
|
||||
assert {"name", "uid", "home", "shell", "locked"} <= LoginAccountDict.__required_keys__
|
||||
assert LoginAccountDict.__optional_keys__ == frozenset(
|
||||
{"sid", "administrator", "remote_desktop"}
|
||||
)
|
||||
|
||||
def test_the_reading_may_name_the_privileged_groups(self):
|
||||
from napalm_device_types.login_accounts import (
|
||||
LoginAccountsDict,
|
||||
LoginGroupDict,
|
||||
LoginGroupMemberDict,
|
||||
)
|
||||
|
||||
assert LoginAccountsDict.__optional_keys__ == frozenset({"groups"})
|
||||
assert LoginGroupDict.__required_keys__ == frozenset({"name", "sid", "grants", "members"})
|
||||
assert LoginGroupMemberDict.__required_keys__ == frozenset(
|
||||
{"name", "sid", "local", "group"}
|
||||
)
|
||||
|
||||
def test_the_grants_are_named(self):
|
||||
from napalm_device_types.login_accounts import LOGIN_GRANTS
|
||||
|
||||
assert LOGIN_GRANTS == ("administrator", "remote_desktop")
|
||||
|
||||
def test_the_linux_reading_sets_none_of_them(self):
|
||||
reading = parse_login_accounts(_wire(DEBIAN_12))
|
||||
|
||||
assert "groups" not in reading
|
||||
for account in reading["accounts"]:
|
||||
assert not {"sid", "administrator", "remote_desktop"} & account.keys()
|
||||
|
||||
def test_they_are_exported(self):
|
||||
import napalm_device_types as dt
|
||||
|
||||
assert dt.LoginGroupDict and dt.LoginGroupMemberDict and dt.LOGIN_GRANTS
|
||||
@@ -290,3 +290,18 @@ class TestTheCommand:
|
||||
except LoginSessionsUnavailable: # a host without login records
|
||||
return
|
||||
assert isinstance(reading["sessions"], list)
|
||||
|
||||
|
||||
class TestWhatAnotherPlatformAdds:
|
||||
"""A key a Windows host fills (NetOrk/netork#2895), optional, so the Linux reading and
|
||||
every driver that builds one stay as they are."""
|
||||
|
||||
def test_the_keys_linux_fills_stay_required(self):
|
||||
from napalm_device_types.login_sessions import LoginSessionDict, LoginSessionsDict
|
||||
|
||||
assert LoginSessionsDict.__required_keys__ == frozenset({"own_address", "sessions"})
|
||||
assert LoginSessionsDict.__optional_keys__ == frozenset({"records_since"})
|
||||
assert LoginSessionDict.__optional_keys__ == frozenset()
|
||||
|
||||
def test_the_linux_reading_does_not_set_it(self):
|
||||
assert "records_since" not in parse_login_sessions(_wire(DEBIAN_12))
|
||||
Reference in new issue
Block a user