Enhance Traefik configuration to include CrowdSec plugin and update comments for clarity

This commit is contained in:
Mohmmed Elfateh Sabry
2025-08-11 00:52:32 +03:00
parent dc452403b5
commit fe90ceed2e

View File

@@ -29,7 +29,7 @@ volumes:
services: services:
## ───────────────────────────────────────────── ## ─────────────────────────────────────────────
## Traefik — edge router + ACME (HTTP-01) ## Traefik — edge router + ACME (HTTP-01) + CrowdSec plugin
## ───────────────────────────────────────────── ## ─────────────────────────────────────────────
traefik: traefik:
image: traefik:v3.1 image: traefik:v3.1
@@ -55,12 +55,13 @@ services:
# Dashboard/API (internal) # Dashboard/API (internal)
- --api.dashboard=true - --api.dashboard=true
# ACME via HTTP-01 # ACME via HTTP-01 (no registrar API needed)
- --certificatesresolvers.le.acme.email=${ACME_EMAIL} - --certificatesresolvers.le.acme.email=${ACME_EMAIL}
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json - --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
- --certificatesresolvers.le.acme.httpchallenge=true - --certificatesresolvers.le.acme.httpchallenge=true
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=web - --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
# (Alt) Use TLS-ALPN-01 if port 80 is blocked:
# - --certificatesresolvers.le.acme.tlschallenge=true
# Metrics (Prometheus) # Metrics (Prometheus)
- --metrics.prometheus=true - --metrics.prometheus=true
@@ -70,6 +71,10 @@ services:
- --accesslog.filepath=/var/log/traefik/access.log - --accesslog.filepath=/var/log/traefik/access.log
- --accesslog.bufferingsize=100 - --accesslog.bufferingsize=100
- --log.level=INFO - --log.level=INFO
# CrowdSec Traefik plugin (recommended vs sidecar)
- --experimental.plugins.crowdsecbouncer.moduleName=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin
- --experimental.plugins.crowdsecbouncer.version=v1.4.4
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro - /var/run/docker.sock:/var/run/docker.sock:ro
- traefik_letsencrypt:/letsencrypt - traefik_letsencrypt:/letsencrypt
@@ -91,9 +96,11 @@ services:
- traefik.http.middlewares.authelia.forwardauth.trustForwardHeader=true - traefik.http.middlewares.authelia.forwardauth.trustForwardHeader=true
- traefik.http.middlewares.authelia.forwardauth.authResponseHeaders=Remote-User,Remote-Groups,Remote-Name,Remote-Email - traefik.http.middlewares.authelia.forwardauth.authResponseHeaders=Remote-User,Remote-Groups,Remote-Name,Remote-Email
# CrowdSec forward-auth (reusable) # CrowdSec plugin middleware (reusable)
- traefik.http.middlewares.crowdsec.forwardauth.address=http://traefik-bouncer:8080/api/v1/forwardAuth - traefik.http.middlewares.crowdsec.plugin.crowdsecbouncer.enabled=true
- traefik.http.middlewares.crowdsec.forwardauth.trustForwardHeader=true - traefik.http.middlewares.crowdsec.plugin.crowdsecbouncer.crowdseclapiurl=http://crowdsec:8080/
- traefik.http.middlewares.crowdsec.plugin.crowdsecbouncer.crowdseclapikey=${CROWDSEC_BOUNCER_KEY}
- traefik.http.middlewares.crowdsec.plugin.crowdsecbouncer.crowdsecmode=stream
# Traefik dashboard (protected) # Traefik dashboard (protected)
- traefik.http.routers.traefik.rule=Host(`traefik.gate.${DOMAIN}`) - traefik.http.routers.traefik.rule=Host(`traefik.gate.${DOMAIN}`)
@@ -167,7 +174,6 @@ services:
environment: environment:
TZ: "${TZ}" TZ: "${TZ}"
volumes: volumes:
# Provide your config at ./authelia/configuration.yml
- ./authelia/configuration.yml:/config/configuration.yml:ro - ./authelia/configuration.yml:/config/configuration.yml:ro
- authelia_data:/config - authelia_data:/config
networks: [traefik_proxy, internal] networks: [traefik_proxy, internal]
@@ -186,7 +192,7 @@ services:
networks: [internal] networks: [internal]
## ───────────────────────────────────────────── ## ─────────────────────────────────────────────
## CrowdSec (LAPI) + Traefik bouncer (forwardAuth) ## CrowdSec (LAPI) — with Traefik plugin
## ───────────────────────────────────────────── ## ─────────────────────────────────────────────
crowdsec: crowdsec:
image: crowdsecurity/crowdsec:latest image: crowdsecurity/crowdsec:latest
@@ -202,7 +208,7 @@ services:
- traefik_logs:/var/log/traefik:ro - traefik_logs:/var/log/traefik:ro
networks: [traefik_proxy] networks: [traefik_proxy]
# Auto-register the bouncer once (uses CROWDSEC_BOUNCER_KEY from .env) # Auto-register the API key used by the Traefik plugin
crowdsec-init: crowdsec-init:
image: crowdsecurity/crowdsec:latest image: crowdsecurity/crowdsec:latest
container_name: crowdsec-init container_name: crowdsec-init
@@ -211,17 +217,6 @@ services:
networks: [traefik_proxy] networks: [traefik_proxy]
restart: "no" restart: "no"
traefik-bouncer:
image: crowdsecurity/traefik-bouncer:latest
container_name: traefik-bouncer
restart: unless-stopped
depends_on: [crowdsec, crowdsec-init]
environment:
CROWDSEC_BOUNCER_API_KEY: "${CROWDSEC_BOUNCER_KEY}"
CROWDSEC_AGENT_HOST: crowdsec:8080
GIN_MODE: release
networks: [traefik_proxy]
## ───────────────────────────────────────────── ## ─────────────────────────────────────────────
## Uptime Kuma — status page / checks ## Uptime Kuma — status page / checks
## ───────────────────────────────────────────── ## ─────────────────────────────────────────────