Merge remote-tracking branch 'origin/feature/windows-posture-2893' into chore/merge-train-windows-depth
driver / lint (pull_request) Successful in 17s
driver / standard (pull_request) Failing after 19s
driver / lowest (pull_request) Successful in 48s
driver / types (pull_request) Successful in 1m14s
driver / test (3.12) (pull_request) Successful in 1m33s
driver / build (pull_request) Successful in 28s
driver / test (3.13) (pull_request) Successful in 1m26s
driver / security (pull_request) Successful in 56s
CI / driver (pull_request) Failing after 2m3s
driver / publish (pull_request) Skipped
driver / lint (pull_request) Successful in 17s
driver / standard (pull_request) Failing after 19s
driver / lowest (pull_request) Successful in 48s
driver / types (pull_request) Successful in 1m14s
driver / test (3.12) (pull_request) Successful in 1m33s
driver / build (pull_request) Successful in 28s
driver / test (3.13) (pull_request) Successful in 1m26s
driver / security (pull_request) Successful in 56s
CI / driver (pull_request) Failing after 2m3s
driver / publish (pull_request) Skipped
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
47ad8c55bf
5 files changed
+272
-3
No files matched your search
@@ -96,6 +96,14 @@ recorded here; their history is the git log.
|
||||
Update's KB articles), the `cves` it fixes on this host, and the vendor's own rating
|
||||
(`vendor_severity`, Windows Update's `MsrcSeverity`). `UpdateHistoryPackageDict` takes an
|
||||
optional `title`. Every reader that leaves them out still conforms.
|
||||
- A host's security posture in `HardeningDict` (NetOrk/netork#2893), as optional keys a
|
||||
driver fills where it reads them, so a Windows host's protection fits the same reading as
|
||||
a Linux host's hardening: `secure_boot` (`SecureBootState`: `on`, `off`, `unsupported`),
|
||||
`tpm` (`TpmDict`), `disk_encryption` (`DiskEncryptionDict` with an `EncryptedVolumeDict`
|
||||
per volume and its `VolumeProtection`), `antimalware` (`AntimalwareDict`, its
|
||||
`AntimalwareMode` telling whether another product protects the host), `firewall_profiles`
|
||||
(`FirewallProfileDict`, on or off) and `vbs` (`VbsDict`, `VbsStatus`). Everything Linux
|
||||
fills stays required and unchanged; `parse_hardening` fills none of the new keys.
|
||||
|
||||
## [4.55.0] - 2026-12-01
|
||||
|
||||
|
||||
@@ -193,6 +193,15 @@ command line, `ID`/`ID_LIKE` from `/etc/os-release`, whether the host runs virtu
|
||||
(`systemd-detect-virt`, else the `hypervisor` CPU flag) and the CPU's `vendor_id`. Read as root first and, where root
|
||||
is refused, as the login user without the profile counts. A driver supplies
|
||||
`_run_hardening_command(command, privileged=)`; what was not read is `None`, never "off".
|
||||
`HardeningDict` also carries a host's security posture in terms no OS owns, as optional keys
|
||||
a driver fills where it reads them (NetOrk/netork#2893): `secure_boot` (`on`, `off`, or
|
||||
`unsupported` on a BIOS boot), `tpm` (`TpmDict`), `disk_encryption` (`DiskEncryptionDict`:
|
||||
the provider, whether it is installed, and each volume's protection, status and cipher),
|
||||
`antimalware` (`AntimalwareDict`: enabled, real-time protection, the mode -- `passive` and
|
||||
`edr_block` when another product protects the host -- and the signatures' date and age),
|
||||
`firewall_profiles` (each profile on or off; the rules are the host firewall reading's) and
|
||||
`vbs` (virtualization-based security and the services it runs). The Linux reading fills
|
||||
none of them yet. They carry state, never a secret: no recovery password or key protector.
|
||||
|
||||
`LoginAccountsMixin` (`get_login_accounts`) is mixed in the same way: every account on the
|
||||
host a person can log in with -- root and UID 1000 on, with a shell that is not `nologin` or
|
||||
|
||||
@@ -206,8 +206,14 @@ from napalm_device_types.fixes import (
|
||||
)
|
||||
from napalm_device_types.hardening import (
|
||||
HARDENING_COMMAND,
|
||||
AntimalwareDict,
|
||||
DiskEncryptionDict,
|
||||
EncryptedVolumeDict,
|
||||
FirewallProfileDict,
|
||||
HardeningDict,
|
||||
HardeningMixin,
|
||||
TpmDict,
|
||||
VbsDict,
|
||||
cpu_vulnerability_state,
|
||||
parse_hardening,
|
||||
)
|
||||
@@ -714,6 +720,12 @@ __all__ = [
|
||||
"firmware_component",
|
||||
"microcode_package",
|
||||
"HardeningDict",
|
||||
"AntimalwareDict",
|
||||
"DiskEncryptionDict",
|
||||
"EncryptedVolumeDict",
|
||||
"FirewallProfileDict",
|
||||
"TpmDict",
|
||||
"VbsDict",
|
||||
"cpu_vulnerability_state",
|
||||
"parse_hardening",
|
||||
"LOGIN_ACCOUNTS_COMMAND",
|
||||
|
||||
@@ -28,14 +28,22 @@ here once and a driver only carries the command across. **Not read is None, neve
|
||||
empty or off:** a section the command did not print -- a file missing, a tool not
|
||||
installed, root refused -- comes back ``None``, so a consumer never reads "not looked"
|
||||
as "clean".
|
||||
|
||||
**The security posture, on any OS** (NetOrk/netork#2893). Six optional keys answer the
|
||||
first questions about a host's protection in terms no OS owns: ``secure_boot``, ``tpm``,
|
||||
``disk_encryption`` (per volume), ``antimalware``, ``firewall_profiles`` and ``vbs``
|
||||
(virtualization-based security). A driver that reads them fills them; one that does not
|
||||
leaves them out, which reads the same as ``None``: not read. ``parse_hardening`` (Linux)
|
||||
fills none of them yet. They carry state only, never a secret: no recovery password, no
|
||||
key protector, no key.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
# No ``from __future__ import annotations``: TypedDict reads ``NotRequired`` off the
|
||||
# evaluated annotations, and HardeningDict's posture keys are optional.
|
||||
import json
|
||||
import re
|
||||
from shlex import quote
|
||||
from typing import TYPE_CHECKING, Literal, TypedDict
|
||||
from typing import TYPE_CHECKING, Literal, NotRequired, TypedDict
|
||||
|
||||
from napalm_device_types.terminal import strip_terminal_codes
|
||||
|
||||
@@ -98,6 +106,86 @@ class AppArmorDict(TypedDict):
|
||||
profiles: dict[str, int] | None
|
||||
|
||||
|
||||
#: Secure Boot: "on" or "off" on a UEFI host; "unsupported" where the firmware has none
|
||||
#: (a BIOS boot), which is no finding.
|
||||
SecureBootState = Literal["on", "off", "unsupported"]
|
||||
#: Whether a volume's encryption protects it now: "off" too where it is encrypted but its
|
||||
#: protection is suspended, or its key sits in the clear on the volume.
|
||||
VolumeProtection = Literal["on", "off", "unknown"]
|
||||
#: Who protects the host: "active" the product itself; "passive" and "sxs_passive" another
|
||||
#: product does, and this one only scans on demand; "edr_block" another product does, and
|
||||
#: this one's EDR blocks what it detects after the fact.
|
||||
AntimalwareMode = Literal["active", "passive", "edr_block", "sxs_passive"]
|
||||
#: Virtualization-based security: "configured" is switched on but not running (yet).
|
||||
VbsStatus = Literal["off", "configured", "running"]
|
||||
|
||||
|
||||
class TpmDict(TypedDict):
|
||||
"""The host's Trusted Platform Module. ``None`` in a field: could not be read."""
|
||||
|
||||
present: bool # False: the host has no TPM, or the firmware hides it
|
||||
enabled: bool | None
|
||||
activated: bool | None
|
||||
owned: bool | None # taken into use by the OS
|
||||
version: str | None # the specification's version: "2.0", "1.2"
|
||||
manufacturer: str | None # the vendor's ID as the TPM gives it: "INTC", "AMD", "MSFT"
|
||||
|
||||
|
||||
class EncryptedVolumeDict(TypedDict):
|
||||
"""One volume the host's disk encryption knows."""
|
||||
|
||||
volume: str # where it is mounted: "C:", "/", "/home"
|
||||
system: bool # the volume the OS runs from
|
||||
protection: VolumeProtection
|
||||
#: "fully_encrypted", "fully_decrypted", "encrypting", "decrypting",
|
||||
#: "encryption_paused", "decryption_paused"; None where the tool gives none.
|
||||
status: str | None
|
||||
method: str | None # the cipher, in snake case: "xts_aes_128", "aes_256", ...
|
||||
|
||||
|
||||
class DiskEncryptionDict(TypedDict):
|
||||
"""The host's own disk encryption: BitLocker on Windows, LUKS on Linux."""
|
||||
|
||||
provider: str # "bitlocker", "luks"
|
||||
#: False where the host does not have it (BitLocker is a feature a Windows Server
|
||||
#: installs first): no volume can be encrypted with it, ``volumes`` is empty.
|
||||
installed: bool
|
||||
volumes: list[EncryptedVolumeDict]
|
||||
|
||||
|
||||
class AntimalwareDict(TypedDict):
|
||||
"""The host's own antimalware product, as it reports itself. ``None``: not read."""
|
||||
|
||||
product: str # "Microsoft Defender Antivirus"
|
||||
enabled: bool | None # its scanning engine is on
|
||||
real_time: bool | None # it scans files as they are opened
|
||||
mode: AntimalwareMode | None
|
||||
signatures_updated: int | None # when its signatures were last updated, unix seconds
|
||||
signature_age_days: int | None # their age in days, as the product counts it
|
||||
signature_version: str | None
|
||||
tamper_protected: bool | None # its settings are locked against local changes
|
||||
|
||||
|
||||
class FirewallProfileDict(TypedDict):
|
||||
"""One profile of the host's own firewall: whether it filters at all.
|
||||
|
||||
Its rules are not here: what they let through is the host firewall reading's.
|
||||
"""
|
||||
|
||||
name: str # lowercase: "domain", "private", "public"
|
||||
enabled: bool | None
|
||||
|
||||
|
||||
class VbsDict(TypedDict):
|
||||
"""Virtualization-based security: the hypervisor-isolated part of the OS."""
|
||||
|
||||
status: VbsStatus | None
|
||||
#: The services it runs, in snake case: "credential_guard", "hvci" (memory
|
||||
#: integrity), "system_guard", "smm_firmware_measurement", "kernel_shadow_stacks",
|
||||
#: "kernel_shadow_stacks_audit", "hypervisor_paging_translation"; None where not read.
|
||||
running: list[str] | None
|
||||
|
||||
|
||||
class HardeningDict(TypedDict):
|
||||
"""What :meth:`HardeningMixin.get_hardening` read. ``None``: not read, never "off"."""
|
||||
|
||||
@@ -117,6 +205,13 @@ class HardeningDict(TypedDict):
|
||||
#: ``hypervisor`` CPU flag tells it.
|
||||
virtualization: str | None
|
||||
cpu_vendor: str | None # the first vendor_id of /proc/cpuinfo: "GenuineIntel", ...
|
||||
# The security posture (NetOrk/netork#2893); left out where the driver does not read it.
|
||||
secure_boot: NotRequired[SecureBootState | None]
|
||||
tpm: NotRequired[TpmDict | None]
|
||||
disk_encryption: NotRequired[DiskEncryptionDict | None]
|
||||
antimalware: NotRequired[AntimalwareDict | None] # None also where it reports nothing
|
||||
firewall_profiles: NotRequired[list[FirewallProfileDict] | None]
|
||||
vbs: NotRequired[VbsDict | None]
|
||||
|
||||
|
||||
def cpu_vulnerability_state(text: str) -> CpuVulnerabilityState:
|
||||
@@ -350,6 +445,10 @@ class HardeningMixin:
|
||||
own hardware; "vm" where only the ``hypervisor`` CPU flag tells it
|
||||
* cpu_vendor (str or None) - ``vendor_id`` of ``/proc/cpuinfo``
|
||||
|
||||
A driver may add the security posture (``secure_boot``, ``tpm``,
|
||||
``disk_encryption``, ``antimalware``, ``firewall_profiles``, ``vbs``); this Linux
|
||||
reading does not yet.
|
||||
|
||||
``None`` means not read. Read as root first, for AppArmor's profiles; where root
|
||||
is refused, as the login user, without them.
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
"""The OS-neutral security posture in HardeningDict (NetOrk/netork#2893).
|
||||
|
||||
Secure Boot, the TPM, disk encryption per volume, the antimalware product, the host
|
||||
firewall's profiles and virtualization-based security: optional keys beside what a Linux
|
||||
host reports, so a Windows host's reading fits the same shape and Linux's stays as it is.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import get_args, get_type_hints
|
||||
|
||||
from napalm_device_types import (
|
||||
AntimalwareDict,
|
||||
DiskEncryptionDict,
|
||||
EncryptedVolumeDict,
|
||||
FirewallProfileDict,
|
||||
HardeningDict,
|
||||
TpmDict,
|
||||
VbsDict,
|
||||
)
|
||||
from napalm_device_types.hardening import (
|
||||
AntimalwareMode,
|
||||
SecureBootState,
|
||||
VbsStatus,
|
||||
VolumeProtection,
|
||||
parse_hardening,
|
||||
)
|
||||
|
||||
LINUX_KEYS = frozenset(
|
||||
{
|
||||
"lsm",
|
||||
"selinux",
|
||||
"apparmor",
|
||||
"crypto_policy",
|
||||
"fips",
|
||||
"cpu_vulnerabilities",
|
||||
"cmdline",
|
||||
"mitigations",
|
||||
"nosmt",
|
||||
"os_ids",
|
||||
"virtualization",
|
||||
"cpu_vendor",
|
||||
}
|
||||
)
|
||||
POSTURE_KEYS = frozenset(
|
||||
{"secure_boot", "tpm", "disk_encryption", "antimalware", "firewall_profiles", "vbs"}
|
||||
)
|
||||
|
||||
|
||||
def test_what_linux_fills_stays_required():
|
||||
assert HardeningDict.__required_keys__ == LINUX_KEYS
|
||||
|
||||
|
||||
def test_the_posture_keys_are_optional():
|
||||
assert HardeningDict.__optional_keys__ == POSTURE_KEYS
|
||||
|
||||
|
||||
def test_a_linux_reading_carries_none_of_them():
|
||||
reading = parse_hardening("HARDENING_BEGIN\n[fips]\n0\nHARDENING_END\n")
|
||||
|
||||
assert set(reading) == LINUX_KEYS
|
||||
|
||||
|
||||
def test_the_words_each_state_takes():
|
||||
assert set(get_args(SecureBootState)) == {"on", "off", "unsupported"}
|
||||
assert set(get_args(VolumeProtection)) == {"on", "off", "unknown"}
|
||||
assert set(get_args(AntimalwareMode)) == {"active", "passive", "edr_block", "sxs_passive"}
|
||||
assert set(get_args(VbsStatus)) == {"off", "configured", "running"}
|
||||
|
||||
|
||||
def test_the_shapes():
|
||||
assert set(get_type_hints(TpmDict)) == {
|
||||
"present",
|
||||
"enabled",
|
||||
"activated",
|
||||
"owned",
|
||||
"version",
|
||||
"manufacturer",
|
||||
}
|
||||
assert set(get_type_hints(EncryptedVolumeDict)) == {
|
||||
"volume",
|
||||
"system",
|
||||
"protection",
|
||||
"status",
|
||||
"method",
|
||||
}
|
||||
assert set(get_type_hints(DiskEncryptionDict)) == {"provider", "installed", "volumes"}
|
||||
assert set(get_type_hints(AntimalwareDict)) == {
|
||||
"product",
|
||||
"enabled",
|
||||
"real_time",
|
||||
"mode",
|
||||
"signatures_updated",
|
||||
"signature_age_days",
|
||||
"signature_version",
|
||||
"tamper_protected",
|
||||
}
|
||||
assert set(get_type_hints(FirewallProfileDict)) == {"name", "enabled"}
|
||||
assert set(get_type_hints(VbsDict)) == {"status", "running"}
|
||||
|
||||
|
||||
def test_a_windows_reading_fits_the_shape():
|
||||
reading: HardeningDict = {
|
||||
**dict.fromkeys(LINUX_KEYS), # type: ignore[typeddict-item]
|
||||
"secure_boot": "on",
|
||||
"tpm": {
|
||||
"present": True,
|
||||
"enabled": True,
|
||||
"activated": True,
|
||||
"owned": True,
|
||||
"version": "2.0",
|
||||
"manufacturer": "INTC",
|
||||
},
|
||||
"disk_encryption": {
|
||||
"provider": "bitlocker",
|
||||
"installed": True,
|
||||
"volumes": [
|
||||
{
|
||||
"volume": "C:",
|
||||
"system": True,
|
||||
"protection": "on",
|
||||
"status": "fully_encrypted",
|
||||
"method": "xts_aes_128",
|
||||
}
|
||||
],
|
||||
},
|
||||
"antimalware": {
|
||||
"product": "Microsoft Defender Antivirus",
|
||||
"enabled": True,
|
||||
"real_time": True,
|
||||
"mode": "active",
|
||||
"signatures_updated": 1764547200,
|
||||
"signature_age_days": 0,
|
||||
"signature_version": "1.443.512.0",
|
||||
"tamper_protected": True,
|
||||
},
|
||||
"firewall_profiles": [{"name": "domain", "enabled": True}],
|
||||
"vbs": {"status": "running", "running": ["credential_guard", "hvci"]},
|
||||
}
|
||||
|
||||
assert set(reading) == LINUX_KEYS | POSTURE_KEYS
|
||||
Reference in new issue
Block a user