Deploy CrowdSec with Docker¶
CrowdSec is an open source behavioral detection solution that analyzes logs and various events to identify malicious behavior.
Unlike a simple blocking system based on IP address lists, CrowdSec relies on detection scenarios to identify different types of attacks, then produces decisions that can be used by bouncers to apply remediation, for example by blocking an IP address.
In this part, we only see how to deploy CrowdSec to integrate it with NGX Ops.
For a complete CrowdSec installation with bouncer configuration and remediation setup, you will find several additional resources at the end of this page.
Deploy CrowdSec¶
In a folder dedicated to CrowdSec, for example /containers/crowdsec, create the following compose.yml file:
services:
crowdsec:
image: crowdsecurity/crowdsec:latest
restart: always
user: root
environment:
COLLECTIONS: "crowdsecurity/nginx crowdsecurity/sshd crowdsecurity/wordpress crowdsecurity/base-http-scenarios crowdsecurity/http-cve crowdsecurity/http-dos"
GID: "${GID-1000}"
volumes:
- /var/log:/var/log
- /containers/nginx/nginx/logs:/var/log/nginx
- ./crowdsec/db:/var/lib/crowdsec/data/
- ./crowdsec/config:/etc/crowdsec/
networks:
crowdsec_network:
ipv4_address: 10.199.0.5
networks:
crowdsec_network:
ipam:
driver: default
config:
- subnet: 10.199.0.0/24
Note: this example mounts the NGX Ops log directory directly in the CrowdSec container. Adapt the
/containers/nginx/nginx/logspath to your installation.
Then start CrowdSec:
Check that the container started correctly:
Configure Nginx log analysis¶
We now tell CrowdSec that it must analyze the Nginx logs.
In the directory:
create the file:
For example:
Add the following content:
The /var/log/nginx/*.log path is the path as seen from the CrowdSec container.
The Docker mount defined earlier maps this path to the logs generated by NGX Ops on the host.
Then restart CrowdSec to apply the new configuration:
Check that it works¶
To check that CrowdSec is analyzing the logs, use the command:
This command notably lets you check that the log files are taken into account and that events are analyzed by CrowdSec.
If the Nginx logs are correctly detected, they appear in CrowdSec's metrics.
Integration with NGX Ops¶
At this stage, CrowdSec can analyze the logs generated by NGX Ops.
This configuration is the detection part.
It notably lets NGX Ops rely on CrowdSec to get information on IP addresses that have been the subject of decisions or detections.
To set up automatic blocking of IP addresses, you then need to configure a bouncer suited to your architecture.
CrowdSec and NGX Ops are complementary: NGX Ops provides administration and visibility around Nginx, while CrowdSec brings its behavioral detection engine and, with a bouncer, the ability to apply automatic remediation.
Additional resources¶
If you want to go further with setting up CrowdSec, here are several articles available on RDR-IT:
- CrowdSec: installation and configuration in a container with Docker
- CrowdSec: integration with Fortigate – Fortinet firewalls
- Set up a central CrowdSec instance to secure your infrastructure
(These articles are in French.)