Crowdsec Traefik Beispiel
Version vom 9. April 2025, 07:27 Uhr von Thomas.will (Diskussion | Beiträge) (→Access-Log in Traefik aktivieren)
Traefik mit CrowdSec absichern
Ziel
CrowdSec soll HTTP-Angriffe auf einen Traefik-Proxy erkennen. Dazu wird das JSON-Access-Log von Traefik per Volume-Mount an CrowdSec übergeben und ausgewertet.
Voraussetzungen
Traefik läuft im Docker-Container.
Access-Logs im JSON-Format sind aktiviert.
CrowdSec ist installiert und läuft.
Access-Log in Traefik aktivieren
- vi /mnt/docker/traefik/traefik.yaml
accessLog: filePath: "/logs/traefik-access.log" format: json
- vi /mnt/docker/traefik/docker-compose.yaml
./logs:/logs
CrowdSec vorbereiten
- cscli hub update
- cscli parsers install crowdsecurity/traefik-logs
- cscli collections install crowdsecurity/traefik
- systemctl restart crowdsec
Logquelle einbinden
- vi /etc/crowdsec/acquis.yaml
filenames: - /var/log/traefik/traefik-access.log labels: type: traefik
- systemctl restart crowdsec
Angriff simulieren
- for i in $(seq 1 100); do curl -s "http://traefik-host/scan$i" > /dev/null; done
- curl http://traefik-host/.env
- curl http://traefik-host/.git/config
- curl http://traefik-host/.htpasswd
Erkennung prüfen
- cscli alerts list
- cscli decisions list
- journalctl -u crowdsec -f
Hinweis
CrowdSec kann keine Logs aus docker logs oder journald lesen, wenn das Log im JSON-Format ist. Nur eine explizite Logdatei mit Volume-Mount funktioniert zuverlässig.
Fazit
Traefik lässt sich mit CrowdSec absichern, wenn das JSON-Access-Log korrekt in eine Datei geschrieben und über acquis.yaml eingebunden wird. Die Kombination aus Parser, Szenarien und Volume