Hi, i tried setting up crowdsec with traefik as a reverse proxy in docker. with the following docker-compose.yaml files
version: '3'
volumes:
letsencrypt: {}
traefikLogs: {}
networks:
web_public:
external: true
internal:
external: false
services:
traefik:
image: "traefik:v2.10.7"
container_name: "traefik"
command:
- "--api.dashboard=true"
- "--log.level=INFO"
- "--log.filePath=/var/logs/traefik.log"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
- "--entrypoints.web.http.redirections.entryPoint.scheme=https"
- "--entrypoints.web.http.redirections.entrypoint.permanent=true"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.genericresolver.acme.tlschallenge=true"
- "--certificatesresolvers.genericresolver.acme.email=randommail@gmail.com"
- "--certificatesresolvers.genericresolver.acme.storage=/letsencrypt/acme.json"
- "--accesslog=true"
- "--accessLog.filePath=/var/log/crowdsec/traefik.log"
- "--accessLog.bufferingSize=100" # Configuring a buffer of 100 lines
- "--accessLog.filters.statusCodes=204-299,400-499,500-59" # Status code to log
- "--entrypoints.http.http.middlewares=crowdsec-bouncer@docker"
- "--entrypoints.https.http.middlewares=crowdsec-bouncer@docker"
network_mode: host
volumes:
- "./data/letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "/var/log/crowdsec/:/var/log/crowdsec/"
environment:
- TZ=Europe/Berlin
restart: unless-stopped
crowdsec:
image: crowdsecurity/crowdsec
container_name: crowdsec
environment:
PGID: "1000"
COLLECTIONS: "crowdsecurity/traefik crowdsecurity/http-cve"
expose:
- "8080"
volumes:
- /var/log/crowdsec:/var/log/crowdsec:ro
- /opt/crowdsec-db:/var/lib/crowdsec/data
- /var/log/auth.log:/var/log/auth.log:ro
- /opt/crowdsec:/etc/crowdsec
restart: unless-stopped
networks:
- web_public
- internal
## Bouncer service
crowdsec-traefik-bouncer:
image: fbonalair/traefik-crowdsec-bouncer
container_name: bouncer-traefik
environment:
CROWDSEC_BOUNCER_API_KEY: 122345678/ABCDEF/09876543
CROWDSEC_AGENT_HOST: crowdsec:8080
GIN_MODE: release
expose:
- "8080"
depends_on:
- crowdsec
restart: unless-stopped
networks:
- web_public
- internal
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.crowdsec-bouncer.forwardauth.address=http://bouncer-traefik:8080/api/v1/forwardAuth"
- "traefik.http.middlewares.crowdsec-bouncer.forwardauth.trustForwardHeader=true"
- "traefik.http.services.crowdsec-bouncer.loadbalancer.server.port=8080"
version: '3.9'
networks:
web_public:
external: true
internal:
external: false
services:
whoami:
image: traefik/whoami
command:
- --name=POM
networks:
- web_public
- internal
restart: unless-stopped
ports:
- 8223:80
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.testdomain.com`)"
- "traefik.http.routers.whoami.entrypoints=websecure"
- "traefik.http.routers.whoami.tls.certresolver=genericresolver"
- "traefik.docker.network=web_public"
- "traefik.http.services.whoami.loadbalancer.server.port=80"
# Bouncer Middleware
- "traefik.http.middlewares.crowdsec-bouncer.forwardauth.address=http://bouncer-traefik:8080/api/v1/forwardAuth"
- "traefik.http.middlewares.crowdsec-bouncer.forwardauth.trustForwardHeader=true"
- traefik.http.routers.whoami.middlewares=crowdsec-bouncer@docker
At first i was using the traefik Container in non-Host-Mode. The bouncer worked fine, but apparently there are (known) problems with the real source IP. The bouncer sees everything coming from the traefik containers IP address.
Now when switching the Traefik Container to Host Mode, calling the whoami page returns an empty page. All other hosted sites running over Traefik work perfectly fine, just adding the bouncer destroys it. The returned status of the webpage is "500"