feat: read the PVE firewall, the node's loaded ruleset, and the hardening reading (NetOrk/netork#2654, #2776) #80
No files matched your search
@@ -19,6 +19,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- `get_host_firewall()` on the PVE driver (napalm-device-types' `HostFirewallMixin`): what the
|
- `get_host_firewall()` on the PVE driver (napalm-device-types' `HostFirewallMixin`): what the
|
||||||
node has loaded -- proxmox-firewall's nftables tables on PVE 9, pve-firewall's iptables chains
|
node has loaded -- proxmox-firewall's nftables tables on PVE 9, pve-firewall's iptables chains
|
||||||
before -- read as root over SSH, as for any Linux host.
|
before -- read as root over SSH, as for any Linux host.
|
||||||
|
- `get_hardening()` on both drivers (napalm-device-types' `HardeningMixin`, NetOrk/netork#2776):
|
||||||
|
the security modules, SELinux and AppArmor, the crypto policy and FIPS mode, what the kernel
|
||||||
|
reports for each CPU vulnerability, and the kernel command line (`mitigations=`, `nosmt`). One
|
||||||
|
fixed, read-only command over the exec path, which is root's login, so AppArmor's profiles per
|
||||||
|
mode are read too. A hypervisor's guests share its CPU, so its CPU vulnerabilities matter most.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Needs napalm-device-types 4.48.0 or later (`HardeningMixin`).
|
||||||
|
|
||||||
## [0.16.0] - 2026-11-26
|
## [0.16.0] - 2026-11-26
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ device = driver(
|
|||||||
| `get_services_need_restart` | the services that still run code an update replaced on disk, as root over SSH (napalm-device-types' `ServicesRestartMixin`): `needrestart` in list-only mode where it is installed, else the processes whose `/proc/<pid>/maps` maps deleted code. A running VM's QEMU is a process (`processes`), an LXC container's processes are left out (the container updates itself). Only as root: another SSH login gets no reading, rather than a clean one |
|
| `get_services_need_restart` | the services that still run code an update replaced on disk, as root over SSH (napalm-device-types' `ServicesRestartMixin`): `needrestart` in list-only mode where it is installed, else the processes whose `/proc/<pid>/maps` maps deleted code. A running VM's QEMU is a process (`processes`), an LXC container's processes are left out (the container updates itself). Only as root: another SSH login gets no reading, rather than a clean one |
|
||||||
| `get_pve_firewall` | the PVE firewall as the operator wrote it, read only (NetOrk/netork#2654): the datacenter's `options`, `rules`, security `groups` (name → rules), `ipsets` (name → `[{cidr, nomatch, comment}]`) and `aliases` (name → cidr), this node's `options` and `rules`, and every guest's on this node (`vmid`, `type`, `name`, `options`, `rules`, and `nics`: `[{name, firewall}]` from `netN … firewall=1`). Each rule keeps PVE's fields and its `origin` (`cluster`, `group`, `node`, `guest`). A part PVE refuses is `null`, never empty |
|
| `get_pve_firewall` | the PVE firewall as the operator wrote it, read only (NetOrk/netork#2654): the datacenter's `options`, `rules`, security `groups` (name → rules), `ipsets` (name → `[{cidr, nomatch, comment}]`) and `aliases` (name → cidr), this node's `options` and `rules`, and every guest's on this node (`vmid`, `type`, `name`, `options`, `rules`, and `nics`: `[{name, firewall}]` from `netN … firewall=1`). Each rule keeps PVE's fields and its `origin` (`cluster`, `group`, `node`, `guest`). A part PVE refuses is `null`, never empty |
|
||||||
| `get_host_firewall` | what the node has loaded, as for any Linux host (napalm-device-types' `HostFirewallMixin`): `nft list ruleset` (PVE 9's proxmox-firewall) or `iptables-save` (pve-firewall), as root over SSH |
|
| `get_host_firewall` | what the node has loaded, as for any Linux host (napalm-device-types' `HostFirewallMixin`): `nft list ruleset` (PVE 9's proxmox-firewall) or `iptables-save` (pve-firewall), as root over SSH |
|
||||||
|
| `get_hardening` | how the node is hardened (napalm-device-types' `HardeningMixin`, NetOrk/netork#2776): security modules, SELinux and AppArmor, crypto policy, FIPS mode, CPU vulnerabilities, kernel command line, as root over SSH. On the backup server too |
|
||||||
|
|
||||||
**Not implemented** (raise `NotImplementedError`):
|
**Not implemented** (raise `NotImplementedError`):
|
||||||
`get_bgp_config`, `get_bgp_neighbors`, `get_bgp_neighbors_detail`,
|
`get_bgp_config`, `get_bgp_neighbors`, `get_bgp_neighbors_detail`,
|
||||||
@@ -255,6 +256,7 @@ tests/
|
|||||||
├── test_time_sync.py # get_time_sync / configure_time_sync on both drivers
|
├── test_time_sync.py # get_time_sync / configure_time_sync on both drivers
|
||||||
├── test_certificates.py # get_certificates on both drivers
|
├── test_certificates.py # get_certificates on both drivers
|
||||||
├── test_firewall.py # get_pve_firewall and get_host_firewall
|
├── test_firewall.py # get_pve_firewall and get_host_firewall
|
||||||
|
├── test_hardening.py # get_hardening on both drivers
|
||||||
├── test_utils.py # Unit tests for napalm_proxmox.utils
|
├── test_utils.py # Unit tests for napalm_proxmox.utils
|
||||||
├── fixtures/pbs_api.json # What a Proxmox Backup Server 4.2 answered (sanitised)
|
├── fixtures/pbs_api.json # What a Proxmox Backup Server 4.2 answered (sanitised)
|
||||||
├── pbs_fake.py # A proxmoxer stand-in answering from that recording
|
├── pbs_fake.py # A proxmoxer stand-in answering from that recording
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from napalm_device_types import (
|
|||||||
BackupServerDriver,
|
BackupServerDriver,
|
||||||
EnsurePackageMixin,
|
EnsurePackageMixin,
|
||||||
FingerprintRule,
|
FingerprintRule,
|
||||||
|
HardeningMixin,
|
||||||
HostStatusMixin,
|
HostStatusMixin,
|
||||||
KernelFactsMixin,
|
KernelFactsMixin,
|
||||||
LicenseMixin,
|
LicenseMixin,
|
||||||
@@ -65,6 +66,7 @@ class ProxmoxBackupDriver(
|
|||||||
BackupServerDriver,
|
BackupServerDriver,
|
||||||
StorageDriver,
|
StorageDriver,
|
||||||
KernelFactsMixin,
|
KernelFactsMixin,
|
||||||
|
HardeningMixin,
|
||||||
ServicePackagesMixin,
|
ServicePackagesMixin,
|
||||||
ListeningSocketsMixin,
|
ListeningSocketsMixin,
|
||||||
LogSourcesMixin,
|
LogSourcesMixin,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ from napalm_device_types import (
|
|||||||
AptProxyMixin,
|
AptProxyMixin,
|
||||||
EnsurePackageMixin,
|
EnsurePackageMixin,
|
||||||
FingerprintRule,
|
FingerprintRule,
|
||||||
|
HardeningMixin,
|
||||||
HostFirewallMixin,
|
HostFirewallMixin,
|
||||||
HostStatusMixin,
|
HostStatusMixin,
|
||||||
HypervisorDriver,
|
HypervisorDriver,
|
||||||
@@ -103,6 +104,7 @@ class ProxmoxDriver(
|
|||||||
ProxmoxFirewallMixin,
|
ProxmoxFirewallMixin,
|
||||||
KernelFactsMixin,
|
KernelFactsMixin,
|
||||||
HostFirewallMixin,
|
HostFirewallMixin,
|
||||||
|
HardeningMixin,
|
||||||
ServicePackagesMixin,
|
ServicePackagesMixin,
|
||||||
ListeningSocketsMixin,
|
ListeningSocketsMixin,
|
||||||
LogSourcesMixin,
|
LogSourcesMixin,
|
||||||
|
|||||||
@@ -72,6 +72,12 @@ class ProxmoxHostMixin:
|
|||||||
"""The transport for ``KernelFactsMixin.get_kernel_facts``: the exec path."""
|
"""The transport for ``KernelFactsMixin.get_kernel_facts``: the exec path."""
|
||||||
return self._exec_ssh_command(command)
|
return self._exec_ssh_command(command)
|
||||||
|
|
||||||
|
def _run_hardening_command(self, command: str, *, privileged: bool) -> str:
|
||||||
|
"""The transport for ``HardeningMixin.get_hardening`` (NetOrk/netork#2776): the exec
|
||||||
|
path, which is root's login, so AppArmor's profiles per mode are read too. Another
|
||||||
|
login reads the rest without them, as napalm-device-types' fallback does. No stdin."""
|
||||||
|
return str(self._exec_ssh_command(command))
|
||||||
|
|
||||||
def _run_host_firewall_command(self, command: str, *, privileged: bool) -> str:
|
def _run_host_firewall_command(self, command: str, *, privileged: bool) -> str:
|
||||||
"""The transport for ``HostFirewallMixin.get_host_firewall``: the exec path, which
|
"""The transport for ``HostFirewallMixin.get_host_firewall``: the exec path, which
|
||||||
runs as root either way. What the node has loaded -- proxmox-firewall's nftables
|
runs as root either way. What the node has loaded -- proxmox-firewall's nftables
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ classifiers = [
|
|||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"napalm>=5.0.0",
|
"napalm>=5.0.0",
|
||||||
"napalm_device_types>=4.46.0", # ServicesRestartMixin with LXC left out; CredentialExpiryMixin
|
"napalm_device_types>=4.48.0", # HardeningMixin; ServicesRestartMixin with LXC left out
|
||||||
"paramiko>=5.0.0", # CVE-2026-44405; imported directly for the node's SSH session (_base.py)
|
"paramiko>=5.0.0", # CVE-2026-44405; imported directly for the node's SSH session (_base.py)
|
||||||
"proxmoxer>=2.0.0",
|
"proxmoxer>=2.0.0",
|
||||||
"netaddr>=0.9.0",
|
"netaddr>=0.9.0",
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
"""`get_hardening`: how the node is hardened (NetOrk/netork#2776).
|
||||||
|
|
||||||
|
A hypervisor is where CPU vulnerabilities matter most: its guests share the CPU.
|
||||||
|
The command and its parse are napalm-device-types' (``HardeningMixin``); both
|
||||||
|
drivers carry the command over their own exec path, which is root's login, so
|
||||||
|
AppArmor's profiles per mode are read as well.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from napalm_device_types import HardeningMixin
|
||||||
|
|
||||||
|
from napalm_proxmox.backup_driver import ProxmoxBackupDriver
|
||||||
|
from napalm_proxmox.driver import ProxmoxDriver
|
||||||
|
|
||||||
|
WIRE = "\n".join(
|
||||||
|
[
|
||||||
|
"HARDENING_BEGIN",
|
||||||
|
"[lsm]",
|
||||||
|
"lockdown,capability,landlock,yama,apparmor,bpf",
|
||||||
|
"[cmdline]",
|
||||||
|
"BOOT_IMAGE=/boot/vmlinuz-6.8.12-4-pve root=/dev/mapper/pve-root ro mitigations=off",
|
||||||
|
"[fips]",
|
||||||
|
"0",
|
||||||
|
"[apparmor_enabled]",
|
||||||
|
"Y",
|
||||||
|
"[os]",
|
||||||
|
"ID=debian",
|
||||||
|
"[cpu_vulnerabilities]",
|
||||||
|
"/sys/devices/system/cpu/vulnerabilities/mds:Vulnerable; SMT vulnerable",
|
||||||
|
"/sys/devices/system/cpu/vulnerabilities/meltdown:Not affected",
|
||||||
|
"HARDENING_END",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("cls", [ProxmoxDriver, ProxmoxBackupDriver])
|
||||||
|
def test_both_drivers_declare_the_contract(cls):
|
||||||
|
assert issubclass(cls, HardeningMixin)
|
||||||
|
assert hasattr(cls, "get_hardening")
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_node_runs_the_shared_command_over_its_exec_path(driver):
|
||||||
|
with patch.object(driver, "_exec_ssh_command", return_value=WIRE) as exec_:
|
||||||
|
reading = driver.get_hardening()
|
||||||
|
|
||||||
|
exec_.assert_called_once()
|
||||||
|
assert "HARDENING_" in exec_.call_args.args[0]
|
||||||
|
assert reading["lsm"] == ["lockdown", "capability", "landlock", "yama", "apparmor", "bpf"]
|
||||||
|
assert reading["mitigations"] == "off"
|
||||||
|
assert reading["cpu_vulnerabilities"]["mds"] == "Vulnerable; SMT vulnerable"
|
||||||
|
assert reading["os_ids"] == ["debian"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_backup_server_reads_it_the_same_way():
|
||||||
|
drv = ProxmoxBackupDriver("192.0.2.80", "root", "", optional_args={"token_name": "a!b"})
|
||||||
|
|
||||||
|
with patch.object(drv, "_exec_ssh_command", return_value=WIRE):
|
||||||
|
reading = drv.get_hardening()
|
||||||
|
|
||||||
|
assert reading["cpu_vulnerabilities"]["meltdown"] == "Not affected"
|
||||||
|
|
||||||
|
|
||||||
|
def test_output_without_a_report_raises(driver):
|
||||||
|
with patch.object(driver, "_exec_ssh_command", return_value=""):
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
driver.get_hardening()
|
||||||
Reference in new issue
Block a user