fix(healing): judge post-heal verification against the pre-heal decisions
A decision issued in the seconds between a heal and its verification is missing from the kernel until the bouncer's next poll, so verification reported the heal as failed even though it had fixed the drift it was started for. Seen on a node: a metadata heal fixed a stale TTL, a new ban arrived inside the 5 s window, and the heal was logged as failed; the next audit found the node in sync. reconcile() now records the decision values it saw (last_truth_values) and takes an optional baseline_truth. Post-heal verification passes the values the drift was found against; values whose LAPI membership changed since then are left out of the drift, logged with a count, returned as lapi_changed_values, and checked by the next regular audit. Drift on decisions that existed when the heal started still fails verification. The regular audit and the membership re-check are unchanged. Tests: baseline handling in reconcile, the verification call, and a replay of the logged sequence (failed before, success now). 78 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6cb7fae06a
commit
16338a2507
5 files changed
+161
-4
No files matched your search
+30
-1
@@ -31,6 +31,9 @@ class FirewallAuditor:
|
||||
# Per-IP evidence from the latest scan, used only for drift diagnostics.
|
||||
self._last_decisions = {}
|
||||
self._last_kernel_sources = {}
|
||||
# Decision values the latest reconcile saw in the LAPI. A heal records them as
|
||||
# the baseline its post-heal verification is judged against.
|
||||
self.last_truth_values = None
|
||||
|
||||
def log_enforcement_startup_state(self):
|
||||
target_desc = ", ".join(f"{family}:{table}" for family, table in self.targets)
|
||||
@@ -393,12 +396,23 @@ class FirewallAuditor:
|
||||
f"({family} {table} {set_name}): {stderr or e}"
|
||||
)
|
||||
|
||||
def reconcile(self):
|
||||
def reconcile(self, baseline_truth=None):
|
||||
"""
|
||||
Compares LAPI decisions (the truth) with the kernel's nft sets.
|
||||
|
||||
baseline_truth: decision values from an earlier reconcile. Values whose LAPI
|
||||
membership changed since then (added or removed) are left out of the drift:
|
||||
the bouncer applies such changes on its next poll, so a post-heal check would
|
||||
otherwise blame the heal for a decision issued after it started. They are
|
||||
returned in drift["lapi_changed_values"] and checked again by the next audit.
|
||||
"""
|
||||
truth_map = self.get_remote_lapi_truth()
|
||||
reality_map = self.get_kernel_state()
|
||||
|
||||
truth_set = set(truth_map.keys())
|
||||
reality_set = set(reality_map.keys())
|
||||
self.last_truth_values = frozenset(truth_set)
|
||||
changed = set() if baseline_truth is None else truth_set ^ set(baseline_truth)
|
||||
missing, extra, unenforceable_ranges = self._match_collapsed_ranges(
|
||||
sorted(truth_set - reality_set),
|
||||
reality_set,
|
||||
@@ -422,9 +436,20 @@ class FirewallAuditor:
|
||||
f"ranges={self._preview_values(unenforceable_ranges)}"
|
||||
)
|
||||
|
||||
lapi_changed = sorted(value for value in [*missing, *extra] if value in changed)
|
||||
if lapi_changed:
|
||||
missing = [value for value in missing if value not in changed]
|
||||
extra = [value for value in extra if value not in changed]
|
||||
logging.info(
|
||||
"Not counted as drift: LAPI decisions changed since the baseline "
|
||||
f"(count={len(lapi_changed)}); the bouncer applies them on its next poll "
|
||||
f"and the next audit checks them. values={self._preview_values(lapi_changed)}"
|
||||
)
|
||||
|
||||
if missing or extra:
|
||||
drift = {
|
||||
"reason": "membership_mismatch",
|
||||
"lapi_changed_values": lapi_changed,
|
||||
"missing_count": len(missing),
|
||||
"extra_count": len(extra),
|
||||
"metadata_drift_count": 0,
|
||||
@@ -443,6 +468,8 @@ class FirewallAuditor:
|
||||
now_epoch = datetime.datetime.now(datetime.timezone.utc).timestamp()
|
||||
|
||||
for ip, decision_meta in truth_map.items():
|
||||
if ip in changed:
|
||||
continue
|
||||
siem_seconds = self._expected_remaining_seconds(decision_meta, now_epoch)
|
||||
if siem_seconds <= 0:
|
||||
continue
|
||||
@@ -469,6 +496,7 @@ class FirewallAuditor:
|
||||
if metadata_drift:
|
||||
drift = {
|
||||
"reason": "metadata_drift",
|
||||
"lapi_changed_values": lapi_changed,
|
||||
"missing_count": 0,
|
||||
"extra_count": 0,
|
||||
"metadata_drift_count": len(metadata_drift),
|
||||
@@ -483,6 +511,7 @@ class FirewallAuditor:
|
||||
|
||||
drift = {
|
||||
"reason": "in_sync",
|
||||
"lapi_changed_values": lapi_changed,
|
||||
"missing_count": 0,
|
||||
"extra_count": 0,
|
||||
"metadata_drift_count": 0,
|
||||
|
||||
Reference in new issue
Block a user