feat(hardening): how a Linux host is hardened, as one read-only reading (NetOrk/netork#2706)

HardeningMixin.get_hardening() reads, with one fixed command: the active
security modules, SELinux's mode and its configured mode, AppArmor's switch
and (as root) its profiles per mode, the crypto policy and FIPS mode, the
kernel's text for each CPU vulnerability, mitigations= and nosmt from the
command line, and the distribution's IDs. Read as root first, as the login
user where root is refused. What was not read is None, never off.
This commit is contained in:
christianmanivong committed 2026-11-26 23:11:57 +01:00
1 parent 5985c87cc8
commit 3cd0e3621a
5 files changed
+713

No files matched your search

+11
View File
@@ -160,6 +160,17 @@ everywhere, so the command and its parse are concrete here and a driver supplies
`_run_kernel_facts_command`. `OSDriver` does not carry it — a Windows host is an OS driver
too, and `hasattr(driver, "get_kernel_facts")` has to stay truthful.
`HardeningMixin` (`get_hardening`) is mixed in the same way: how the host is hardened, as
its kernel and its own tools say it, in one read-only command. The active security modules
(`/sys/kernel/security/lsm`), SELinux's mode (`getenforce`) and the mode it boots in
(`/etc/selinux/config`), AppArmor's switch and its profiles per mode (`aa-status --json`,
the one part that needs root), the crypto policy (`update-crypto-policies --show`) and FIPS
mode, the kernel's answer for each CPU vulnerability (`/sys/devices/system/cpu/vulnerabilities`,
put in one word by `cpu_vulnerability_state`), `mitigations=` and `nosmt` from the kernel
command line, and `ID`/`ID_LIKE` from `/etc/os-release`. 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".
`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
shipping the binary its `ExecStart` runs, by `dpkg -S` or `rpm -qf`, not the libraries