Give the backup unit network access so its heartbeat ping can leave
CI / tests (Python 3.11) (pull_request) Successful in 28s
CI / tests (Python 3.10) (pull_request) Successful in 29s
CI / tests (Python 3.12) (pull_request) Successful in 25s
CI / tests (Python 3.13) (pull_request) Successful in 26s
CI / lint (pull_request) Successful in 2s

kernelwatch-backup.service still had PrivateNetwork=yes and
RestrictAddressFamilies=AF_UNIX from before scheduled-backup pinged
backup_heartbeat_url. Every nightly ping failed DNS inside the sandbox
("heartbeat request failed (URLError)"); the backup itself succeeded, so
the only symptom was the heartbeat monitor going down after a day.

Allow AF_INET/AF_INET6 like the alerts unit, and add a test that every
unit running a command that sends requests (check-alerts,
scheduled-backup, notify-backup-failure) keeps network access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-31 14:58:51 -04:00
1 parent 669f1dc545
commit f9d9660f71
3 files changed
+31 -2

No files matched your search

+24
View File
@@ -329,6 +329,30 @@ class ServerInstallTest(InstallCase):
for command in commands:
self.assertRegex(help_text, rf"\b{re.escape(command)}\b")
def test_units_that_send_requests_have_network_access(self):
"""These commands ping a heartbeat or send to ntfy. A unit that runs one with its
network sandboxed away fails only in a log line (the request fails, the run
doesn't), so the heartbeat monitor just goes quiet."""
outbound = {"check-alerts", "scheduled-backup", "notify-backup-failure"}
checked = set()
for unit in os.listdir(SERVER_DIR):
if not unit.endswith(".service"):
continue
text = read(os.path.join(SERVER_DIR, unit))
if not outbound & set(re.findall(r"kernelwatch-server (\S+)$", text, re.M)):
continue
checked.add(unit)
with self.subTest(unit=unit):
self.assertNotRegex(text, r"(?m)^PrivateNetwork=(yes|true|1|on)$")
self.assertNotRegex(text, r"(?m)^IPAddressDeny=")
families = re.findall(r"(?m)^RestrictAddressFamilies=(.*)$", text)
self.assertTrue(families, "set RestrictAddressFamilies= explicitly")
for line in families:
self.assertFalse(line.startswith("~"))
self.assertTrue({"AF_INET", "AF_INET6"} <= set(line.split()), line)
self.assertEqual(checked, {"kernelwatch-alerts.service", "kernelwatch-backup.service",
"kernelwatch-backup-failed.service"})
def test_on_failure_targets_are_shipped_units(self):
"""A typo'd OnFailure= is silently ignored by systemd, so check the names."""
units = {n for n in os.listdir(SERVER_DIR) if n.endswith((".service", ".timer"))}