crowdsec-firewall-bouncer's nftables mode strips the prefix from Range
decisions and bans only the network address, so a /24 decision blocked
a single IP. With ranges.enabled, every audit now syncs range decisions
into a dedicated `inet crowdsec-ranges` table (interval+timeout sets with
input/forward drop chains) in one atomic `nft -f` transaction, then reads
it back to confirm each range is enforced.
- element timeouts track each decision's remaining lifetime; stale
elements are removed and extended decisions refreshed
- ranges nested in another active range are covered, not inserted
- ranges broader than min_prefix_v4/v6 (default /16, /32) are refused
- ranges still missing after the sync stay in unenforceable_ranges, so
the node reports DEGRADED rather than HEALTHY
- the bouncer-set scan normalizes nft prefix elements to addr/len
instead of failing the table scan on them
- doctor checks the range table; the audit log line says when a synced
node is degraded
Disabled by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
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>
A drift whose fingerprint matches a heal from the last heal_min_interval
seconds was counted as a drift event but never as a heal attempt, so the
24h counters showed a drift with no heal and no failure. Decide on the
heal before recording the check and report heals_suppressed_24h and
heals_suppressed_total, so every drift event is either a heal attempt
or a suppressed heal. The suppression warning now names the earlier
heal that did not hold.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A decision created moments before an audit shows up as missing=1 until
the bouncer's next poll, which triggered a bouncer restart for nothing.
When the audit finds a membership mismatch, wait membership_recheck_delay
seconds (default 30, 0 disables) and audit again; only drift that is still
present is reported and healed. Metadata drift is not delayed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bouncer keeps one nft set per decision origin, so an IP with both a
crowdsec ban and a later, longer cscli ban sits in two sets. The kernel
scan kept whichever set it read last, so the short TTL could be compared
against the longest LAPI decision and reported as metadata drift.
Keep the longest expiry per IP instead, and log per-IP evidence (expected
vs kernel seconds, source sets, LAPI decisions) whenever drift is flagged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- add tail-based HEAL line lookup to avoid O(file-size) reads in should_heal()
- keep a safe fallback full scan when no HEAL marker is found in tail window
- add regression test for large history files with recent HEAL marker
Add drift-aware heal path in FirewallAuditor to remediate metadata drift by discovering and flushing
*-cscli sets in crowdsec/crowdsec6 tables, then restarting the bouncer.
Update execute_heal_and_verify to pass drift context to heal_with_drift when supported, keeping
backward compatibility via heal().
Add unit tests covering metadata-drift flush+restart behavior, non-metadata restart-only behavior,
and drift context propagation.