fix(auditor): don't heal when the LAPI is unreachable
CI / Unit tests (push) Successful in 4s
CI / Unit tests (pull_request) Successful in 3s

get_remote_lapi_truth() returned {} when 'cscli decisions list' failed, which is
indistinguishable from "no active bans". reconcile() then saw every kernel ban as extra,
reported membership_mismatch, and the heal restarted crowdsec-firewall-bouncer. A LAPI
outage would do that on every node at once, every heal interval.

Raise LapiUnavailableError instead. reconcile() propagates it, so the main loop records
it as last_error and retries in 60s without healing; post-heal verification records it
as verify_error. A genuinely empty decision list still returns {} as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-21 16:47:48 -04:00
1 parent cb2a88917c
commit 8c8be8ec63
2 files changed
+32 -3

No files matched your search

+9 -2
View File
@@ -11,6 +11,10 @@ except ImportError:
def load_dotenv():
return None
class LapiUnavailableError(RuntimeError):
"""The LAPI could not be queried, so there is no decision truth to compare against."""
class FirewallAuditor:
def __init__(self, targets=None, managed_sets=None):
"""Ensures the NFT kernel state matches the LAPI's desired state."""
@@ -98,8 +102,11 @@ class FirewallAuditor:
logging.info(f"LAPI Local Parser: Found {len(truth_map)} active bans.")
return truth_map
except Exception as e:
logging.error(f"Failed to get LAPI truth: {e}")
return {}
# Raise rather than return {}: an empty truth map would make every kernel ban
# look like drift and trigger a bouncer restart whenever the LAPI is down.
detail = (getattr(e, "stderr", None) or "").strip() or str(e)
logging.error(f"Failed to get LAPI truth: {detail}")
raise LapiUnavailableError(f"LAPI unreachable: {detail}") from e
def _normalize_truth_decision(self, decision):
return {