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
+53
-3
@@ -5,6 +5,7 @@ import json
|
||||
import logging
|
||||
import hashlib
|
||||
import datetime
|
||||
import ipaddress
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
except ImportError:
|
||||
@@ -389,8 +390,18 @@ class FirewallAuditor:
|
||||
|
||||
truth_set = set(truth_map.keys())
|
||||
reality_set = set(reality_map.keys())
|
||||
missing = sorted(truth_set - reality_set)
|
||||
extra = sorted(reality_set - truth_set)
|
||||
missing, extra, unenforceable_ranges = self._match_collapsed_ranges(
|
||||
sorted(truth_set - reality_set),
|
||||
reality_set,
|
||||
reality_set - truth_set,
|
||||
)
|
||||
if unenforceable_ranges:
|
||||
logging.warning(
|
||||
"Range decisions not enforced: the nft set holds only their network "
|
||||
"address (it lacks the interval flag), so a bouncer restart cannot "
|
||||
f"fix them (count={len(unenforceable_ranges)}) "
|
||||
f"ranges={self._preview_values(unenforceable_ranges)}"
|
||||
)
|
||||
|
||||
if missing or extra:
|
||||
drift = {
|
||||
@@ -399,10 +410,13 @@ class FirewallAuditor:
|
||||
"extra_count": len(extra),
|
||||
"metadata_drift_count": 0,
|
||||
"fingerprint": self._fingerprint_drift(missing, extra, []),
|
||||
"unenforceable_ranges": unenforceable_ranges,
|
||||
}
|
||||
logging.warning(
|
||||
"Desync: IP membership mismatch "
|
||||
f"(missing={drift['missing_count']}, extra={drift['extra_count']})."
|
||||
f"(missing={drift['missing_count']}, extra={drift['extra_count']}) "
|
||||
f"missing_values={self._preview_values(missing)} "
|
||||
f"extra_values={self._preview_values(extra)}"
|
||||
)
|
||||
return False, len(reality_set), drift
|
||||
|
||||
@@ -440,6 +454,7 @@ class FirewallAuditor:
|
||||
"extra_count": 0,
|
||||
"metadata_drift_count": len(metadata_drift),
|
||||
"fingerprint": self._fingerprint_drift([], [], metadata_drift),
|
||||
"unenforceable_ranges": unenforceable_ranges,
|
||||
}
|
||||
logging.warning(
|
||||
"Metadata Drift detected "
|
||||
@@ -453,9 +468,44 @@ class FirewallAuditor:
|
||||
"extra_count": 0,
|
||||
"metadata_drift_count": 0,
|
||||
"fingerprint": "",
|
||||
"unenforceable_ranges": unenforceable_ranges,
|
||||
}
|
||||
return True, len(reality_map), drift
|
||||
|
||||
def _match_collapsed_ranges(self, missing, kernel_values, extra):
|
||||
"""
|
||||
Pairs LAPI range decisions with the bare network address that a set without
|
||||
the interval flag stores in their place. A restart re-adds that same address,
|
||||
so these ranges are reported apart from drift rather than healed.
|
||||
|
||||
Returns (missing, extra, unenforceable_ranges) with the paired values removed.
|
||||
A full-length prefix (/32, /128) stored as its address is fully enforced, so
|
||||
it is dropped from missing without being reported.
|
||||
"""
|
||||
remaining_missing = []
|
||||
remaining_extra = set(extra)
|
||||
unenforceable_ranges = []
|
||||
for value in missing:
|
||||
try:
|
||||
network = ipaddress.ip_network(value, strict=False)
|
||||
except ValueError:
|
||||
remaining_missing.append(value)
|
||||
continue
|
||||
address = str(network.network_address)
|
||||
if address not in kernel_values:
|
||||
remaining_missing.append(value)
|
||||
continue
|
||||
remaining_extra.discard(address)
|
||||
if network.prefixlen < network.max_prefixlen:
|
||||
unenforceable_ranges.append(value)
|
||||
return remaining_missing, sorted(remaining_extra), unenforceable_ranges
|
||||
|
||||
def _preview_values(self, values, limit=10):
|
||||
shown = ",".join(str(v) for v in values[:limit])
|
||||
if len(values) > limit:
|
||||
shown += f",+{len(values) - limit} more"
|
||||
return f"[{shown}]"
|
||||
|
||||
def _fingerprint_drift(self, missing, extra, metadata_drift):
|
||||
payload = {
|
||||
"missing": sorted(missing),
|
||||
|
||||
Reference in new issue
Block a user