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
@@ -543,5 +543,74 @@ class AuditorDecisionExtractionTests(unittest.TestCase):
|
||||
warning_mock.assert_not_called()
|
||||
|
||||
|
||||
class ReconcileBaselineTests(unittest.TestCase):
|
||||
"""Post-heal verification is judged against the decisions the heal started from."""
|
||||
|
||||
LONG = {"duration": "4h", "until_epoch": None}
|
||||
|
||||
def _auditor(self, truth, kernel):
|
||||
auditor = FirewallAuditor()
|
||||
auditor.get_remote_lapi_truth = lambda: {value: dict(self.LONG) for value in truth}
|
||||
auditor.get_kernel_state = lambda: {value: 14000 for value in kernel}
|
||||
return auditor
|
||||
|
||||
def test_reconcile_records_the_truth_values_it_saw(self):
|
||||
auditor = self._auditor(["192.0.2.1", "192.0.2.2"], ["192.0.2.1", "192.0.2.2"])
|
||||
|
||||
auditor.reconcile()
|
||||
|
||||
self.assertEqual(frozenset({"192.0.2.1", "192.0.2.2"}), auditor.last_truth_values)
|
||||
|
||||
def test_without_baseline_a_new_decision_not_yet_applied_is_drift(self):
|
||||
auditor = self._auditor(["192.0.2.1", "198.51.100.7"], ["192.0.2.1"])
|
||||
|
||||
is_synced, _, drift = auditor.reconcile()
|
||||
|
||||
self.assertFalse(is_synced)
|
||||
self.assertEqual("membership_mismatch", drift["reason"])
|
||||
self.assertEqual(1, drift["missing_count"])
|
||||
self.assertEqual([], drift["lapi_changed_values"])
|
||||
|
||||
def test_decision_added_since_baseline_is_not_drift(self):
|
||||
auditor = self._auditor(["192.0.2.1", "198.51.100.7"], ["192.0.2.1"])
|
||||
|
||||
is_synced, _, drift = auditor.reconcile(baseline_truth={"192.0.2.1"})
|
||||
|
||||
self.assertTrue(is_synced)
|
||||
self.assertEqual("in_sync", drift["reason"])
|
||||
self.assertEqual(0, drift["missing_count"])
|
||||
self.assertEqual(["198.51.100.7"], drift["lapi_changed_values"])
|
||||
|
||||
def test_decision_removed_since_baseline_is_not_drift(self):
|
||||
auditor = self._auditor(["192.0.2.1"], ["192.0.2.1", "198.51.100.8"])
|
||||
|
||||
is_synced, _, drift = auditor.reconcile(baseline_truth={"192.0.2.1", "198.51.100.8"})
|
||||
|
||||
self.assertTrue(is_synced)
|
||||
self.assertEqual(0, drift["extra_count"])
|
||||
self.assertEqual(["198.51.100.8"], drift["lapi_changed_values"])
|
||||
|
||||
def test_drift_on_decisions_present_at_baseline_still_counts(self):
|
||||
auditor = self._auditor(["192.0.2.1", "192.0.2.2", "198.51.100.7"], ["192.0.2.1"])
|
||||
|
||||
is_synced, _, drift = auditor.reconcile(baseline_truth={"192.0.2.1", "192.0.2.2"})
|
||||
|
||||
self.assertFalse(is_synced)
|
||||
self.assertEqual("membership_mismatch", drift["reason"])
|
||||
self.assertEqual(1, drift["missing_count"])
|
||||
self.assertEqual(["198.51.100.7"], drift["lapi_changed_values"])
|
||||
self.assertEqual(auditor._fingerprint_drift(["192.0.2.2"], [], []), drift["fingerprint"])
|
||||
|
||||
def test_metadata_check_skips_decisions_changed_since_baseline(self):
|
||||
auditor = FirewallAuditor()
|
||||
auditor.get_remote_lapi_truth = lambda: {"198.51.100.7": {"duration": "24h", "until_epoch": None}}
|
||||
auditor.get_kernel_state = lambda: {"198.51.100.7": 3 * 3600 * 1000}
|
||||
|
||||
is_synced, _, drift = auditor.reconcile(baseline_truth=set())
|
||||
|
||||
self.assertTrue(is_synced)
|
||||
self.assertEqual(0, drift["metadata_drift_count"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user