Crowdsec Modules
Required Knowledge
How to SSH into servers and use SSH keys
Install Crowdsec
Crowdsec is pushed via Ansible, but if you're following along at home... follow the official guide instead :P
Firewall Bouncer
This guide is applicable to Ubuntu 20.04 LTS, which uses nf tables by default
Run the below commands and take note of the API key
Remove and edit the config file
Paste in my config below (please update the variables marked with a $)
Restart the service and review the nft tables
You should see an output similar to below
Cloudflare Bouncer
I've read online that the original bouncer isn't as good as the workers module but I'm a bit nervous to use the worker as, to me, it reads like it reviews every request coming through Cloudflare. This is great because it checks current data against current data but you only get x amount of free worker compute. If you're DDOS'd I imagine the bill would be big. So I've gone with the WAF based bouncer, which is pretty slow to update and can get API limited.
Generate an API key for Cloudflare
Navigate to user profile > API keys
Create a new API token and pick custom token
Give it the following permissions
Click continue to summary and then create token
Copy the API token into your password vault
Gather your Account and Zone IDs
Go to your Cloudflare dashboard and open one of the domains you wish to protect with Cloudflare
Scroll down and locate the API section on the right
Take note of your Zone ID (I would recommend formatting it like $ZONEID #my.domain.com)
Take note of your Account ID
Repeat steps 1 - 3 for each domain you wish to protect (the account ID will most likely be the same for each)
Install the Crowdsec module and bouncer
Example config:
Allow CURL or remote access to Crowdsec Engine
Some tools, such as Docker containers, are considered 'external' to the host device. This causes Crowdsec (and potentially the firewall) to block communications for this app or module.
For example, I had to do this for the Wordpress Crowdsec plugin, which sits inside my Wordpress container.
SSH into the server you wish to link back too (generally the host machine)
Input the below command allow Crowdsec through the firewall and to edit the Crowdsec config file
Locate 127.0.0.1:8080 and change it to 0.0.0.0:8080 This allows any device to talk to the Crowdsec engine on that device
Save the config file
Input the below command to restart Crowdsec
You will now be able to CURL the Crowdsec engine
Last updated