fix(auditor): use longest kernel expiry for IPs in multiple sets
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>
This commit is contained in:
1 parent
9d68d1f4b4
commit
79f72512e4
2 files changed
+68
-3
No files matched your search
@@ -257,6 +257,36 @@ class AuditorDecisionExtractionTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual({"1.1.1.1": 1000.0}, kernel_state)
|
||||
|
||||
@patch("auditor.subprocess.run")
|
||||
def test_get_kernel_state_keeps_longest_expiry_for_ip_in_multiple_sets(self, run_mock):
|
||||
auditor = FirewallAuditor(targets=[("ip", "crowdsec")])
|
||||
run_mock.return_value = subprocess.CompletedProcess(
|
||||
args=[],
|
||||
returncode=0,
|
||||
stdout=json.dumps(
|
||||
{
|
||||
"nftables": [
|
||||
{
|
||||
"set": {
|
||||
"name": "crowdsec-blacklists-cscli",
|
||||
"elem": [{"elem": {"val": "1.1.1.1", "expires": 600000}}],
|
||||
}
|
||||
},
|
||||
{
|
||||
"set": {
|
||||
"name": "crowdsec-blacklists-crowdsec",
|
||||
"elem": [{"elem": {"val": "1.1.1.1", "expires": 13000}}],
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
kernel_state = auditor.get_kernel_state()
|
||||
|
||||
self.assertEqual({"1.1.1.1": 600000.0}, kernel_state)
|
||||
|
||||
@patch("auditor.subprocess.run")
|
||||
def test_get_kernel_state_falls_back_when_configured_sets_do_not_match(self, run_mock):
|
||||
auditor = FirewallAuditor(
|
||||
|
||||
Reference in new issue
Block a user