HAProxy Crowdsec Workshop: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Zeile 49: Zeile 49:
 
     server mailit113 mail.it113.int:443 ssl verify none
 
     server mailit113 mail.it113.int:443 ssl verify none
 
</pre>
 
</pre>
 +
 
==Check==
 
==Check==
 
*haproxy -c -f /etc/haproxy/haproxy.cfg
 
*haproxy -c -f /etc/haproxy/haproxy.cfg

Version vom 27. März 2025, 18:32 Uhr

Vorbereitung

Nameserver

Wildcard Record anlegen
*.art113.int.		300	IN	A	10.88.113.61

Rechner aufsetzen

  • Hostname: star.art113.int
  • Address: 10.88.113.61/24
  • Nameserver: 10.88.113.21
  • Netz: DMZ

Wildcard Certifikat für *.art113.int

Request erstellen
  • openssl req -new -newkey rsa:4096 -nodes -keyout star.art113.int.key -out star.art113.int.csr -subj "/CN=*.art113.int"
Zu CA schicken dort wird signiert
  • openssl x509 -req -days 730 -in star.art113.int.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out star.art113.int.crt -extfile <(echo "subjectAltName=DNS:*.art113.int")
Empfang des star.art113.int Zertifikat
star.art113.int.crt

HAProxy

Installation

Haproxy und andere Dinge
  • apt install -y haproxy curl

Minimales Szenario

  • HAProxy unter mail.art113.int erreichbar zu machen
  • Anfragen an einen internen Server mailit113.int per HTTPS weiterzuleiten (Reverse Proxy)
  • Das Wildcard-Zertifikat zu verwenden (star.art113.int.pem)

Konfiguration

  • mkdir /etc/haproxy/ssl
  • sudo sh -c 'cat star.art113.int.crt star.art113.int.key > /etc/haproxy/ssl/star.art113.int.pem'

Konfigurations Datei

  • vi /etc/haproxy/haproxy.cfg
global
    daemon

defaults
    mode http
    timeout connect 10s
    timeout client  30s
    timeout server  30s

frontend https-in
    bind *:443 ssl crt /etc/haproxy/star.art113.int.pem
    mode http
    acl host_mail hdr(host) -i mail.art113.int
    use_backend mailit113_backend if host_mail

backend mailit113_backend
    mode http
    server mailit113 mail.it113.int:443 ssl verify none

Check

  • haproxy -c -f /etc/haproxy/haproxy.cfg
Configuration file is valid

Starten, Enablen und Checken

  • systemctl restart haproxy.service
  • systemctl enable haproxy.service
  • ss -lntp | grep 443
LISTEN 0      4096         0.0.0.0:443       0.0.0.0:*    users: (("haproxy",pid=993,fd=6))

Installation der WAF mit CrowdSec für HAProxy

Vorherige Version entfernen und aktuelle installieren

CrowdSec Hub aktualisieren

  • cscli hub update

HAProxy Collection und Parser aktivieren

  • cscli collections install crowdsecurity/haproxy
  • cscli parsers install crowdsecurity/haproxy-logs

Journald-Logverarbeitung aktivieren

  • cscli collections install crowdsecurity/linux-journal-logs

Logging in HAProxy aktivieren

In der Datei /etc/haproxy/haproxy.cfg im defaults-Block ergänzen:

log stdout format raw local0
option httplog

Dienste neu starten

  • systemctl restart haproxy
  • systemctl restart crowdsec

Verarbeitung prüfen

  • cscli metrics | grep haproxy

Angriff simulieren

Bann prüfen

  • cscli decisions list