3.1 KiB
3.1 KiB
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 cycle. - Heal: Restart
crowdsec-firewall-bounceron desync to force a fresh LAPI pull. - Verify: Re-check state after healing and record success/failure telemetry.
🛠️ Technical Architecture
The Auditor (auditor.py)
- Schema-tolerant parsing: Supports both flat decision JSON and nested alert-style JSON from
cscli. - State reconciliation: Compares LAPI decision IP set against kernel IP set and computes drift as
missingandextra. - Drift fingerprinting: Generates a deterministic fingerprint for flap suppression and heal history.
- Metadata drift check: Flags long-duration decisions that are near expiry in kernel state.
- Kernel scan scope: Scans
ip crowdsecandip6 crowdsec6tables vianft -j.
The Orchestrator (agent.py)
- Runs the reconcile loop (default
600sinterval). - Triggers heal when any drift is detected.
- Applies flap suppression using drift fingerprint, not raw kernel count.
- Performs post-heal verification after a short delay (default
5s).
The Reporter (reporter.py)
- Writes local health state JSON atomically.
- Persists structured heal history, including pre/post fingerprints and heal result.
- Default state path:
/root/threat-engine-agent/threat-agent-state.json.
📂 Project Structure
threat-engine-agent/
├── agent.py # Main loop and heal orchestration
├── auditor.py # LAPI vs nft reconciliation and drift fingerprinting
├── reporter.py # Local state and heal history writer
├── config.yaml # Static config (currently not wired into runtime)
├── systemd/ # Deployment configurations
│ └── threat-agent.service
└── logs/ # Runtime logs
🚀 Installation & Deployment
- Environment Setup:
mkdir -p /root/threat-engine-agent/logs
cd /root/threat-engine-agent
- Systemd Integration:
sudo cp systemd/threat-agent.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now threat-agent
- Monitoring:
# Watch the agent in real time
tail -f /root/threat-engine-agent/logs/threat-agent.log
🔍 Troubleshooting
If you see a "Heal Loop" in the logs:
- Check decision source: Run
/usr/bin/cscli decisions list -a -o jsonand confirm output shape/contents are valid. - Check kernel state: Run
nft -j list table ip crowdsecandnft -j list table ip6 crowdsec6. - Check drift telemetry: Review
missing,extra,drift_fingerprint,heal_result, andpost_drift_fingerprintin logs/history. - Check service health:
systemctl status threat-agent crowdsec-firewall-bouncer.