A http service to verify requests and bounce them according to decisions made by CrowdSec. Fork of https://github.com/fbonalair/traefik-crowdsec-bouncer


Supported Architectures
Our images support multiple architectures such as x86-64, arm64 and armhf.
Simply pulling ghcr.io/thespad/traefik-crowdsec-bouncer should retrieve the correct image for your arch.
The architectures supported by this image are:
| Architecture |
Available |
Tag |
| x86-64 |
✅ |
latest |
| arm64 |
✅ |
latest |
| armhf |
✅ |
latest |
Prerequisites
- Docker and Docker-compose installed.
- Traefik v2.x
- CrowdSec running natively or in a container and configured to read logs from Traefik
Application Setup
- Get a bouncer API key from CrowdSec with command
docker exec crowdsec cscli bouncers add bouncer-traefik
- Copy the API key printed. You WON'T be able the get it again.
- Paste this API key as the value for bouncer environment variable
CROWDSEC_BOUNCER_API_KEY, or use an .env file.
- Set the other environment variables as required (see below for details).
- Start bouncer.
- Visit a site proxied by Traefik and confirm you can access it.
- In another console, ban your IP with command
docker exec crowdsec cscli decisions add --ip <your ip> -R "Test Ban", modify the IP with your address.
- Visit the site again, in your browser you will see "Forbidden" since this time since you've been banned.
- Unban yourself with
docker exec crowdsec cscli decisions delete --ip <your IP>
- Visit the site one last time, you will have access to the site again.
Parameters
The webservice configuration is made via environment variables:
CROWDSEC_BOUNCER_API_KEY - CrowdSec bouncer API key required to be authorized to request local API (required)
CROWDSEC_AGENT_HOST - Host and port of CrowdSec agent, i.e. crowdsec-agent:8080 (required)
CROWDSEC_BOUNCER_SCHEME - Scheme to query CrowdSec agent. Expected value: http, https. Default to http
CROWDSEC_BOUNCER_LOG_LEVEL - Minimum log level for bouncer. Expected value zerolog levels. Default to 1
CROWDSEC_BOUNCER_SKIPRFC1918 - Don't send RCF1918 (Private) IP addresses to the LAPI to check ban status. Expected value: "true", "false" . Default to "true"
CROWDSEC_BOUNCER_REDIRECT - Optionally redirect instead of giving 403 Forbidden. Accepts relative or absolute URLs but must not be protected by the bouncer or you'll get a redirect loop. Default to null
PORT - Change listening port of web server. Default listen on 8080
GIN_MODE - By default, run app in "debug" mode. Set it to "release" in production
TRUSTED_PROXIES - Can accept a list of IP addresses in CIDR format, delimited by ','. Default is 0.0.0.0/0
Exposed routes
The webservice exposes some routes:
- GET
/api/v1/forwardAuth - Main route to be used by Traefik: query CrowdSec agent with the header X-Real-Ip as client IP`
- GET
/api/v1/ping - Simple health route that respond pong with http 200`
- GET
/api/v1/healthz - Another health route that query CrowdSec agent with localhost (127.0.0.1)`
- GET
/api/v1/metrics - Prometheus route to scrap metrics
Support Info
- Shell access whilst the container is running:
docker exec -it traefik-crowdsec-bouncer /bin/bash
- To monitor the logs of the container in realtime:
docker logs -f traefik-crowdsec-bouncer
Image Update Notifications - Diun (Docker Image Update Notifier)
- We recommend Diun for update notifications. Other tools that automatically update containers unattended are not recommended or supported.
Building locally
If you want to make local modifications to these images for development purposes or just to customize the logic:
git clone https://github.com/thespad/traefik-crowdsec-bouncer.git
cd traefik-crowdsec-bouncer
docker build \
--no-cache \
--pull \
-t ghcr.io/thespad/traefik-crowdsec-bouncer:latest .
Versions
- 15.02.22: - Initial Release.