-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CrowdSec and/or ModSecurity #255
Comments
Thanks for the request, I think it should be possible, but one question: What do they exactly do? I didn't understand it, yeet? What is a use case? |
Hey, i will try my best to explain it: Now to ModSecurity: ModSecurity is basically a Module for various Web-Servers (Apache, Nginx, etc) which is used as a WAF (Web-Application-Firewall) to protect against and to help setting up protection against different attacks like Cross-Site-Scripting, SQL Injection, or Session Hijacking. I guess the use case for both should be clearer now, but in general, both of them can improve the overall security of the system at the web-server (or reverse-proxy in our case) level by scanning logs and network traffic, checking them against pre-defined rules and taking action against malicious activity. Both of these systems have a lot of pre-configured scenarious to check, but they still have to be used by the user. I tried to make this explanation as simple as possible with my (limited) knowledge, but i hope its still understandable :) And a quick side-note to CrowdSec: It only detects activity, to apply these a bouncer is needed which there are a larger number of different ones for different systems found here https://docs.crowdsec.net/docs/bouncers/intro |
do they need to be configured in a nginx config file? and would it possible to built them into nginx and make them manually configurable? |
For CrowdSec after installation a nginx.conf should be placed here "/etc/nginx/conf.d/crowdsec_nginx.conf" which is so far pre-configured to just run (thats with the bouncer-installation, not with crowdsec on its own, as i said earlier, crowdsec doesnt do much on its own). More information about this can be found here https://doc.crowdsec.net/docs/bouncers/nginx/ For ModSecurity (for this libmodsecurity and the nginx-connector is needed) there are a few directives that need to be configured in the nginx.conf files of the different hosts. |
Btw, there are 2 pr´s for nginx-proxy-manager for this |
I will do it (maybe this or next week), but how do I test if they work? |
Hm, thats not so easy. For crowdsec i would guess either the "cscli metrics"-command would work, which shows some metric information or simpler "cscli decisions add --ip your.ip.address --duration 5m --reason "testing"" could work. The last command blocks your ip address for 5 minutes. |
I think mod security should be possible very easily, but crowdsec could be hard, since it is not optimized for alpine linux, which this fork is based on |
Are you sure about the crowdsec part? Even the official crowdsec docker is based off of alpine https://github.com/crowdsecurity/crowdsec/blob/master/Dockerfile |
that is just crowdsec, no nginx... |
Ohh yes, you are totally right. I am sorry, havent looked closer. |
I could try to do the steps of install.sh manually |
Crowdsec has a requirement for lua scripting language as well so that will need to be installed, npm normally uses openresty instead of vanilla nginx I did a similar pr for jlesage/docker-nginx-proxy-manager that contains everything needed in one PR jlesage/docker-nginx-proxy-manager#238 there is also a caddy module |
But it should work with vanilla nginx also, right? since I don't get openresty built to a binary without shared libaries, I switched to plain nginx, because I got it built static |
I would say it is doable but you will need to add lua and a few modules to nginx |
crowdsec would come with a massive size increment: https://pkgs.alpinelinux.org/package/edge/testing/x86_64/crowdsec 70MB! |
where did you add the cscli? |
No, that is the full crowdsec package, what you add to nginx is the bouncer https://github.com/crowdsecurity/cs-nginx-bouncer (About 20kb) this talks to the crowdsec server and blocks based on a ban list in crowdsec |
i'll have a look at your build process and try get this working, did the rest of them so shouldn't be hard |
https://github.com/crowdsecurity/cs-nginx-bouncer/blob/8a8f40f83a3495b973fd5a4b402a48cacd34460b/install.sh#L44 since the install script makes requests to cscli |
I'll have to port some of my changes from here, and make it docker friendly https://github.com/crowdsecurity/cs-openresty-bouncer |
I got nginx build with lua support, but
|
What would you all do?
|
@LePresidente what would you say? |
Hi, if this fork was done for quic then i say leave it as is without crowdsec, when quic does make it officially into nginx/openresty then make the move back to openresty, |
with #266 I got lua working, so crowsec should be possible |
I've got crowdsec working |
I will do a last test and then push it to latest, then I will work on modsecurity |
@LePresidente @Joly0 I've added some docs to the readme and pushed it to latest, could you please test it? |
Hey, thank you for your work. I am currently in vacation, so quite difficult for me to test that, but maybe i find a way |
But one question from my side: Is it normal that with crowdsec enabled, nginx takes long to launch and uses a lot of cpu while launching/reloading (one complete cpu core)? and after the full launch/reload of nginx, nginx uses only a few percent cpu? |
modsec is building: https://github.com/ZoeyVid/nginx-quic/actions/runs/5012341255 |
got it working, a last fix is building here: https://github.com/ZoeyVid/nginx-quic/actions/runs/5015297036/jobs/8990672365 when this build is finished, I will do a last test and push it to latest, modsec will be always enabled |
It works, but I wont will push it to latest, because of this: coreruleset/coreruleset#3216, if you need it you can use the zoeyvid/nginx-proxy-manager:develop image, but note: this image has always the latest commit from this repo and breaks very often |
I will publish modsec, when coreruleset/coreruleset#3218 is merged, I will also add options for manual config (already in readme) |
Wow, progress movies fast on this repo! Great work @Zoey2936 |
thanks |
didyou got a 403 error? |
nope, its just that its checking requests from localhost i believe it shouldn't |
whrer did you find that logs? |
since if modsec does block something, it will return a 403 error |
yes didn't block anything, but its still checking localhost requests made to /api i don't think its necessary to check requests coming from localhost. i believe modsec has option for ip whitelist to add the private ip ranges used by localhost/docker |
You can whitelist it yourself if you want, config files are free to edit in /opt/npm/etc/modsecurity, but I wouldn't do that (ip overriding while portforwarding/wrong proxiing/wrong forwarded for headers, etc.) |
just want to add another thing: nginx released today nginx v1.25.0 with HTTP/3 / Quic support, so if openresty will update to it in some weeks/months I will switch to openresty, I switched today from cloning the branch to using the published tar file |
yeah sorry looks like i was using an older image and i couldn't find
i'll make a copy and save it i don't like openresty 🤷♂️ |
can you explain, why? I like to stick to nginx, but I think openresty has the better lua implementation... |
nothing special just personal preference, i use nginx plus in production with some lua scripting to filter traffic and communicate with backends/apis/redis and thats been running perfectly for me so i don't need more stuff, ngx-lua module was meant for nginx but its maintainers decided to get a copy of nginx and make openresty and keep on suggesting people to install openresty i feel like they are forcing it thats why i don't like it |
I understand what you mean, but I think that the lua implementation is better when using openresty and openresty also has good patches... |
true and they tend to release stuff faster then nginx aswell, but nginx has a better and more stable development process and is less likely to cause bugs so its more suitable for production use.. imo |
I've pushed this now to latest. |
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: