CrowdSec: collaborative intrusion prevention
แทน fail2ban ด้วย CrowdSec — shared blocklists, dashboard ทันสมัย และ bouncer ที่ผูกกับ Caddy และ iptables
CrowdSec: collaborative intrusion prevention
fail2ban ใช้ได้ แต่มันเดี่ยว — ทุกเซิร์ฟเวอร์เห็น SSH brute-force attempts เดียวกันแบบแยกกัน CrowdSec แก้ปัญหานั้น: เมื่อเซิร์ฟเวอร์หนึ่ง ban IP, ทุก CrowdSec users ได้ประโยชน์จาก shared blocklist
ติดตั้ง
curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | sudo bash
apt install -y crowdsec
apt install -y crowdsec-caddy-bouncer
CrowdSec auto-detect services ที่รันอยู่และ activate parsers สำหรับ setup พื้นฐานมันจะ parse SSH, Caddy, และ Nginx logs ทันที
ตรวจสอบ
sudo cscli metrics
sudo cscli decisions list
sudo cscli alerts list
คุณจะเห็น SSH brute-force attempts แรกภายในไม่กี่นาที
มันทำงานยังไง
- Parsers อ่าน service logs (sshd, nginx, caddy, etc.)
- Scenarios match patterns (เช่น
ssh-bf= brute force) - Decisions ถูกสร้าง (ban IP 4 ชั่วโมง เป็น default)
- Bouncers enforce decisions (drop packets, return 403)
- Community blocklist แชร์ anonymized signals กับทุกคน
ปรับ bouncer สำหรับ Caddy
Caddy bouncer เป็น Caddy module แก้ Caddyfile:
{
order crowdsec first
}
example.com {
crowdsec
reverse_proxy app:8080
}
Reload Caddy IP ที่ถูก ban จะถูก reject ที่ TLS handshake — ก่อนจะ hit app ของคุณเลย
Console (optional)
CrowdSec console ฟรี dashboard มีแผนที่ของ attacks, top offenders, security posture สมัครแล้ว enroll instance:
sudo cscli console enroll <your-enrollment-key>
optional แต่ดีสำหรับ visibility
ทำไมไม่ใช้ fail2ban ต่อ?
- Shared intelligence: ban ของ user หนึ่งปกป้องทุกคน
- เร็วกว่า: Bouncer block ได้ที่ L4 (iptables) หรือ L7 (Caddy)
- Modern stack: HTTP API, dashboard, metric export
- Logs ดีกว่า: Structured alerts ไม่ใช่ raw regex
สำหรับ server เดียว fail2ban ก็พอ สำหรับ 3+ servers CrowdSec คุ้มที่จะ switch