Traefik Bouncer
The aim here is to implement a CrowdSec bouncer for the router Traefik to block malicious IPs to access your services. For this, it leverages Traefik v2 ForwardAuth middleware and queries CrowdSec with client IP.
If the client IP is on the ban list, it will get an HTTP code 403 response. Otherwise, the request will continue as usual.
Flow of information

What is a parser?
Parsers take log formats and break them down into readable information for the CrowdSec app. We will be using the Traefik parser to take the Traefik access logs and pass that information over to the CrowdSec app to make decisions.
What is a bouncer?
Bouncers react to decisions made by CrowdSec. In this case, the Traefik bouncer will take the decision made by CrowdSec and either allow or deny the traffic going through Traefik. CrowdSec on its own will just make the decisions to ban IPs. It will do this by connecting back to the mothership to get the information required to make the decisions locally. Check out available bouncers on the hub
Check out available bouncers on the hub
What is a Scenario?
A scenario is a behavior, i.e. is it a brute force attack that is happening. You can choose which Scenarios you would like to check the traffic against. In this Traefik collection, we will be using the typical http behaviors.
Enable the Bouncer
Go inside the CrowdSec Docker console and run
Go to the apps tab, and download the container crowdsec-traefik-bouncer.
Get the API Key that we generated above and past it on this option
leave it as it is
Put the CrowdSec Container IP with port
Traefik
Enable Logging
Edit your traefik static configuration file (traefik.yml) in your traefik appdata folder. (use nano command or code server, very useful, tutorial here https://www.youtube.com/watch?v=7FMCBjUVaYQ&t=1s )
If your logs don't show the external IP of the users hitting the Traefik proxy and only show the IP of the docker gateway (eg.: 172.19.x.x in this case) then edit the traefik.yml file and your docker gateway IP under trusted IPs.
Create a path mapping in your traefik template, so that the log file is written in the shared folder previously created.
Add the CrowdSec Middleware
Once again, edit your traefik static configuration file (traefik.yml), then edit your dynamic configuration file (fileConfig.yml)
Restart CrowdSec and Traefik
Last updated
Was this helpful?