1. Traefik plugins #
Adding middlewares and providers.
How it works #
Traefik plugins are written in Go and run by the built-in Yaegi interpreter: no need to recompile Traefik. They are published in the Plugin Catalog and declared in the static configuration, then used like middlewares.
# configuration statique
experimental:
plugins:
crowdsec:
moduleName: github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin
version: v1.3.5 # fixez une version testéeCommon mistake: A plugin runs inside the Traefik process: choose maintained plugins, pin their version and test them before production.
2. CrowdSec #
Collaborative detection.
Architecture #
- Traefik writes its access logs to a shared file.
- The CrowdSec agent analyzes them with scenarios (brute force, scans, exploitation of known vulnerabilities) and sends alerts.
- The local API creates decisions (ban an IP for 4 h) and also receives the lists shared by the community.
- The bouncer plugin queries the local API and responds 403 to banned IPs.
3. Setup with Docker Compose #
The essential elements.
Configuration #
services:
crowdsec:
image: crowdsecurity/crowdsec
environment:
COLLECTIONS: "crowdsecurity/traefik crowdsecurity/http-cve"
volumes:
- ./acquis.yaml:/etc/crowdsec/acquis.yaml:ro
- traefik-logs:/var/log/traefik:ro
traefik:
image: traefik:v3
command:
- --accesslog.filepath=/var/log/traefik/access.log
- --experimental.plugins.crowdsec.modulename=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin
- --experimental.plugins.crowdsec.version=v1.3.5
volumes: [traefik-logs:/var/log/traefik]
# middleware dynamique : crowdsecLapiKey = clé créée par « cscli bouncers add traefik »docker compose exec crowdsec cscli bouncers add traefik # clé pour le plugin
docker compose exec crowdsec cscli metrics # lignes lues, scénarios déclenchés
docker compose exec crowdsec cscli decisions list # IP bloquées
docker compose exec crowdsec cscli decisions add --ip 203.0.113.7 --duration 1h # testGood practice: Add your own addresses (monitoring, offices) to a CrowdSec allow list so you never block yourself.
