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
@@ -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