Crowdsec Traefik Beispiel: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „==== Traefik mit CrowdSec absichern ==== ;Ziel CrowdSec soll HTTP-Angriffe auf Traefik erkennen. Die Logdatei im JSON-Format wird direkt analysiert. ==== Vor…“) |
|||
| Zeile 1: | Zeile 1: | ||
| − | + | =Traefik mit CrowdSec absichern= | |
| − | + | ==Ziel== | |
| − | CrowdSec soll HTTP-Angriffe auf Traefik erkennen. | + | 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. | Traefik läuft im Docker-Container. | ||
| − | + | Access-Logs im JSON-Format sind aktiviert. | |
| − | + | CrowdSec ist installiert und läuft. | |
| − | Traefik | + | ==Access-Log in Traefik aktivieren== |
| + | *vi /etc/traefik/traefik.yml | ||
accessLog: | accessLog: | ||
filePath: "/logs/traefik-access.log" | filePath: "/logs/traefik-access.log" | ||
format: json | format: json | ||
| + | Container mit Volume-Mount starten: | ||
| − | * | + | *-v /var/log/traefik:/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 | ||
Version vom 9. April 2025, 07:21 Uhr
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 /etc/traefik/traefik.yml
accessLog: filePath: "/logs/traefik-access.log" format: json
Container mit Volume-Mount starten:
- -v /var/log/traefik:/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