CrowdSec Security Engine
Collaborative security engine with crowdsourced threat intelligence.
Overview
CrowdSec is a modern, open-source Intrusion Detection System (IDS) that revolutionizes network security through collaborative threat intelligence. Born from the need to address evolving cyber threats, CrowdSec operates on a crowdsourced security model where detection signals from the global community are aggregated and shared to identify malicious actors in real-time. Unlike traditional security solutions that work in isolation, CrowdSec creates a collective intelligence network where blocked IPs and attack patterns from one installation protect all users in the ecosystem. This Docker stack combines CrowdSec's security engine with PostgreSQL for metrics storage, Metabase for comprehensive analytics dashboards, and multiple bouncers including Traefik integration and firewall-level protection. The PostgreSQL database serves as the central repository for security events, decision logs, and behavioral analytics, while Metabase transforms this raw security data into actionable insights through customizable dashboards and reporting. This configuration creates a complete security operations center capable of real-time threat detection, automated response, and detailed forensic analysis, making enterprise-grade security accessible to organizations of all sizes.
Key Features
- Collaborative threat intelligence with real-time IP reputation updates from the global CrowdSec community
- Multi-layer bouncer architecture supporting both Traefik reverse proxy integration and iptables firewall enforcement
- PostgreSQL-backed metrics storage with full ACID compliance for reliable security event logging and analysis
- Metabase business intelligence integration providing customizable security dashboards and automated reporting
- Collection-based detection scenarios for Linux, Nginx, and SSH with extensible parser architecture
- RESTful API at port 8080 for programmatic access to decisions, alerts, and community threat intelligence
- Behavioral analysis engine distinguishing between legitimate users and malicious actors through machine learning algorithms
- Hub ecosystem integration allowing installation of community-contributed parsers, scenarios, and collections
Common Use Cases
- 1Web application protection with Traefik integration for blocking malicious requests before they reach application servers
- 2SSH brute force protection for Linux servers with automatic IP blocking and community threat intelligence
- 3Multi-tenant hosting environments requiring coordinated security across multiple customer applications
- 4Security operations centers needing centralized threat visibility and automated incident response capabilities
- 5Compliance environments requiring detailed audit trails and security reporting through Metabase dashboards
- 6DevOps teams implementing security-first infrastructure with automated threat response and minimal false positives
- 7Small to medium businesses seeking enterprise-grade security without dedicated security personnel or expensive commercial solutions
Prerequisites
- Minimum 2GB RAM recommended for PostgreSQL metrics storage and Metabase analytics processing
- Host system with iptables support and NET_ADMIN capabilities for firewall bouncer functionality
- Read access to system log files (/var/log) for CrowdSec parsers to analyze SSH, web server, and system events
- Available ports 8080 (CrowdSec API), 3000 (Metabase), and 6060 (CrowdSec metrics) for service communication
- Basic understanding of firewall rules and network security concepts for bouncer configuration
- PostgreSQL administration knowledge for database maintenance and custom metrics schema modifications
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 crowdsec: 3 image: crowdsecurity/crowdsec:latest4 ports: 5 - "8080:8080"6 - "6060:6060"7 environment: 8 GID: "${GID:-1000}"9 COLLECTIONS: "crowdsecurity/linux crowdsecurity/nginx crowdsecurity/sshd"10 CUSTOM_HOSTNAME: crowdsec11 volumes: 12 - crowdsec_config:/etc/crowdsec13 - crowdsec_data:/var/lib/crowdsec/data14 - /var/log:/var/log:ro15 networks: 16 - crowdsec-net17 restart: unless-stopped1819 crowdsec-bouncer-traefik: 20 image: fbonalair/traefik-crowdsec-bouncer:latest21 environment: 22 CROWDSEC_BOUNCER_API_KEY: ${BOUNCER_API_KEY}23 CROWDSEC_AGENT_HOST: crowdsec:808024 GIN_MODE: release25 depends_on: 26 - crowdsec27 networks: 28 - crowdsec-net29 restart: unless-stopped3031 crowdsec-bouncer-firewall: 32 image: crowdsecurity/cs-firewall-bouncer:latest33 environment: 34 BACKEND: iptables35 API_URL: http://crowdsec:808036 API_KEY: ${BOUNCER_API_KEY}37 cap_add: 38 - NET_ADMIN39 - NET_RAW40 network_mode: host41 depends_on: 42 - crowdsec43 restart: unless-stopped4445 postgres: 46 image: postgres:16-alpine47 environment: 48 POSTGRES_USER: ${POSTGRES_USER}49 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}50 POSTGRES_DB: crowdsec_metrics51 volumes: 52 - postgres_data:/var/lib/postgresql/data53 networks: 54 - crowdsec-net55 restart: unless-stopped5657 metabase: 58 image: metabase/metabase:latest59 ports: 60 - "3000:3000"61 environment: 62 MB_DB_TYPE: postgres63 MB_DB_HOST: postgres64 MB_DB_PORT: 543265 MB_DB_DBNAME: crowdsec_metrics66 MB_DB_USER: ${POSTGRES_USER}67 MB_DB_PASS: ${POSTGRES_PASSWORD}68 depends_on: 69 - postgres70 networks: 71 - crowdsec-net72 restart: unless-stopped7374volumes: 75 crowdsec_config: 76 crowdsec_data: 77 postgres_data: 7879networks: 80 crowdsec-net: 81 driver: bridge.env Template
.env
1# CrowdSec Bouncer API Key (generate with: cscli bouncers add my-bouncer)2BOUNCER_API_KEY=34# PostgreSQL5POSTGRES_USER=crowdsec6POSTGRES_PASSWORD=secure_postgres_passwordUsage Notes
- 1CrowdSec API at http://localhost:8080
- 2Metabase dashboards at http://localhost:3000
- 3Generate bouncer key: docker compose exec crowdsec cscli bouncers add my-bouncer
- 4View decisions: docker compose exec crowdsec cscli decisions list
Individual Services(5 services)
Copy individual services to mix and match with your existing compose files.
crowdsec
crowdsec:
image: crowdsecurity/crowdsec:latest
ports:
- "8080:8080"
- "6060:6060"
environment:
GID: ${GID:-1000}
COLLECTIONS: crowdsecurity/linux crowdsecurity/nginx crowdsecurity/sshd
CUSTOM_HOSTNAME: crowdsec
volumes:
- crowdsec_config:/etc/crowdsec
- crowdsec_data:/var/lib/crowdsec/data
- /var/log:/var/log:ro
networks:
- crowdsec-net
restart: unless-stopped
crowdsec-bouncer-traefik
crowdsec-bouncer-traefik:
image: fbonalair/traefik-crowdsec-bouncer:latest
environment:
CROWDSEC_BOUNCER_API_KEY: ${BOUNCER_API_KEY}
CROWDSEC_AGENT_HOST: crowdsec:8080
GIN_MODE: release
depends_on:
- crowdsec
networks:
- crowdsec-net
restart: unless-stopped
crowdsec-bouncer-firewall
crowdsec-bouncer-firewall:
image: crowdsecurity/cs-firewall-bouncer:latest
environment:
BACKEND: iptables
API_URL: http://crowdsec:8080
API_KEY: ${BOUNCER_API_KEY}
cap_add:
- NET_ADMIN
- NET_RAW
network_mode: host
depends_on:
- crowdsec
restart: unless-stopped
postgres
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: crowdsec_metrics
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- crowdsec-net
restart: unless-stopped
metabase
metabase:
image: metabase/metabase:latest
ports:
- "3000:3000"
environment:
MB_DB_TYPE: postgres
MB_DB_HOST: postgres
MB_DB_PORT: 5432
MB_DB_DBNAME: crowdsec_metrics
MB_DB_USER: ${POSTGRES_USER}
MB_DB_PASS: ${POSTGRES_PASSWORD}
depends_on:
- postgres
networks:
- crowdsec-net
restart: unless-stopped
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 crowdsec:5 image: crowdsecurity/crowdsec:latest6 ports:7 - "8080:8080"8 - "6060:6060"9 environment:10 GID: "${GID:-1000}"11 COLLECTIONS: "crowdsecurity/linux crowdsecurity/nginx crowdsecurity/sshd"12 CUSTOM_HOSTNAME: crowdsec13 volumes:14 - crowdsec_config:/etc/crowdsec15 - crowdsec_data:/var/lib/crowdsec/data16 - /var/log:/var/log:ro17 networks:18 - crowdsec-net19 restart: unless-stopped2021 crowdsec-bouncer-traefik:22 image: fbonalair/traefik-crowdsec-bouncer:latest23 environment:24 CROWDSEC_BOUNCER_API_KEY: ${BOUNCER_API_KEY}25 CROWDSEC_AGENT_HOST: crowdsec:808026 GIN_MODE: release27 depends_on:28 - crowdsec29 networks:30 - crowdsec-net31 restart: unless-stopped3233 crowdsec-bouncer-firewall:34 image: crowdsecurity/cs-firewall-bouncer:latest35 environment:36 BACKEND: iptables37 API_URL: http://crowdsec:808038 API_KEY: ${BOUNCER_API_KEY}39 cap_add:40 - NET_ADMIN41 - NET_RAW42 network_mode: host43 depends_on:44 - crowdsec45 restart: unless-stopped4647 postgres:48 image: postgres:16-alpine49 environment:50 POSTGRES_USER: ${POSTGRES_USER}51 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}52 POSTGRES_DB: crowdsec_metrics53 volumes:54 - postgres_data:/var/lib/postgresql/data55 networks:56 - crowdsec-net57 restart: unless-stopped5859 metabase:60 image: metabase/metabase:latest61 ports:62 - "3000:3000"63 environment:64 MB_DB_TYPE: postgres65 MB_DB_HOST: postgres66 MB_DB_PORT: 543267 MB_DB_DBNAME: crowdsec_metrics68 MB_DB_USER: ${POSTGRES_USER}69 MB_DB_PASS: ${POSTGRES_PASSWORD}70 depends_on:71 - postgres72 networks:73 - crowdsec-net74 restart: unless-stopped7576volumes:77 crowdsec_config:78 crowdsec_data:79 postgres_data:8081networks:82 crowdsec-net:83 driver: bridge84EOF8586# 2. Create the .env file87cat > .env << 'EOF'88# CrowdSec Bouncer API Key (generate with: cscli bouncers add my-bouncer)89BOUNCER_API_KEY=9091# PostgreSQL92POSTGRES_USER=crowdsec93POSTGRES_PASSWORD=secure_postgres_password94EOF9596# 3. Start the services97docker compose up -d9899# 4. View logs100docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/crowdsec-firewall/run | bashTroubleshooting
- CrowdSec container fails with 'permission denied' on /var/log: Ensure Docker has read access to host log directories and GID environment variable matches host log group permissions
- Firewall bouncer exits with 'operation not permitted': Add NET_ADMIN and NET_RAW capabilities and ensure container runs with sufficient privileges for iptables manipulation
- Metabase shows 'database connection failed': Verify PostgreSQL container is fully initialized before Metabase startup and check POSTGRES_USER/POSTGRES_PASSWORD environment variables match
- No threat intelligence updates received: Check internet connectivity and ensure CrowdSec can reach api.crowdsec.net for community threat feed synchronization
- High memory usage from PostgreSQL: Implement log rotation for CrowdSec metrics tables and consider PostgreSQL memory tuning for large-scale deployments
- Traefik bouncer not blocking malicious IPs: Verify BOUNCER_API_KEY matches the key generated via 'cscli bouncers add' command and check bouncer registration status
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
crowdseccrowdsec-bouncermetabasepostgresql
Tags
#crowdsec#security#firewall#threat-intelligence#ids
Category
Security & NetworkingAd Space
Shortcuts: C CopyF FavoriteD Download