CrowdSec
To install Crowdsec with the offical installer, start it with the --crowdsec flag. This will prompt for a Crowdsec install at the end of the process.
This is a community guide and is not officially supported. If you have any issues, please reach out to the author.
CrowdSec is a modern, open-source, collaborative behavior detection engine, integrated with a global IP reputation network. It functions as a massively multiplayer firewall, analyzing visitor behavior and responding appropriately to various types of attacks.
Installation
Crowdsec can be installed using the Pangolin Installer.
Enabling CrowdSec turns on Traefik access logging so CrowdSec can analyze traffic. This means config/traefik/logs/access.log will grow over time. If you want to set up log rotation, see the Traefik Access Log Rotation guide.
Configuration
By default, Crowdsec is installed with a basic configuration, which includes the Crowdsec Bouncer Traefik plugin.
Choose the right logs
Syslog
For systems utilizing Syslog, the following volumes should be added to the docker-compose.yml file:
service:
crowdsec:
volumes:
- /var/log/auth.log:/var/log/auth.log:ro
- /var/log/syslog:/var/log/syslog:roCreate a syslog.yaml file under /config/crowdsec/acquis.d with the following content:
filenames:
- /var/log/auth.log
- /var/log/syslog
labels:
type: syslogJournalctl
To log iptables to journalctl, execute the following command on your host system:
iptables -A INPUT -j LOG --log-prefix "iptables: "Update the docker-compose.yml file as follows:
service:
crowdsec:
image: crowdsecurity/crowdsec:latest-debian
environment:
COLLECTIONS: crowdsecurity/traefik crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules crowdsecurity/linux crowdsecurity/iptables
volumes:
- ./config/crowdsec:/etc/crowdsec
- ./config/crowdsec/db:/var/lib/crowdsec/data
- ./config/traefik/logs:/var/log/traefik:ro
- /var/log/journal:/var/log/host:roCreate a journalctl.yaml file under /config/crowdsec/acquis.d with the following content:
source: journalctl
journalctl_filter:
- "--directory=/var/log/host/"
labels:
type: syslogSecuring the Host System (SSH)
By default, only Traefik requests are secured through the Crowdsec bouncer. To extend protection to your host system (e.g., SSH), follow these steps to add a firewall bouncer:
- Install the Crowdsec repositories. Refer to the installation documentation:
curl -s https://install.crowdsec.net | sudo sh- Install the firewall bouncer. For Debian/Ubuntu systems using IPTables, refer to the documentation:
sudo apt install crowdsec-firewall-bouncer-iptables- Create an API key for the firewall bouncer to communicate with your CrowdSec Docker container. ("vps-firewall" is a placeholder name for the key):
docker exec -it crowdsec cscli bouncers add vps-firewall- Copy the displayed API key and insert it into the bouncer's configuration file:
nano /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml- Restart the firewall bouncer:
systemctl restart crowdsec-firewall-bouncer- Update the
docker-compose.ymlfile to expose communication port8080for the CrowdSec container and restart the container:
service:
crowdsec:
ports:
- 6060:6060 # Metrics port
- 8080:8080 # Local API portDocker’s NAT-based port publishing feature automatically exposes all ports: defined in the docker-compose file on all network interfaces. This behavior can bypass your host firewall settings, potentially exposing services that you did not intend to make public.
Please see complete warning about exposing ports.
- Verify communication between the firewall bouncer and the CrowdSec container by running:
docker exec crowdsec cscli metricsThe output should look like this:
+------------------------------------------------------------------+
| Local API Bouncers Metrics |
+---------------------------+----------------------+--------+------+
| Bouncer | Route | Method | Hits |
+---------------------------+----------------------+--------+------+
| traefik-bouncer | /v1/decisions/stream | HEAD | 2 |
| traefik-bouncer@10.0.4.20 | /v1/decisions | GET | 3 |
| vps-firewall | /v1/decisions/stream | GET | 84 | <---------
+---------------------------+----------------------+--------+------+Bot Detection
Bot detection is available as an opt-in option in the installer starting with Pangolin 1.26. It is currently in alpha.
CrowdSec's AppSec bot detection requires browsers to solve a challenge before they can reach any resource behind Traefik. Automated clients that cannot solve the challenge are blocked.
Bot detection applies to every resource routed through the CrowdSec middleware. Non-browser clients, such as mobile apps, API tools, scripts, and webhooks, may be blocked.
Enable with the installer
When installing CrowdSec with the Pangolin installer, answer yes to the following prompt:
Would you like to enable CrowdSec bot detection (alpha)?The installer will add the crowdsecurity/appsec-bot-challenge collection and enable the bot detection AppSec rules for you.
Enable on an existing installation
If CrowdSec is already installed, you can enable bot detection manually:
- Make sure the CrowdSec bouncer plugin in
/config/traefik/traefik_config.ymlisv1.8.1or newer:
experimental:
plugins:
crowdsec:
moduleName: "github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
version: "v1.8.1"- Add the
crowdsecurity/appsec-bot-challengecollection to the CrowdSec container in yourdocker-compose.ymlfile:
service:
crowdsec:
environment:
COLLECTIONS: crowdsecurity/traefik crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules crowdsecurity/appsec-bot-challenge- Update
/config/crowdsec/acquis.d/appsec.yamlto load the bot detection AppSec configs. Note thatappsec_configis replaced by the listappsec_configs:
listen_addr: 0.0.0.0:7422
appsec_configs:
- crowdsecurity/appsec-default
- crowdsecurity/appsec-bot-*
name: myAppSecComponent
source: appsec
labels:
type: appsec- Make sure AppSec is enabled on the CrowdSec middleware in
/config/traefik/dynamic_config.yml. This is the default for installer-based setups:
http:
middlewares:
crowdsec:
plugin:
crowdsec:
crowdsecAppsecEnabled: true
crowdsecAppsecHost: crowdsec:7422- Restart the stack:
docker compose down && docker compose up -dTo disable bot detection, remove crowdsecurity/appsec-bot-* from appsec_configs and restart CrowdSec.
The default detection threshold is used, as recommended by CrowdSec. To tune it, see choosing a threshold. To confirm it is working, follow CrowdSec's verification steps.
Custom Ban Page
To display a custom ban page to attackers, follow these steps:
- Place a
ban.htmlpage in the/config/traefikdirectory. If you prefer not to create your own, you can download the official example:
wget https://raw.githubusercontent.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/refs/heads/main/ban.html- Update the
/config/traefik/dynamic_config.ymlfile to include the following:
http:
middlewares:
crowdsec:
plugin:
crowdsec:
banHTMLFilePath: /etc/traefik/ban.htmlCustom Captcha Page
To use a custom captcha page, follow these steps:
- Place a
captcha.htmlpage in the/config/traefikdirectory. If you don't want to create your own, you can download the official example:
wget https://raw.githubusercontent.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/refs/heads/main/captcha.html- Update the
/config/traefik/dynamic_config.ymlfile with the following configuration, replacing<SERVICE>with your captcha provider (MUST BE eitherhcaptcha,recaptcha, orturnstile), and<KEY>with the appropriate site and secret keys:
http:
middlewares:
crowdsec:
plugin:
crowdsec:
captchaHTMLFilePath: /etc/traefik/captcha.html
captchaGracePeriodSeconds: 300
captchaProvider: <SERVICE>
captchaSiteKey: <KEY>
captchaSecretKey: <KEY>Testing
You can test your configuration by adding a temporary ban or captcha for your IP. The ban will last for one minute.
To add a ban:
docker exec crowdsec cscli decisions add --ip <YOUR IP> -d 1m --type banTo trigger a captcha challenge:
docker exec crowdsec cscli decisions add --ip <YOUR IP> -d 1m --type captchaWas this page helpful?