chore(release): 0.9.0 #50

Merged
christianmanivong merged 3 commits from chore/release-0.9.0 into main 2026-11-26 12:26:05 +00:00
4 changed files with 182 additions and 5 deletions

No files matched your search

+10
View File
@@ -7,6 +7,16 @@ recorded here; their history is the git log.
## [Unreleased]
## [0.9.0] - 2026-11-26
### Added
- An active-only Zabbix agent closes the port netOrk opened for it on an earlier passive run
(`_revoke_zabbix_agent_sources`, napalm-device-types `ZabbixAgentMixin`,
NetOrk/netork#2693): the firewall step deletes the rule netOrk wrote -- the named section
`allow_zabbix_agent` or `allow_zabbix_agent_from_<zone>` -- from the configuration and
reloads the firewall where one runs. A rule written in LuCI has an anonymous `cfgXXXX` key
and stays; the rules for the port left in place are named.
## [0.8.0] - 2026-11-17
### Changed
+80 -2
View File
@@ -20,7 +20,8 @@ Zabbix publishes no repository for OpenWrt, so the feed is the only source.
The package index lives in RAM and is gone after every restart; the template loads
it first (``refresh_available_updates``). The firewall step opens tcp/``listen_port``
in the zone that owns the management address, the way the SNMP agent's step opens
udp/161 -- and only where a firewall runs: an access point often runs none.
udp/161 -- and only where a firewall runs: an access point often runs none. For an
active-only agent it deletes that rule again, by its key (NetOrk/netork#2693).
"""
from __future__ import annotations
@@ -50,6 +51,15 @@ _FIREWALL_RUNS = (
)
#: The key of the rule ``_allow_zabbix_agent_sources`` writes, unscoped or per zone.
_RULE_KEY = "allow_zabbix_agent"
def _netork_rule(key: str) -> bool:
"""Whether the firewall section *key* is the rule netOrk writes for the agent."""
return key == _RULE_KEY or key.startswith(f"{_RULE_KEY}_from_")
def _failed(result: CommandResult, what: str) -> FixStepOutcomeDict:
detail = (result.stderr or result.stdout or "").strip()[-300:]
return {"ok": False, "output": f"{what}: {detail or result.exit_code}"}
@@ -92,7 +102,7 @@ class OpenWrtZabbixAgentMixin(ZabbixAgentMixin):
if self._send_command(_FIREWALL_RUNS).strip() != "on":
return {"ok": True, "output": "no firewall runs; nothing to open"}
outcome = self._allow_in_management_zone(
key="allow_zabbix_agent",
key=_RULE_KEY,
name="Allow-Zabbix-Agent",
proto="tcp",
port=int(settings["listen_port"]),
@@ -101,6 +111,66 @@ class OpenWrtZabbixAgentMixin(ZabbixAgentMixin):
)
return {"ok": bool(outcome["ok"]), "output": str(outcome["output"])}
def _revoke_zabbix_agent_sources(self, settings: ZabbixAgentSettingsDict) -> FixStepOutcomeDict:
"""For an active-only agent: delete the rules netOrk wrote for the agent on an
earlier passive run, and nothing else (NetOrk/netork#2693).
netOrk's are the named sections ``allow_zabbix_agent`` and
``allow_zabbix_agent_from_<zone>`` (``_allow_zabbix_agent_sources``); a rule
written in LuCI gets an anonymous ``cfgXXXX`` key. Other rules for the port stay
and are named. The firewall reloads where one runs.
"""
port = int(settings["listen_port"])
mine, others = self._agent_rules(port)
lines: list[str] = []
ok = True
if mine:
removed = self._delete_rules(mine)
if not removed["ok"]:
return removed
lines.append(str(removed["output"]))
ok = self._reload_if_running(lines)
else:
lines.append("netOrk wrote no rule for the agent; nothing removed")
if others:
lines.append(
f"{len(others)} rule(s) for tcp/{port} that netOrk did not write are left in"
f" place: {', '.join(others)}"
)
return {"ok": ok, "output": "; ".join(lines)}
def _agent_rules(self, port: int) -> tuple[list[str], list[str]]:
"""The rule sections netOrk wrote for the agent, and the others for *port*."""
sections = self._parse_uci_sections(self._send_command("uci show firewall 2>/dev/null"))
rules = {key: opts for key, opts in sections.items() if opts.get("_type") == "rule"}
mine = sorted(key for key in rules if _netork_rule(key))
others = sorted(
key
for key, opts in rules.items()
if key not in mine and self._uci_scalar(opts.get("dest_port", "")) == str(port)
)
return mine, others
def _delete_rules(self, keys: list[str]) -> FixStepOutcomeDict:
deletes = "; ".join(f"uci -q delete firewall.{key}" for key in keys)
done = self._rc_step(f"{deletes}; uci commit firewall", "")
if not done["ok"]:
return {"ok": False, "output": str(done["output"])}
return {
"ok": True,
"output": f"removed the rule(s) netOrk wrote for the agent: {', '.join(keys)}",
}
def _reload_if_running(self, lines: list[str]) -> bool:
"""Reload the firewall where one runs; False where it refused the ruleset."""
if self._send_command(_FIREWALL_RUNS).strip() != "on":
return True
reload_out = self._send_command(
"fw4 reload 2>&1 || /etc/init.d/firewall reload 2>&1"
).strip()
lines.append(f"reload: {reload_out or 'ok'}")
return not self._fw_reload_failed(reload_out)
if TYPE_CHECKING: # pragma: no cover - the driver's
def run_command(
@@ -117,3 +187,11 @@ class OpenWrtZabbixAgentMixin(ZabbixAgentMixin):
def _allow_in_management_zone(
self, *, key: str, name: str, proto: str, port: int, sources: list[str], word: str
) -> dict[str, Any]: ...
def _parse_uci_sections(self, raw: str) -> dict[str, dict[str, str]]: ...
def _uci_scalar(self, value: str) -> str: ...
def _rc_step(self, command: str, done: str) -> dict[str, Any]: ...
def _fw_reload_failed(self, output: str) -> bool: ...
+2 -2
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "napalm-openwrt"
version = "0.8.0"
version = "0.9.0"
description = "NAPALM driver for OpenWrt routers/access-points"
readme = "README.md"
license = "Apache-2.0"
@@ -21,7 +21,7 @@ classifiers = [
]
dependencies = [
"napalm>=5.1", # older releases import pkg_resources, which a 3.12 venv lacks
"napalm_device_types>=4.41.0", # FirmwareUpgradeMixin
"napalm_device_types>=4.43.0", # ZabbixAgentMixin._revoke_zabbix_agent_sources
"netmiko>=4.0.0",
"paramiko>=5.0.0", # CVE-2026-44405
"netaddr>=0.7.19", # IPAddress; below it the package has none (CI lowest job)
+90 -1
View File
@@ -34,6 +34,8 @@ class _Shell:
self.installed = installed
self.nft_hits = nft_hits
self.issued: list[str] = []
self.firewall = UCI_FIREWALL_HEALTHY
self.reload = ""
def __call__(self, cmd, **kw):
self.issued.append(cmd)
@@ -54,7 +56,9 @@ class _Shell:
self.installed = True
return "ok\n__OWRT_RC=0"
if cmd.startswith("uci show firewall"):
return UCI_FIREWALL_HEALTHY
return self.firewall
if cmd.startswith("fw4 reload"):
return self.reload
if cmd.startswith("uci show network"):
return UCI_NETWORK_STATIC
if "$SSH_CONNECTION" in cmd:
@@ -234,3 +238,88 @@ class _SnmpShell:
self.shell.issued.append(cmd)
return "1"
return self.shell(cmd, **kw)
# --- Active only: closing the rule netOrk wrote (NetOrk/netork#2693) ----------------
ACTIVE_ONLY = {**SETTINGS, "active_only": True, "allowed_sources": []}
NETORK_RULES = """\
firewall.allow_zabbix_agent_from_lan=rule
firewall.allow_zabbix_agent_from_lan.name='Allow-Zabbix-Agent'
firewall.allow_zabbix_agent_from_lan.proto='tcp'
firewall.allow_zabbix_agent_from_lan.dest_port='10050'
firewall.allow_zabbix_agent_from_lan.src='lan'
firewall.allow_zabbix_agent=rule
firewall.allow_zabbix_agent.name='Allow-Zabbix-Agent'
firewall.allow_zabbix_agent.dest_port='10051'
"""
OPERATOR_RULE = """\
firewall.cfg0e92bd=rule
firewall.cfg0e92bd.name='zabbix from the monitoring VLAN'
firewall.cfg0e92bd.proto='tcp'
firewall.cfg0e92bd.dest_port='10050'
firewall.allow_zabbix_agent_backup=rule
firewall.allow_zabbix_agent_backup.dest_port='10050'
"""
def _deletes(shell) -> list[str]:
return [c for c in shell.issued if "uci -q delete firewall." in c]
def test_active_only_removes_the_rules_netork_wrote_and_reloads(owrt, shell):
shell.firewall = UCI_FIREWALL_HEALTHY + NETORK_RULES
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
assert result["success"] is True, result["output"]
deletes = " ".join(_deletes(shell))
assert "uci -q delete firewall.allow_zabbix_agent_from_lan" in deletes
assert "uci -q delete firewall.allow_zabbix_agent;" in deletes + ";"
assert "uci commit firewall" in deletes
assert any(c.startswith("fw4 reload") for c in shell.issued)
assert "allow_zabbix_agent_from_lan" in result["steps"][2]["output"]
assert not any("uci set firewall.allow_zabbix_agent" in c for c in shell.issued)
def test_rules_the_operator_wrote_stay_and_are_reported(owrt, shell):
shell.firewall = UCI_FIREWALL_HEALTHY + NETORK_RULES + OPERATOR_RULE
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
deletes = " ".join(_deletes(shell))
assert "cfg0e92bd" not in deletes
assert "allow_zabbix_agent_backup" not in deletes
firewall = result["steps"][2]["output"]
assert "2 rule(s) for tcp/10050" in firewall
assert "cfg0e92bd" in firewall
def test_without_a_rule_netork_wrote_nothing_changes(owrt, shell):
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
assert result["success"] is True
assert _deletes(shell) == []
assert not any(c.startswith("fw4 reload") for c in shell.issued)
assert "netOrk wrote no rule" in result["steps"][2]["output"]
def test_without_a_running_firewall_the_rule_still_goes_from_the_configuration(owrt, shell):
shell.firewall = UCI_FIREWALL_HEALTHY + NETORK_RULES
shell.firewall_runs = False
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
assert result["success"] is True
assert _deletes(shell)
assert not any(c.startswith("fw4 reload") for c in shell.issued)
def test_a_reload_the_firewall_refuses_fails(owrt, shell):
shell.firewall = UCI_FIREWALL_HEALTHY + NETORK_RULES
shell.reload = "Section @rule[3] is not a valid rule"
result = owrt.configure_zabbix_agent(ACTIVE_ONLY)
assert result["success"] is False
assert result["steps"][-1]["step"] == "firewall"