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).
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).
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.
_selinux_configured, _selinux_running and _selinux_seen, each on its own, so
_selinux stays within napalm-standard's complexity limit. The parse is
unchanged.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
HardeningMixin.get_hardening()(new modulehardening), for NetOrk/netork#2706 (decided A + B):/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).update-crypto-policies --showand FIPS mode (/proc/sys/crypto/fips_enabled)./sys/devices/system/cpu/vulnerabilities, as the kernel's text;cpu_vulnerability_state()puts it in one word (not_affected,mitigated,vulnerable,unknown).mitigations=(autowhen not given, as in the kernel; the last one wins) andnosmt.ID/ID_LIKEfrom/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
ListeningSocketsMixinpattern). Not read isNone, 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 withmitigations=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).