Tier 0: render what the services already decided, honestly

Claude-Session: https://claude.ai/code/session_01Ms2FbjQy31TVf3CEvQhGM8
This commit is contained in:
Gabriel Brown
2026-08-25 00:24:30 -04:00
parent be0e55214b
commit 8b1205e4b8
38 changed files with 1474 additions and 260 deletions
+12 -5
View File
@@ -15,7 +15,7 @@ Changes go through firewall-cmd, which is polkit-aware, so they prompt.
panama-firewall snapshot
panama-firewall zone-info ZONE
panama-firewall add-service NAME | remove-service NAME
panama-firewall add-port PORT/PROTO | remove-port PORT/PROTO
panama-firewall add-port PORT/PROTO... | remove-port PORT/PROTO...
panama-firewall set-zone INTERFACE ZONE
panama-firewall set-default-zone ZONE
"""
@@ -401,10 +401,17 @@ def main(arguments: list[str]) -> int:
name = require(SERVICE, arguments[1], "That is not a service name.")
verb = "--add-service" if arguments[0] == "add-service" else "--remove-service"
change(active_zone(), f"{verb}={name}")
elif len(arguments) == 2 and arguments[0] in ("add-port", "remove-port"):
spec = require(PORT_SPEC, arguments[1], "That is not a port.")
elif len(arguments) >= 2 and arguments[0] in ("add-port", "remove-port"):
# Several specs in one invocation, because one rule as a user sees
# it is often two as firewalld stores it: the range Fedora opens is
# a tcp range AND a udp range, and "close the range" that closed
# only the tcp half would be a lie the page had already told.
# Validated all-or-nothing first, so a bad spec at the end cannot
# leave the firewall half-changed.
specs = [require(PORT_SPEC, argument, "That is not a port.")
for argument in arguments[1:]]
verb = "--add-port" if arguments[0] == "add-port" else "--remove-port"
change(active_zone(), f"{verb}={spec}")
change(active_zone(), *[f"{verb}={spec}" for spec in specs])
elif len(arguments) == 3 and arguments[0] == "set-zone":
interface = require(INTERFACE, arguments[1], "That is not a network interface.")
zone = require(ZONE, arguments[2], "That is not a zone.")
@@ -416,7 +423,7 @@ def main(arguments: list[str]) -> int:
else:
raise BoundaryError(
"Usage: panama-firewall snapshot | zone-info ZONE | add-service NAME | "
"remove-service NAME | add-port PORT/PROTO | remove-port PORT/PROTO | "
"remove-service NAME | add-port PORT/PROTO... | remove-port PORT/PROTO... | "
"set-zone INTERFACE ZONE | set-default-zone ZONE")
except BoundaryError as error:
try: