|
|
| Zeile 8: |
Zeile 8: |
|
| |
|
| ==Modul 2: CrowdSec HAProxy Bouncer== | | ==Modul 2: CrowdSec HAProxy Bouncer== |
| | | *[[CrowdSec HAProxy Bouncer]] |
| CrowdSec läuft als IDS/IPS und kommuniziert über den SPOE-Mechanismus direkt mit HAProxy. Blockentscheidungen werden auf Proxy-Ebene getroffen, bevor der Request das Backend erreicht.
| |
| | |
| ;Voraussetzung: CrowdSec ist installiert und läuft (siehe [[CrowdSec]])
| |
| | |
| ===Installation===
| |
| | |
| *apt install crowdsec-haproxy-bouncer
| |
| | |
| ===SPOE-Konfiguration===
| |
| | |
| Der Bouncer legt automatisch eine SPOE-Konfigurationsdatei an:
| |
| | |
| /etc/haproxy/spoe-crowdsec.conf
| |
| | |
| Inhalt prüfen:
| |
| | |
| *cat /etc/haproxy/spoe-crowdsec.conf
| |
| | |
| <syntaxhighlight lang="text">
| |
| [config]
| |
| spoe-agent crowdsec
| |
| messages check-client-ip
| |
| option var-prefix crowdsec
| |
| timeout hello 100ms
| |
| timeout idle 30s
| |
| timeout processing 50ms
| |
| use-backend crowdsec_backend
| |
| | |
| spoe-message check-client-ip
| |
| args src
| |
| event on-client-session
| |
| </syntaxhighlight>
| |
| | |
| ===HAProxy Konfiguration erweitern===
| |
| | |
| *nano /etc/haproxy/haproxy.cfg
| |
| | |
| Im <code>global</code>-Block ergänzen:
| |
| | |
| <syntaxhighlight lang="text">
| |
| global
| |
| # ... bestehende Einträge ...
| |
| lua-prepend-path /usr/lib/crowdsec/lua/haproxy/?.lua
| |
| lua-load /usr/lib/crowdsec/lua/haproxy/crowdsec.lua
| |
| setenv CROWDSEC_API_KEY <DEIN_BOUNCER_KEY>
| |
| setenv CROWDSEC_API_URL http://127.0.0.1:8080
| |
| </syntaxhighlight>
| |
| | |
| Im <code>frontend ft_https</code> ergänzen:
| |
| | |
| <syntaxhighlight lang="text">
| |
| frontend ft_https
| |
| # ... bestehende Einträge ...
| |
| filter spoe engine crowdsec config /etc/haproxy/spoe-crowdsec.conf
| |
| http-request lua.crowdsec_allow
| |
| http-request deny deny_status 403 if { var(txn.crowdsec.action) -m str "ban" }
| |
| </syntaxhighlight>
| |
| | |
| Backend für den CrowdSec-Agent hinzufügen:
| |
| | |
| <syntaxhighlight lang="text">
| |
| backend crowdsec_backend
| |
| server crowdsec 127.0.0.1:7422
| |
| </syntaxhighlight>
| |
| | |
| ===Bouncer-Key generieren===
| |
| | |
| *cscli bouncers add haproxy-bouncer
| |
| | |
| Den ausgegebenen Key in die HAProxy-Konfiguration unter <code>CROWDSEC_API_KEY</code> eintragen.
| |
| | |
| ===Konfiguration testen und neu laden===
| |
| | |
| *haproxy -c -f /etc/haproxy/haproxy.cfg
| |
| *systemctl reload haproxy
| |
| | |
| ===Test===
| |
| | |
| CrowdSec-Entscheidungen anzeigen:
| |
| | |
| *cscli decisions list
| |
| | |
| Eine Test-IP manuell bannen:
| |
| | |
| *cscli decisions add --ip 10.88.2XX.99 --duration 5m --reason "Test"
| |
| | |
| Vom gebannten Client aus sollte ein HTTP 403 zurückkommen. Ban wieder entfernen:
| |
| | |
| *cscli decisions delete --ip 10.88.2XX.99
| |
| | |
| Logs beobachten:
| |
| | |
| *journalctl -fu haproxy
| |
| *journalctl -fu crowdsec
| |
| | |
| ----
| |
|
| |
|
| ==Modul 3: Coraza WAF via SPOE== | | ==Modul 3: Coraza WAF via SPOE== |
| *[[Coraza WAF via SPOE]] | | *[[Coraza WAF via SPOE]] |
HAProxy Middleware
HAProxy lässt sich durch verschiedene Middleware-Module erweitern, die zwischen Client und Backend Traffic inspizieren, filtern oder transformieren. Die folgenden Module können unabhängig voneinander eingesetzt werden.
Modul 2: CrowdSec HAProxy Bouncer
Modul 3: Coraza WAF via SPOE