Skip to Content
OrcaCD LogoOrcaCD

CrowdSec

Detect and block attacks on your OrcaCD Hub with CrowdSec

The Hub writes security events like failed logins, rejected agent connections and invalid webhook requests to its log in a fixed format. With CrowdSec you can turn these events into automatic bans. The same events work for other tools, such as fail2ban.

Prerequisites

Set TRUSTED_PROXIES to the IP address of your reverse proxy. Otherwise, every event shows the IP of the proxy, and CrowdSec would ban your proxy instead of the attacker. Also set LOG_JSON to true and keep LOG_LEVEL at info or lower, see the environment variables.

Security events

Every security event is a log line with "category":"security". Failed or suspicious actions are logged as warn, successful logins and registrations as info.

Rate limits and requests from IPs outside of ALLOWED_IPS are not logged by the Hub, as this would flood the log during an attack. The Hub answers with 429 Too Many Requests and 403 Forbidden, which you can detect in the log of your reverse proxy, see rate limits and blocked requests.

Set up CrowdSec

This guide assumes that CrowdSec and a bouncer already run on your server, for example the Nginx, Traefik or firewall bouncer. If not, follow the CrowdSec quickstart first.

Read the Hub log

Tell CrowdSec where to find the log of the Hub. Add a file to the acquis.d directory of CrowdSec, usually /etc/crowdsec/acquis.d/. If you use the default docker-compose.yml, the Hub log is read from the container:

/etc/crowdsec/acquis.d/orcacd.yaml
source: docker
container_name:
  - orca-hub
labels:
  type: orcacd

If CrowdSec runs in a container itself, mount the Docker socket (/var/run/docker.sock) read-only into it.

Add the parser

The parser reads the JSON lines of the Hub and ignores all lines that are not security events.

/etc/crowdsec/parsers/s01-parse/orcacd-logs.yaml
onsuccess: next_stage
name: custom/orcacd-logs
description: Parse the security events of the OrcaCD Hub
filter: "evt.Line.Labels.type == 'orcacd' && JsonExtract(evt.Line.Raw, 'category') == 'security'"
statics:
  - meta: log_type
    value: orcacd_security
  - meta: service
    value: orcacd
  - meta: source_ip
    expression: JsonExtract(evt.Line.Raw, "client_ip")
  - meta: orcacd_event
    expression: JsonExtract(evt.Line.Raw, "event")
  - meta: orcacd_reason
    expression: JsonExtract(evt.Line.Raw, "reason")
  - meta: orcacd_email
    expression: JsonExtract(evt.Line.Raw, "email")
  - meta: orcacd_agent
    expression: JsonExtract(evt.Line.Raw, "agent_id")

Add the scenarios

A scenario describes when CrowdSec reports an IP. Below you find multiple recommended scenario you can add in /etc/crowdsec/scenarios. Misconfigured Agents and Git providers cause events as well. Whitelist them or fix their configuration, otherwise you ban your own hosts.

We also recommend to block large amounts of rate limited requests by checking the logs of your reverse proxy for HTTP 429.

Reload CrowdSec

Restart CrowdSec so it loads the new files:

sudo systemctl restart crowdsec

Test the setup

Check that a log line is understood by the parser and matches a scenario:

cscli explain --type orcacd --log '{"level":"warn","service":"hub","category":"security","event":"login_failed","client_ip":"203.0.113.7","method":"POST","path":"/api/v1/auth/login","reason":"wrong_password","email":"admin@example.com","message":"security event"}'

The output should show that the line was parsed by custom/orcacd-logs and that source_ip is 203.0.113.7. To see real events afterward, use cscli metrics show acquisition and cscli alerts list.

Last updated on

On this page