2.3.0-beta.1: CrowdSec AppSec
A beta of 2.3, to try CrowdSec's WAF, AppSec, behind HAProxy (requested in #30). Until now the CrowdSec integration covered bans and captchas by address only. With an AppSec URL set, the bouncer on each node also sends every request to your AppSec listener, and a request one of its rules matches gets the 403 ban page, whoever sent it.
Nothing changes for an installation that leaves the AppSec URL empty.
Getting the beta
- Updates page: tick Also offer beta versions, then update.
- Docker:
ghcr.io/avandeputte/haproxy-manager:2.3.0-beta.1 install.sh: the usual command with--ref beta.
Setting it up
On the CrowdSec host, install the rules and add a listener the nodes can reach. CrowdSec's own guide binds it to 127.0.0.1; here the bouncers run on the haproxy-manager nodes, so use the host's LAN address.
sudo cscli collections install crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules/etc/crowdsec/acquis.d/appsec.yaml, then sudo systemctl restart crowdsec:
appsec_configs:
- crowdsecurity/appsec-default
labels:
type: appsec
listen_addr: 192.168.1.5:7422
source: appsecOn haproxy-manager, under Access › CrowdSec:
- Fill in AppSec URL, such as
http://192.168.1.5:7422/. - Press Test the AppSec connection. It asks AppSec about one harmless request from this node and says whether AppSec answers and accepts the key. There is no second key: the bouncer uses its LAPI key.
- Save, then Apply.
To see it work, request something a rule matches:
curl -I http://your-service.example.com/.env # HTTP/1.1 403 Forbidden
sudo cscli metrics show appsec # on the CrowdSec hostWhat to know
-
Bodies over about 50 kB are not inspected. HAProxy hands the bouncer a request in one frame of at most 64 kB. A larger request is still judged on its path, query and headers, but not on its body. Refuse bodies too large to inspect answers such requests with 413 instead. It is off by default, because it also refuses every upload over 50 kB on every HTTP service.
-
AppSec applies to every HTTP service. There is no switch per service. To excuse one application, use a hook on the CrowdSec host. This one lets every request for one hostname through; put it in
/etc/crowdsec/appsec-configs/exempt.yaml, add- custom/exemptunderappsec_configsin the listener file, and restart CrowdSec:name: custom/exempt on_match: - filter: req.Host == "app.example.com" apply: - SetRemediation("allow") - CancelAlert()
-
Addresses on the Never ask about lists skip AppSec too.
-
If AppSec does not answer, requests are served. The bouncer waits 200 ms for AppSec, then judges the request on its address alone.
-
An
https://AppSec URL needs a certificate the node trusts. The CA has to be in the node's system store, and the bouncer and haproxy-manager restarted after it is added. Skip TLS verification applies to the LAPI only. With an untrusted certificate nothing is inspected; the test button reports certificate verify failed. -
A challenge becomes a ban. An AppSec configuration that asks for a JavaScript challenge gets a 403 here.
Fixed along the way
- Docker: a changed bouncer setting was not loaded until the container restarted. The image reported a running bouncer as failed, so Apply "started" it instead of restarting it. A new API key, captcha key or contact URL now takes effect at Apply.
- The bouncer now installs on a minimised system. On a system that leaves
/usr/share/docout (a slim container image, Ubuntu minimal), the bouncer's package stayed half-configured and made every lateraptrun fail.
Tested
Against CrowdSec 1.8.2 with AppSec, on the container image (HAProxy 3.4) and on Debian 13 under systemd (HAProxy 3.0), with bouncer 0.4.0. Not tried: RPM systems, and a cluster of mixed versions.