fix(auditor): report range decisions the kernel can't enforce instead of healing
A LAPI range decision (e.g. 195.178.110.0/24) inserted into an nft set without the interval flag is stored as its bare network address. The string diff saw that as one missing and one extra entry, and every heal re-added the same address, so nodes stuck in DESYNC_DETECTED with the flap guard suppressing repeat heals. Pair such ranges with their network address, report them as unenforceable_ranges with a dedicated warning, and keep them out of the drift counts and fingerprint. The reporter records unenforceable_range_count and shows DEGRADED for a node that is otherwise in sync. Desync log lines now name the missing and extra values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
57ed6cfc1c
commit
e76e957282
6 files changed
+175
-4
No files matched your search
@@ -67,6 +67,93 @@ class AuditorDecisionExtractionTests(unittest.TestCase):
|
||||
self.assertFalse(is_synced)
|
||||
self.assertEqual("metadata_drift", drift["reason"])
|
||||
|
||||
def test_reconcile_reports_range_collapsed_to_network_address_without_drift(self):
|
||||
auditor = FirewallAuditor()
|
||||
auditor.get_remote_lapi_truth = lambda: {
|
||||
"195.178.110.0/24": {"duration": "11h", "until_epoch": None},
|
||||
"1.1.1.1": {"duration": "4h", "until_epoch": None},
|
||||
}
|
||||
auditor.get_kernel_state = lambda: {"195.178.110.0": 40000, "1.1.1.1": 14000}
|
||||
|
||||
is_synced, count, drift = auditor.reconcile()
|
||||
|
||||
self.assertTrue(is_synced)
|
||||
self.assertEqual(2, count)
|
||||
self.assertEqual("in_sync", drift["reason"])
|
||||
self.assertEqual(["195.178.110.0/24"], drift["unenforceable_ranges"])
|
||||
|
||||
def test_reconcile_keeps_real_drift_alongside_collapsed_range(self):
|
||||
auditor = FirewallAuditor()
|
||||
auditor.get_remote_lapi_truth = lambda: {
|
||||
"195.178.110.0/24": {"duration": "11h", "until_epoch": None},
|
||||
"2.2.2.2": {"duration": "4h", "until_epoch": None},
|
||||
}
|
||||
auditor.get_kernel_state = lambda: {"195.178.110.0": 40000, "9.9.9.9": 14000}
|
||||
|
||||
is_synced, _, drift = auditor.reconcile()
|
||||
|
||||
self.assertFalse(is_synced)
|
||||
self.assertEqual("membership_mismatch", drift["reason"])
|
||||
self.assertEqual(1, drift["missing_count"])
|
||||
self.assertEqual(1, drift["extra_count"])
|
||||
self.assertEqual(
|
||||
auditor._fingerprint_drift(["2.2.2.2"], ["9.9.9.9"], []),
|
||||
drift["fingerprint"],
|
||||
)
|
||||
self.assertEqual(["195.178.110.0/24"], drift["unenforceable_ranges"])
|
||||
|
||||
def test_reconcile_matches_range_whose_network_address_is_also_banned(self):
|
||||
auditor = FirewallAuditor()
|
||||
auditor.get_remote_lapi_truth = lambda: {
|
||||
"10.0.0.0/24": {"duration": "4h", "until_epoch": None},
|
||||
"10.0.0.0": {"duration": "4h", "until_epoch": None},
|
||||
}
|
||||
auditor.get_kernel_state = lambda: {"10.0.0.0": 14000}
|
||||
|
||||
is_synced, _, drift = auditor.reconcile()
|
||||
|
||||
self.assertTrue(is_synced)
|
||||
self.assertEqual(["10.0.0.0/24"], drift["unenforceable_ranges"])
|
||||
|
||||
def test_reconcile_treats_full_length_prefix_stored_as_address_as_in_sync(self):
|
||||
auditor = FirewallAuditor()
|
||||
auditor.get_remote_lapi_truth = lambda: {
|
||||
"1.2.3.4/32": {"duration": "4h", "until_epoch": None},
|
||||
"2001:db8::1/128": {"duration": "4h", "until_epoch": None},
|
||||
}
|
||||
auditor.get_kernel_state = lambda: {"1.2.3.4": 14000, "2001:db8::1": 14000}
|
||||
|
||||
is_synced, _, drift = auditor.reconcile()
|
||||
|
||||
self.assertTrue(is_synced)
|
||||
self.assertEqual([], drift["unenforceable_ranges"])
|
||||
|
||||
def test_reconcile_logs_missing_and_extra_values(self):
|
||||
auditor = FirewallAuditor()
|
||||
auditor.get_remote_lapi_truth = lambda: {
|
||||
"2.2.2.2": {"duration": "4h", "until_epoch": None}
|
||||
}
|
||||
auditor.get_kernel_state = lambda: {"9.9.9.9": 14000}
|
||||
|
||||
with self.assertLogs(level="WARNING") as logs:
|
||||
auditor.reconcile()
|
||||
|
||||
self.assertTrue(
|
||||
any(
|
||||
"missing_values=[2.2.2.2]" in line and "extra_values=[9.9.9.9]" in line
|
||||
for line in logs.output
|
||||
)
|
||||
)
|
||||
|
||||
def test_preview_values_truncates_long_lists(self):
|
||||
auditor = FirewallAuditor()
|
||||
values = [f"10.0.0.{i}" for i in range(12)]
|
||||
|
||||
self.assertEqual(
|
||||
"[" + ",".join(values[:10]) + ",+2 more]",
|
||||
auditor._preview_values(values),
|
||||
)
|
||||
|
||||
def test_parse_duration_supports_compound_values(self):
|
||||
auditor = FirewallAuditor()
|
||||
self.assertEqual(5400, auditor.parse_duration("1h30m"))
|
||||
|
||||
Reference in new issue
Block a user