672e821738f5aa00bba1b7d5f43daef95f2d75cf
Threat Engine Agent (Triton Edition)
A self-healing synchronization agent designed to ensure the local nftables kernel state perfectly matches the CrowdSec Local API (LAPI) desired state.
🎯 Purpose
The standard crowdsec-firewall-bouncer can occasionally experience "ghost" desynchronization where the LAPI removes a ban, but the kernel retains it (or vice-versa). This agent acts as a high-integrity supervisor to:
- Audit: Compare LAPI "Truth" vs. Nftables "Reality" every 5 minutes.
- Heal: Automatically restart remediation services if a desync is detected.
- Filter: Handle protocol mismatches (filtering IPv6 noise) and expired "zombie" decisions.
🛠️ Technical Architecture
The Auditor (auditor.py)
- Deep-Harvest Parser: Recursively scans the
cscliAlert-style JSON. This bypasses schema variations where IPs might be hidden insource,decisions, ormetablocks. - Protocol Filtering: Automatically ignores IPv6 addresses (detected by
:) to prevent insertion errors in IPv4-onlynfttables. - Global Table Scan: Rather than checking a single set, it scans the entire
ip crowdsectable. This ensures that IPs placed in different "drawers" (like Range sets) are still accounted for. - Temporal Awareness: Filters out decisions with negative durations (
startswith('-')) to ignore bans that are technically expired but not yet vacuumed from the database.
The Service
- Root-Level Execution: Necessary for direct interaction with
nftablesand thecsclilocal socket. - Dependency Management: Configured to start only after
crowdsec.serviceis initialized to prevent false-positive desyncs on boot.
📂 Project Structure
threat-engine-agent/
├── main.py # Logic loop and orchestration
├── auditor.py # The "Brain": Recursive parsing and kernel scanning
├── systemd/ # Deployment configurations
│ └── threat-agent.service
└── logs/ # Local audit history (Git ignored)
🚀 Installation & Deployment
- Environment Setup:
mkdir logs
- Systemd Integration:
sudo systemctl daemon-reload
sudo systemctl enable --now threat-agent```
3. Monitoring:
```# Watch the auditor work in real-time
tail -f logs/threat-agent.log```
## 🔍 Troubleshooting
If you see a "Heal Loop" in the logs:
1. **Manual Check**: Run `/usr/bin/cscli decisions list -a -o json` and check if the count matches `nft list table ip crowdsec`.
2. **IPv6 Ghosting**: Verify if the "Missing from Kernel" IPs are actually IPv6. The auditor should filter these, but new formats may require a regex update.
3. **Set Naming**: Ensure the bouncer hasn't created a new table name outside of the `crowdsec` namespace.
Description
Designed to ensure the LAPI and firewall are in sync with the proper decision count, and if not - restarts the bouncer automatically to restore sync.
154 KiB
0 Stars
1 Watchers
0 Forks
Languages
Python
100%