Crowdsec in docker with traefik v3 problem

Hello, I've got crowdsec in docker setup with traefik using the bouncer, but I don't think it's working, everything in the logs seems ok but to test it I added my local IP to the decsions list and tried to access my nginx-test container I have running, but it still lets me get through to nginx test page and doesn't block my local ip, I would like someone to help me it would be greatly appereciated thanks
157 Replies
CrowdSec
CrowdSec7d ago
Important Information
Thank you for getting in touch with your support request. To expedite a swift resolution, could you kindly provide the following information? Rest assured, we will respond promptly, and we greatly appreciate your patience. While you wait, please check the links below to see if this issue has been previously addressed. If you have managed to resolve it, please use run the command /resolve or press the green resolve button below.
Log Files
If you possess any log files that you believe could be beneficial, please include them at this time. By default, CrowdSec logs to /var/log/, where you will discover a corresponding log file for each component.
Guide Followed (CrowdSec Official)
If you have diligently followed one of our guides and hit a roadblock, please share the guide with us. This will help us assess if any adjustments are necessary to assist you further.
Screenshots
Please forward any screenshots depicting errors you encounter. Your visuals will provide us with a clear view of the issues you are facing.
© Created By WhyAydan for CrowdSec ❤️
jhmc93
jhmc93OP6d ago
can someone help me with this
Loz
Loz6d ago
@jhmc93 feel free to post your configs here so doesnt get lost, redact any PII you dont want to share.
jhmc93
jhmc93OP6d ago
traefik-crowdsec docker compose file
jhmc93
jhmc93OP6d ago
traefik config and yaml files
Loz
Loz6d ago
so you have traefik-secure (from labels) and secured in yaml in middlewares but I dont see how these overlap each other? so doesnt seem you are applying the middlewares to your https entrypoint probably best to spin up the traefik dashboard to see if they are applied edit: also you only want to use, WAF I dontt know if the plugin allows you to do waf only mode unless you change the mode configuration
jhmc93
jhmc93OP6d ago
I do have it spun up, I can take a screenshot of the middlewares section if that helps?
Loz
Loz6d ago
CrowdsecMode

string
default: live, expected values are: none, live, stream, alone, appsec
CrowdsecMode

string
default: live, expected values are: none, live, stream, alone, appsec
you need to set mode to appsec for waf to work standalone
jhmc93
jhmc93OP6d ago
How do I set the mode to waf
Loz
Loz6d ago
You provide crowdsecMode in the yaml configuration but this means no IP based blocking will be enabled just the WAF https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/blob/50beb4294fbd72ef6b6c3720fcc571e1e86ab38e/pkg/configuration/configuration.go#L48
Wobak
Wobak6d ago
also I don't see where you're applying the middleware I see where you defined it, but not where it's applied
jhmc93
jhmc93OP6d ago
In what yaml? Here's the screenshot of my middlewares
jhmc93
jhmc93OP6d ago
Here
No description
Loz
Loz6d ago
yeah that registered, but if you click on http router do you see it applied? it will tell you which middlewares are applied to the http routers
Wobak
Wobak6d ago
Also I see the http middleware definition, but not the plugin integration in the traefik.yaml ? or am I misreading this?
Loz
Loz6d ago
example
No description
jhmc93
jhmc93OP6d ago
this nginx i span up should have the crowdsec middleware but it doesnt
No description
Loz
Loz6d ago
yeah that because you registered the plugin but didnt apply it since your using a mixture of labels and yaml file it going to get complex
Wobak
Wobak6d ago
you can define it at each router level or directly on the entrypoint
Loz
Loz6d ago
jhmc93
jhmc93OP6d ago
No description
jhmc93
jhmc93OP6d ago
this is the labels ive setup for nginx
Wobak
Wobak6d ago
yeah you created the plugin config but you didn't apply the middleware
Loz
Loz6d ago
but your naming that middleware to be the same name as the global one
Wobak
Wobak6d ago
traefik.http.routers.nginx.middlewares=crowdsec
Loz
Loz6d ago
applying the labels just creates the plugins it doesnt apply by default the simplist is following the guide I linked and applying to your entrypoint
jhmc93
jhmc93OP6d ago
so if i place this "traefik.http.routers.nginx.middlewares=crowdsec" in my labels it should work?
Wobak
Wobak6d ago
it might yes, or at least we should see it appear in the middlewares section and see what the error looks like
jhmc93
jhmc93OP6d ago
No description
jhmc93
jhmc93OP6d ago
as u said an error how do I solve this then?, also is there a way to simplify it so I don't have to keep using the labels for the bouncer constantly @Wobak @Loz
Wobak
Wobak6d ago
so let me recap : you have 4 elements : 1/ crowdsec installation and listening on 7422 (seems OK in your case) 2/ you need the traefik.yml config to include the definition of the bouncer plugin : (https://plugins.traefik.io/plugins/6335346ca4caa9ddeffda116/crowdsec-bouncer-traefik-plugin, see "Install plugin button" there are 2 parts to this) 3/ Then you define the middleware (in a yml file or as labels) 4/ then you apply the middleware (either on labels in a router like you're doing, or directly to your entrypoint if you want it setup everywhere) I think your issue is in point 2 in the link I'm giving to setup the plugin, you'll see they name it "crowdsec-bouncer-traefik-plugin", and then you define the middleware with a name that refers to this to send it configuration values in my case to use "bouncer" I did this in my traefik.yaml :
experimental:
plugins:
bouncer:
moduleName: github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin
version: v1.4.6 # To update
experimental:
plugins:
bouncer:
moduleName: github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin
version: v1.4.6 # To update
jhmc93
jhmc93OP6d ago
so i do the same in my traefik.yaml?
Wobak
Wobak6d ago
you can try, that might fix your error you'll need to restart traefik
jhmc93
jhmc93OP6d ago
sorry i'm still newbie when it comes to traefik
jhmc93
jhmc93OP6d ago
it fixed the error
No description
jhmc93
jhmc93OP6d ago
is that working now? or do I like u said to make more changes to my configuration? @Wobak
Wobak
Wobak6d ago
so you can try to access your nginx and add a .env to the URL see if you get a 403 and if cscli metrics reports it if so it means it works for the bouncing, and if you don't have another website you need to protect you can leave it as is. If you want things to be a bit more clean, moving the middleware config & definition to yaml is probably better
jhmc93
jhmc93OP6d ago
I have two more websites i wanna publish can you help me simplify it? just so I don't have to keep using the labels constantly, also what do u mean by add a .env?, sorry like I said I'm still very new to this and need the step by step guides to help with this, if u can guide me a bit more that would be appreciated thanks @Wobak
Wobak
Wobak6d ago
no worries. your website url that you're hosting with nginx. Try to access https://mynginxwebsiteURL/.env see if you get blocked
jhmc93
jhmc93OP6d ago
what am I looking for in the metrics? as i did get blocked
Wobak
Wobak6d ago
No description
Wobak
Wobak6d ago
this is part of the output of cscli metrics
Loz
Loz6d ago
also note that you need to set mode to appsec if not, I think it bypasses all checks
jhmc93
jhmc93OP6d ago
here you go @Wobak dont know if that's showing anything similar @Loz oz how do I go about doing that, can you walk me through it?
No description
No description
Wobak
Wobak6d ago
unsure
Loz
Loz6d ago
You just update your plugin definition to add
....
crowdsecMode: appsec
....
crowdsecMode: appsec
jhmc93
jhmc93OP6d ago
in the traefik yaml
Loz
Loz6d ago
or well, where ever you defined the plugin
jhmc93
jhmc93OP6d ago
oh, it did 403 error though
Loz
Loz6d ago
check the crowdsec logs also
jhmc93
jhmc93OP6d ago
this right?
No description
Loz
Loz6d ago
no where you defined the plugin configuration like the api key
Wobak
Wobak6d ago
is it equivalent to crowdsecAppsecEnabled: true or does is it need to be set as well @Loz ?
jhmc93
jhmc93OP6d ago
Ooh
Loz
Loz6d ago
honestly dont know @Wobak dont use it, so just purely looking at code 😄
Wobak
Wobak6d ago
😄
Loz
Loz6d ago
but I know the plugin has a fail safe if lapi is down
Wobak
Wobak6d ago
fair enough
Loz
Loz6d ago
and i believe if the mode set to a lapi option it will skip appsec if lapi is down
jhmc93
jhmc93OP5d ago
If I remember rightly I put it docker compose
Loz
Loz5d ago
example
http:
middlewares:
crowdsec:
plugin:
bouncer:
enabled: true
crowdsecAppsecEnabled: true
crowdsecAppsecHost: crowdsec:7422
crowdsecAppsecFailureBlock: true
crowdsecAppsecUnreachableBlock: true
crowdsecLapiKey: someapikey (api key removed)
crowdsecMode: appsec ## add this!
http:
middlewares:
crowdsec:
plugin:
bouncer:
enabled: true
crowdsecAppsecEnabled: true
crowdsecAppsecHost: crowdsec:7422
crowdsecAppsecFailureBlock: true
crowdsecAppsecUnreachableBlock: true
crowdsecLapiKey: someapikey (api key removed)
crowdsecMode: appsec ## add this!
jhmc93
jhmc93OP5d ago
Oh ok So question if I use the label traefik.http.routers.nginx.middlewares=crowdsec, will it use the middlware from the configuration file? So I don't have to keep putting the API key in the labels
Loz
Loz5d ago
think you can do crowdsec@file
jhmc93
jhmc93OP5d ago
Ah
Loz
Loz5d ago
exactly how I did it in the article 😄
jhmc93
jhmc93OP5d ago
Also new error
jhmc93
jhmc93OP5d ago
No description
jhmc93
jhmc93OP5d ago
Sorry it on my phone
Loz
Loz5d ago
hmmm maybe they have a bug that doesnt take the mode into effect as long as I guess you set the mode
jhmc93
jhmc93OP5d ago
I'm not exposing 8080 on crowdsec in the compose file if u check my compose?
Loz
Loz5d ago
well 8080 within the docker network is exposed by default anyways on crowdsec cause it binds to 0.0.0.0
jhmc93
jhmc93OP5d ago
Is it coz I have 8080 one of my traefik port then?
Wobak
Wobak5d ago
yes
Loz
Loz5d ago
no cause your going to crowdsec:8080 not traefik:8080
Wobak
Wobak5d ago
yeah but crowdsec cannot bind to 8080
Loz
Loz5d ago
it can from within the docker namespace
Wobak
Wobak5d ago
ah but there is no attempt to do so my bad I stand corrected
Loz
Loz5d ago
all because your not exposing it, doesnt mean it cannot bind crowdsec would hard crash if it cannot bind lapi
Wobak
Wobak5d ago
well depends on what you mean by bind bind to its own interface in the docker network, you're right bind to the host's port, it'll fail
jhmc93
jhmc93OP5d ago
Then I wonder why it not connection
Loz
Loz5d ago
docker blip
jhmc93
jhmc93OP5d ago
Connecting Both crowdsec and traefik are on my proxy network on docker Still does the error if I recreate the container Another problem
jhmc93
jhmc93OP5d ago
I can't access nginx anymore
No description
jhmc93
jhmc93OP5d ago
What's going on I can't access nginx anymore just says access denied
Loz
Loz5d ago
it cause by default if the plugin cannot access lapi it blocks all traffic so did you set the mode as said?
jhmc93
jhmc93OP5d ago
No description
Loz
Loz5d ago
okay and you remove all crowdsec labels and replaced simply with crowdsec@file?
jhmc93
jhmc93OP5d ago
It been set like that since And ye
Wobak
Wobak5d ago
can you show the nginx compose labels,
jhmc93
jhmc93OP5d ago
No description
Loz
Loz5d ago
also might be useful to turn on debug mode for the plugin add logLevel: DEBUG to the crowdsec@file
jhmc93
jhmc93OP5d ago
In the labels?
jhmc93
jhmc93OP5d ago
Ok
Wobak
Wobak5d ago
did you up -d the nginx after the config change (stupid question but still asking :))
jhmc93
jhmc93OP5d ago
--force recreate the nginx and trraefik-crowdsec compose files
jhmc93
jhmc93OP5d ago
Like this?
No description
Loz
Loz5d ago
capital L logLevel:
jhmc93
jhmc93OP5d ago
Done I'm guessing I check the logs with docker logs crowdsec?
Loz
Loz5d ago
no traefik logs there should be extra debug statements
jhmc93
jhmc93OP5d ago
No description
Loz
Loz5d ago
try a request? then logs
jhmc93
jhmc93OP5d ago
No description
Loz
Loz5d ago
ahhh 401 your api key is not correct or well not working if you run docker exec crowdsec cscli bouncers list
jhmc93
jhmc93OP5d ago
No description
jhmc93
jhmc93OP5d ago
Don't know why two are there but it should be the bottom one @Loz
Loz
Loz5d ago
but it thinks the key is wrong either a copy mistake or something anyway you can try a curl request?
jhmc93
jhmc93OP5d ago
What should I curl @Loz
Loz
Loz5d ago
within the crowdsec one you need to
curl -XHEAD -h "X-Api-Key: <your_key>" http://127.0.0.1:8080/v1/decisions/stream
curl -XHEAD -h "X-Api-Key: <your_key>" http://127.0.0.1:8080/v1/decisions/stream
jhmc93
jhmc93OP5d ago
Ok I'll do that now thanks for helping me
Loz
Loz5d ago
I got to go as end of day and got responsibilites but if that returns 401, then the key is wrong. Regenerate it by doing cscli bouncers add then try that, if works add it to the configuration. but keep reading the logs of both crowdsec and traefik, you should iron it out till I can aid again
jhmc93
jhmc93OP5d ago
@Loz do I need <>? In the command
jhmc93
jhmc93OP5d ago
Getting the following
No description
jhmc93
jhmc93OP5d ago
And ok, can you give me a hand tomorrow @Loz? If not don't worry
Loz
Loz5d ago
No it just what I use to show a placeholder Remove the <>
jhmc93
jhmc93OP5d ago
@Loz same reply on the CMD line
No description
Loz
Loz5d ago
Can you exec it from within the crowdsec container
jhmc93
jhmc93OP5d ago
So this is the command: docker exec crowdsec curl -XHEAD -h "X-Api-Key: hBR7Q9sUaeF/ljkKVVewexmJvjzIGqg3eUTMYrwsI" http://127.0.0.1:8080/v1/decisions/stream, is that right? Or is it wrong @Loz Anyway can u help tmrw if not don't worry From the output of that command above after exec ive obviously put the wrong command @Loz
Wobak
Wobak5d ago
Add -it after exec
jhmc93
jhmc93OP5d ago
Ok will run it later on, bit busy at the moment but thanks @Wobak also thanks to you as well @Loz Will let you know how I get on
jhmc93
jhmc93OP4d ago
Hi @Wobak or @Loz , me again got a slight problem, here's the screenshot:
No description
Loz
Loz4d ago
just need to prefix with apk add curl && curl...<rest of curl command here>
jhmc93
jhmc93OP4d ago
No description
Loz
Loz4d ago
I think I messed up it should be -H not small
jhmc93
jhmc93OP4d ago
it just hangs with that warning
No description
Loz
Loz4d ago
change -XHEAD to -I then
jhmc93
jhmc93OP4d ago
No description
jhmc93
jhmc93OP4d ago
I'm guessing the key doesn't work
Loz
Loz4d ago
yep, so just do cscli bouncers add traefik-prod or whatever name then copy and try that key if that works put that in your configuration
jhmc93
jhmc93OP4d ago
@Loz how do i delete the other 2 on my list
Loz
Loz4d ago
cscli bouncers delete <name> minus <> for placeholder
jhmc93
jhmc93OP4d ago
all good?
No description
Loz
Loz4d ago
yep key is good so put that in your configuration and it should come alive
jhmc93
jhmc93OP4d ago
compose traefik config anything in the crowdsec config files where the key needs to be changed before i recreate the container got any idea? because don't wanna start the container and to find out that im missing th api key somewhere @Loz
Loz
Loz4d ago
You need to update it where you defined the config for the remediation https://discord.com/channels/921520481163673640/1444412137761013962/1445086613943222446 the "crowdsecLapiKey"
jhmc93
jhmc93OP4d ago
done that
Loz
Loz4d ago
then thats it
jhmc93
jhmc93OP4d ago
what does this mean that's appeared in my traefik logs "DEBUG: CrowdsecBouncerTraefikPlugin: 2025/12/03 15:10:57 getTLSConfigCrowdsec:CrowdsecLapiScheme https:no" also tried testing it with docker exec crowdsec cscli decisions add --ip <my laptop ip> but it didn't block it, is that meant to happen because it's https? @Loz
Loz
Loz4d ago
that because you didnt define the LAPI configuration, you only defined WAF configuration hence mode: appsec
jhmc93
jhmc93OP4d ago
ah so is there another way i can test it also what does my traefik logs above mean
Loz
Loz4d ago
yes send a request to .env curl http://yourdomain.tld/.env
jhmc93
jhmc93OP4d ago
it has blocked it sweet
jhmc93
jhmc93OP4d ago
so my traefik logs are normal then?
Loz
Loz4d ago
that because we defined log level DEBUG just remove that from configuration as we debugged the issue
jhmc93
jhmc93OP4d ago
does it mean anything though?
Loz
Loz4d ago
it just a debug log to say that TLS is not going to be used between traefik and crowdsec this is fine for internal / docker network as it not being sent "over the wire" for MITM attacks
jhmc93
jhmc93OP4d ago
so if someone attacks my traffic publicly it will block it using crowdsec
Loz
Loz4d ago
if they send a request that trigger a WAF rule, yes but only for this application as you didnt apply the middleware at the entrypoint level
jhmc93
jhmc93OP4d ago
oh?, I'm wanting to use crowdsec to be my security agent becaue right now I'm exposing my domain via cloudflare tunnel, yes I know cloudflare is secure itself but I wanna add that added layer of protection, hence the main reason I'm trying to use crowdsec
Loz
Loz4d ago
yeah so just move the middleware to your entrypoint, if you want IP blocking there a handful more modifications you need to make (since your traffic is coming from CF tunnels you need to get the real IP)
jhmc93
jhmc93OP4d ago
can you walk me through it?, as I haven't got a clue on where to start... Sorry I sound thick, but still very new to this
Loz
Loz4d ago
Sorry I cant just give up lots of time to hand walk you through it, there a plently of guides online to achieve this and also gpt can help. unless somebody else stumbles across this thread that can spare the time.
jhmc93
jhmc93OP3d ago
ok no problem, just wouldn't know where to start, I've tried to find guides but all I got was the appsec stufff chat gpt just done what u have helped me through on when I asked, do I need to ask it over traefik or cloudflare tunnels as i asked over traefik and it returned with what I've just set up also will I need to use the cloudflare bouncer?? @Loz Are you around @Loz Hey @Loz or @Wobak for cloud flare tunnels and ip blocking do I need the cloud flare bouncer Or do I need something else??
Loz
Loz3d ago
Well up to you, you can do cloudflare or use traefik but you have to configure traefik to trust the cf tunnel IP as it needs to get the real IP. There is configuration for this within the remediation component but as stated, I dont use traefik or this component so have very little I can input for this.
jhmc93
jhmc93OP2d ago
Oh ok, I just wanna block bad ips on my traefik server but I thought I had set up with what we got working the other day Don't worry though, chat gpt just mentions using cloud flare bouncer and traefik bouncer

Did you find this page helpful?