RousselTMLEARNING

Article · CrowdSec: From Discovery to Expertise

Installing and configuring CrowdSec

1. Installing #

Linux packages or Docker.

On Linux #

curl -s https://install.crowdsec.net | sudo sh
sudo apt install crowdsec

sudo systemctl status crowdsec
sudo cscli version
sudo cscli collections list
sudo cscli lapi status
sudo cscli capi status

During installation, CrowdSec detects the services present and installs the matching collections. Read the script before running it if your security policy requires it.

Docker #

services:
  crowdsec:
    image: crowdsecurity/crowdsec:v1.8.2
    restart: unless-stopped
    environment:
      COLLECTIONS: "crowdsecurity/linux crowdsecurity/traefik"
      TZ: Europe/Paris
    volumes:
      - ./acquis.d:/etc/crowdsec/acquis.d:ro
      - crowdsec-config:/etc/crowdsec
      - crowdsec-data:/var/lib/crowdsec/data   # mandatory: without this volume, the container refuses to start
      - /var/log/auth.log:/logs/auth.log:ro
volumes:
  crowdsec-config:
  crowdsec-data:

Declare logs in ./acquis.d/ssh.yaml. The path is the one seen inside the container:

filenames:
  - /logs/auth.log
labels:
  type: syslog
docker compose up -d
docker compose exec crowdsec cscli collections list
docker compose exec crowdsec cscli metrics
VariableRole
COLLECTIONSCollections to install, separated by spaces
BOUNCER_KEY_<nom>Declares a bouncer and its key
DISABLE_ONLINE_APITurns off communication with the CAPI
ENROLL_KEYEnrolls the instance in the console
USE_WALEnables SQLite WAL mode

2. The files #

Where each setting lives.

The tree #

/etc/crowdsec/
├── config.yaml                  # general configuration
├── acquis.yaml et acquis.d/     # which logs to read
├── profiles.yaml                # from alert to decision
├── simulation.yaml              # scenarios in simulation
├── parsers/ scenarios/ collections/ postoverflows/
├── notifications/               # slack.yaml, email.yaml, http.yaml…
├── bouncers/                    # bouncer configuration
├── local_api_credentials.yaml   # LAPI access
└── online_api_credentials.yaml  # CAPI access
/var/lib/crowdsec/data/crowdsec.db  # default SQLite database
/var/log/crowdsec.log and /var/log/crowdsec_api.log

After a change, reload the service: sudo systemctl reload crowdsec.

Declaring logs: acquisition #

Acquisition says which logs to read and with which parser. Prefer one file per source in /etc/crowdsec/acquis.d/.

filenames:
  - /var/log/auth.log
labels:
  type: syslog

The labels.type field points to the right parser. Use syslog for logs in syslog format, otherwise the type stated by the collection (nginx, traefik…). Other sources exist: journalctl, docker, kubernetes, syslog, loki, kafka.

Always check. An undeclared log produces no error: it is simply never analyzed. Check with cscli metrics show acquisition. CrowdSec reads new lines: what existed before startup is not analyzed.

3. Console and several servers #

Supervise and share decisions.

The console #

The app.crowdsec.net console offers a web view of your instances. Get a key from the console, then:

sudo cscli console enroll VOTRE_CLE
# Acceptez l'instance dans la console, puis :
sudo systemctl reload crowdsec

One LAPI for several servers #

Three agents and three bouncers connected to one Local API

On each agent, register with the LAPI, then validate the machine on the LAPI side:

# Sur l'agent
sudo cscli lapi register --url http://10.0.0.10:8080

# Sur le serveur LAPI
sudo cscli machines list
sudo cscli machines validate NOM_DE_LA_MACHINE

On the agent, then disable the local LAPI (api.server.enable: false in config.yaml). For large volumes, replace SQLite with PostgreSQL or MySQL.

Sources #

📄 Installing and configuring CrowdSec: packages, Docker, acquisition →

My progress

  • ⏱ Estimated time : ≈ 9 min

Sign in to track your progress and take notes. Sign in

💬 Ask a question

Recommended Articles

CrowdSec in production: best practices

Good habits for running CrowdSec in production: LAPI, keys, false positives, database, upgrades a...

CrowdSec observability: banned IPs, blocked attacks, Prometheus and Grafana

Monitoring CrowdSec: cscli metrics, banned IPs, detected attacks, volume blocked by bouncers, Pro...

Decisions, profiles, allowlists and AppSec in CrowdSec

Manage decisions with cscli, adapt block duration and type with profiles, avoid false positives w...

CrowdSec: understanding the collaborative firewall

What CrowdSec is, how it detects and blocks attacks: Security Engine, parsers, scenarios, Local A...

CrowdSec bouncers: principles and firewall bouncer

Understanding CrowdSec bouncers: where to block, live and stream modes, API keys, decisions API, ...

CrowdSec collections, parsers and scenarios

The Hub, collections, the parser pipeline and scenarios: install, understand with cscli explain, ...

CrowdSec bouncers for Nginx, Apache and HAProxy

Setting up CrowdSec bouncers for Nginx, OpenResty, Apache and HAProxy SPOA: configuration, block ...

CrowdSec or Fail2ban: what are the differences?

Comparing CrowdSec and Fail2ban: detection, blocking, sharing, performance, multi-server, and how...

Protecting Traefik with CrowdSec: the bouncer plugin

Setting up the CrowdSec bouncer in Traefik: plugin, middleware, stream and live modes, real IP be...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!