feat(login-sources): where a device checks a login, and what each place asks for, 4.50.0 (NetOrk/netork#662)
driver / standard (pull_request) Successful in 20s
driver / lint (pull_request) Successful in 17s
driver / types (pull_request) Successful in 1m1s
driver / test (3.12) (pull_request) Successful in 1m22s
driver / test (3.13) (pull_request) Successful in 1m13s
driver / lowest (pull_request) Successful in 43s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Successful in 3m0s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 20s
driver / lint (pull_request) Successful in 17s
driver / types (pull_request) Successful in 1m1s
driver / test (3.12) (pull_request) Successful in 1m22s
driver / test (3.13) (pull_request) Successful in 1m13s
driver / lowest (pull_request) Successful in 43s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Successful in 3m0s
driver / publish (pull_request) Skipped
LoginSourceDict names one source with the device's word for its kind and what it asks for: password, password_otp, external or unknown. WebLoginAuthDict is what a driver's get_web_login_auth returns, every source the web interface tries, in the device's order. SshServerAuthDict takes password_sources and server_enabled for a platform that writes sshd_config itself.
This commit is contained in:
1 parent
07920941c8
commit
d778c805c1
7 files changed
+163
-2
No files matched your search
@@ -227,6 +227,12 @@ from napalm_device_types.log_sources import (
|
||||
parse_log_forwarding,
|
||||
parse_log_sources,
|
||||
)
|
||||
from napalm_device_types.login_sources import (
|
||||
LOGIN_FACTORS,
|
||||
LoginFactors,
|
||||
LoginSourceDict,
|
||||
WebLoginAuthDict,
|
||||
)
|
||||
from napalm_device_types.mac_acl import MacAclMixin
|
||||
from napalm_device_types.management_controller import ManagementControllerDriver
|
||||
from napalm_device_types.media import MediaDriver
|
||||
@@ -657,6 +663,10 @@ __all__ = [
|
||||
"parse_system_identity",
|
||||
"OpenSshServerMixin",
|
||||
"PamAuthEntryDict",
|
||||
"LOGIN_FACTORS",
|
||||
"LoginFactors",
|
||||
"LoginSourceDict",
|
||||
"WebLoginAuthDict",
|
||||
"SshServerAuthDict",
|
||||
"SshServerAuthMixin",
|
||||
"SSHD_EFFECTIVE_COMMAND",
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"""Where a device checks a person's login, and what each place asks for.
|
||||
|
||||
Some platforms keep their own list of authentication servers and try a login
|
||||
against each in turn, and the first one that accepts it lets the person in. On
|
||||
OPNsense that list (*System → Settings → Administration → Authentication*) serves
|
||||
the web interface, the console and sshd's password login alike. Whether a password
|
||||
alone gets in then depends on every server in the list, not on one switch. So the
|
||||
driver names each place it tries, in the device's own order, with what that place
|
||||
asks for. Which of them counts as a second factor for a policy is the consumer's
|
||||
call (NetOrk/netork#662).
|
||||
|
||||
Two readings carry these sources:
|
||||
|
||||
- ``get_web_login_auth`` returns :class:`WebLoginAuthDict`: how the device's web
|
||||
interface lets people log in. A driver that cannot tell does not have the method,
|
||||
so ``hasattr`` stays a truthful answer.
|
||||
- :class:`~napalm_device_types.ssh_server_auth.SshServerAuthDict` takes
|
||||
``password_sources`` where the platform, not PAM's stack, decides what checks a
|
||||
password over SSH.
|
||||
|
||||
What a source asks for (:data:`LOGIN_FACTORS`):
|
||||
|
||||
- ``password``: a password alone, as with local accounts or an LDAP bind.
|
||||
- ``password_otp``: a password and a one-time code together. Without a code
|
||||
there is no login.
|
||||
- ``external``: another system decides, for example a RADIUS server. How many
|
||||
factors it asks for cannot be seen from the device.
|
||||
- ``unknown``: a kind of source the driver does not know.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Literal, TypedDict
|
||||
|
||||
LoginFactors = Literal["password", "password_otp", "external", "unknown"]
|
||||
|
||||
#: Every value of :data:`LoginFactors`, in the order of the module docstring.
|
||||
LOGIN_FACTORS: tuple[LoginFactors, ...] = ("password", "password_otp", "external", "unknown")
|
||||
|
||||
|
||||
class LoginSourceDict(TypedDict):
|
||||
"""One place a login is checked.
|
||||
|
||||
``{"name": "TOTP", "kind": "totp", "factors": "password_otp"}``
|
||||
"""
|
||||
|
||||
#: The source's name as the device shows it.
|
||||
name: str
|
||||
#: The device's own word for the kind, as written: ``local``, ``totp``, ``radius``.
|
||||
kind: str
|
||||
factors: LoginFactors
|
||||
|
||||
|
||||
class WebLoginAuthDict(TypedDict):
|
||||
"""How a device's web interface lets people log in, as ``get_web_login_auth`` read it."""
|
||||
|
||||
#: Every source a login is tried against, in the device's order. A login that
|
||||
#: any one of them accepts gets in.
|
||||
sources: list[LoginSourceDict]
|
||||
@@ -30,6 +30,8 @@ import re
|
||||
from collections.abc import Mapping
|
||||
from typing import TYPE_CHECKING, TypedDict
|
||||
|
||||
from napalm_device_types.login_sources import LoginSourceDict
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover - for type checkers only
|
||||
from napalm_device_types.channel import CommandResult
|
||||
|
||||
@@ -62,7 +64,18 @@ class PamAuthEntryDict(TypedDict):
|
||||
args: list[str]
|
||||
|
||||
|
||||
class SshServerAuthDict(TypedDict):
|
||||
class _PlatformSshAuthDict(TypedDict, total=False):
|
||||
"""The keys of :class:`SshServerAuthDict` only a platform that writes sshd_config sets.
|
||||
|
||||
A base of their own, as ``total=False``: ``NotRequired`` under postponed
|
||||
annotations is not seen by the class at runtime.
|
||||
"""
|
||||
|
||||
password_sources: list[LoginSourceDict]
|
||||
server_enabled: bool
|
||||
|
||||
|
||||
class SshServerAuthDict(_PlatformSshAuthDict):
|
||||
"""How an OpenSSH server lets people log in, as ``get_ssh_server_auth`` read it.
|
||||
|
||||
The global settings ``sshd -T`` prints. A ``Match`` block can change them for
|
||||
@@ -77,6 +90,16 @@ class SshServerAuthDict(TypedDict):
|
||||
``use_pam`` is None where sshd has no PAM (OpenBSD). ``pam_auth_stack`` is the
|
||||
``auth`` stack PAM runs for sshd, includes and substacks followed; None when
|
||||
PAM is off or its files gave nothing for sshd.
|
||||
|
||||
Two keys only a platform that writes sshd_config itself sets, read from its
|
||||
own configuration rather than from a running sshd:
|
||||
|
||||
- ``password_sources``: what checks a password or keyboard-interactive login,
|
||||
where the platform decides that rather than PAM's stack. OPNsense's PAM
|
||||
module tries its authentication servers. Absent where the stack says it.
|
||||
- ``server_enabled``: False when the platform's SSH server is switched off.
|
||||
Nobody then logs in over SSH, whatever the other keys say. Absent where the
|
||||
reading came from a running sshd.
|
||||
"""
|
||||
|
||||
password_authentication: bool
|
||||
|
||||
Reference in new issue
Block a user