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

Merged
christianmanivong merged 4 commits from feature/hardening-reading into main 2026-11-28 01:44:02 +00:00
Owner

HardeningMixin.get_hardening() (new module hardening), for NetOrk/netork#2706 (decided A + B):

  • Security modules: /sys/kernel/security/lsm; SELinux's mode (getenforce, else /sys/fs/selinux/enforce) and its configured mode (SELINUX= in /etc/selinux/config); AppArmor's switch (/sys/module/apparmor/parameters/enabled, else the LSM list) and, as root, its profiles per mode (aa-status --json).
  • Crypto policy: update-crypto-policies --show and FIPS mode (/proc/sys/crypto/fips_enabled).
  • CPU vulnerabilities: each file under /sys/devices/system/cpu/vulnerabilities, as the kernel's text; cpu_vulnerability_state() puts it in one word (not_affected, mitigated, vulnerable, unknown).
  • Kernel command line: mitigations= (auto when not given, as in the kernel; the last one wins) and nosmt.
  • ID/ID_LIKE from /etc/os-release, so a consumer can tell an Enterprise Linux host.

One fixed, read-only command, framed like the other readings. Read as root first; where root is refused, as the login user, without the profile counts (the ListeningSocketsMixin pattern). Not read is None, never off or empty. A driver supplies _run_hardening_command(command, *, privileged).

Version 4.48.0: 4.47.0 is taken by the open #135.

Tested: tests/test_hardening.py (fixtures for AlmaLinux 9 with SELinux enforcing and DEFAULT, Ubuntu 24.04 with AppArmor, Debian 12 with mitigations=off, the not-read cases, the mixin's root fallback, the command run on a real host). Full suite green locally (1972 passed), ruff and mypy clean.

napalm-linux carries it in NAPALM/napalm-linux (branch feature/hardening-reading, 0.20.0).

`HardeningMixin.get_hardening()` (new module `hardening`), for NetOrk/netork#2706 (decided A + B): - **Security modules:** `/sys/kernel/security/lsm`; SELinux's mode (`getenforce`, else `/sys/fs/selinux/enforce`) and its configured mode (`SELINUX=` in `/etc/selinux/config`); AppArmor's switch (`/sys/module/apparmor/parameters/enabled`, else the LSM list) and, as root, its profiles per mode (`aa-status --json`). - **Crypto policy:** `update-crypto-policies --show` and FIPS mode (`/proc/sys/crypto/fips_enabled`). - **CPU vulnerabilities:** each file under `/sys/devices/system/cpu/vulnerabilities`, as the kernel's text; `cpu_vulnerability_state()` puts it in one word (`not_affected`, `mitigated`, `vulnerable`, `unknown`). - **Kernel command line:** `mitigations=` (`auto` when not given, as in the kernel; the last one wins) and `nosmt`. - `ID`/`ID_LIKE` from `/etc/os-release`, so a consumer can tell an Enterprise Linux host. One fixed, read-only command, framed like the other readings. Read as root first; where root is refused, as the login user, without the profile counts (the `ListeningSocketsMixin` pattern). **Not read is `None`, never off or empty.** A driver supplies `_run_hardening_command(command, *, privileged)`. Version **4.48.0**: 4.47.0 is taken by the open #135. Tested: `tests/test_hardening.py` (fixtures for AlmaLinux 9 with SELinux enforcing and DEFAULT, Ubuntu 24.04 with AppArmor, Debian 12 with `mitigations=off`, the not-read cases, the mixin's root fallback, the command run on a real host). Full suite green locally (1972 passed), ruff and mypy clean. napalm-linux carries it in NAPALM/napalm-linux (branch `feature/hardening-reading`, 0.20.0).
christianmanivong added 2 commits 2026-11-26 22:13:57 +00:00
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.
chore(release): 4.48.0
driver / standard (pull_request) Failing after 16s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 56s
driver / test (3.12) (pull_request) Successful in 1m16s
driver / test (3.13) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 40s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Failing after 2m48s
driver / publish (pull_request) Skipped
e440bee9e1
christianmanivong added 1 commit 2026-11-27 00:45:12 +00:00
refactor(hardening): the SELinux part as three small questions (NetOrk/netork#2706)
driver / lint (pull_request) Successful in 17s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m1s
driver / test (3.13) (pull_request) Successful in 1m12s
driver / test (3.12) (pull_request) Successful in 1m19s
driver / lowest (pull_request) Successful in 39s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Successful in 2m31s
driver / publish (pull_request) Skipped
594cc5e486
_selinux_configured, _selinux_running and _selinux_seen, each on its own, so
_selinux stays within napalm-standard's complexity limit. The parse is
unchanged.
christianmanivong added 1 commit 2026-11-27 04:52:45 +00:00
Merge NAPALM/napalm-device-types main (4.47.0) into feature/hardening-reading
driver / standard (pull_request) Successful in 30s
driver / lint (pull_request) Successful in 59s
driver / types (pull_request) Successful in 2m12s
driver / test (3.12) (pull_request) Successful in 2m16s
driver / lowest (pull_request) Successful in 39s
driver / test (3.13) (pull_request) Successful in 1m26s
driver / build (pull_request) Successful in 39s
driver / security (pull_request) Successful in 1m18s
CI / driver (pull_request) Successful in 5m3s
driver / publish (pull_request) Skipped
c93ceeb320
4.47.0 (#135) is released; this branch stays 4.48.0, its changelog section
above 4.47.0's.
christianmanivong merged commit 419d3ee0e0 into main 2026-11-28 01:44:02 +00:00
christianmanivong deleted branch feature/hardening-reading 2026-11-28 01:44:02 +00:00
Sign in to join this conversation.