CrowdSec IPS Business Continuity
CrowdSec IPS Business Continuity HA Setup Bouncer LAPI CAPI Community Blocklist Brute Force DDoS Web Attack Kubernetes Production
| Component | Role | HA Strategy | Failure Impact |
|---|---|---|---|
| CrowdSec Agent | Log Analysis + Detection | DaemonSet ทุก Node | ไม่ตรวจจับ Attack บน Node นั้น |
| LAPI Server | Decision Management | Multi-instance + LB | ไม่มี Decision ใหม่ (Cache ยังทำงาน) |
| Bouncer | Block Traffic | ทุก Node + Cache | ไม่ Block IP ใหม่ (Cache ยังทำงาน) |
| CAPI | Community Blocklist | CrowdSec Managed | ไม่ได้ Community Data (Local ยังทำงาน) |
| Database | Decision Storage | PostgreSQL Replication | สูญเสีย Decision History |
Installation & Configuration
# === CrowdSec Installation ===
# Install CrowdSec
# curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | sudo bash
# sudo apt install crowdsec
# sudo apt install crowdsec-firewall-bouncer-iptables
# Install Collections
# sudo cscli collections install crowdsecurity/linux
# sudo cscli collections install crowdsecurity/nginx
# sudo cscli collections install crowdsecurity/sshd
# sudo cscli collections install crowdsecurity/http-cve
# Acquisition Config (/etc/crowdsec/acquis.yaml)
# filenames:
# - /var/log/nginx/access.log
# - /var/log/nginx/error.log
# labels:
# type: nginx
# ---
# filenames:
# - /var/log/auth.log
# labels:
# type: syslog
# Check Status
# sudo cscli metrics
# sudo cscli alerts list
# sudo cscli decisions list
# sudo cscli bouncers list
from dataclasses import dataclass
@dataclass
class CrowdSecCollection:
name: str
detects: str
log_source: str
scenarios: str
collections = [
CrowdSecCollection("crowdsecurity/linux",
"SSH Brute Force, SU Abuse",
"/var/log/auth.log",
"ssh-bf ssh-slow-bf su-spam"),
CrowdSecCollection("crowdsecurity/nginx",
"HTTP Flood, Path Traversal, Scanner",
"/var/log/nginx/access.log",
"http-bf http-crawl-non_statics http-path-traversal"),
CrowdSecCollection("crowdsecurity/sshd",
"SSH Brute Force Advanced",
"/var/log/auth.log",
"ssh-bf ssh-slow-bf ssh-cve"),
CrowdSecCollection("crowdsecurity/http-cve",
"Known CVE Exploits (Log4j, etc)",
"Web Server Logs",
"http-cve-xxxx various CVE detections"),
CrowdSecCollection("crowdsecurity/apache2",
"Apache HTTP Attack Patterns",
"/var/log/apache2/access.log",
"http-bf http-crawl http-scan"),
]
print("=== Collections ===")
for c in collections:
print(f" [{c.name}]")
print(f" Detects: {c.detects}")
print(f" Log: {c.log_source}")
print(f" Scenarios: {c.scenarios}")
HA Architecture
# === CrowdSec HA Setup ===
# Multi-instance Architecture
# Agent (Node 1) ──┐
# Agent (Node 2) ──┤──→ LAPI Server (Primary) ──→ PostgreSQL (Primary)
# Agent (Node 3) ──┘ │ │
# LAPI Server (Secondary) ──→ PostgreSQL (Replica)
# │
# Bouncer (Node 1) ←─────────┤
# Bouncer (Node 2) ←─────────┤
# Bouncer (Node 3) ←─────────┘
# LAPI Server Config (/etc/crowdsec/config.yaml)
# db_config:
# type: postgresql
# user: crowdsec
# password: secret
# db_name: crowdsec
# host: postgresql-primary
# port: 5432
#
# api:
# server:
# listen_uri: 0.0.0.0:8080
# Agent Registration
# sudo cscli lapi register -u http://lapi-server:8080
# sudo cscli machines add agent-node1 --url http://lapi-server:8080
# Bouncer Registration
# sudo cscli bouncers add firewall-bouncer-node1
@dataclass
class HAComponent:
component: str
instances: str
failover: str
recovery_time: str
data_loss: str
ha_components = [
HAComponent("LAPI Server",
"2+ instances behind Load Balancer",
"LB ตัด Instance ที่ล่ม ส่งไป Instance อื่น",
"< 30 วินาที (Health Check interval)",
"ไม่สูญเสีย (Shared Database)"),
HAComponent("CrowdSec Agent",
"1 per Node (DaemonSet)",
"ถ้า Agent ล่ม Node นั้นไม่มี Detection",
"Restart อัตโนมัติ < 1 นาที",
"สูญเสีย Log ระหว่าง Restart"),
HAComponent("Bouncer",
"1 per Node",
"Cache Mode ถ้า LAPI ล่ม ใช้ Decision เก่า",
"Cache ทำงานทันที ไม่มี Downtime",
"ไม่ได้ Decision ใหม่จนกว่า LAPI กลับ"),
HAComponent("Database (PostgreSQL)",
"Primary + Replica",
"Promote Replica เป็น Primary",
"1-5 นาที (Manual/Auto Failover)",
"RPO ขึ้นกับ Replication Lag"),
HAComponent("CAPI (Central API)",
"CrowdSec Managed (Multi-region)",
"CrowdSec จัดการ Redundancy",
"< 5 นาที",
"Community Blocklist อาจ Stale"),
]
print("=== HA Components ===")
for h in ha_components:
print(f" [{h.component}] Instances: {h.instances}")
print(f" Failover: {h.failover}")
print(f" Recovery: {h.recovery_time} | Data Loss: {h.data_loss}")
Monitoring & DR
# === Monitoring & Disaster Recovery ===
@dataclass
class DRAction:
scenario: str
detection: str
response: str
recovery: str
dr_actions = [
DRAction("Agent ล่ม",
"Prometheus: crowdsec_agent_up=0",
"Alert Slack → Auto-restart (systemd/k8s)",
"Restart Agent < 1 นาที ตรวจ Log Parsing กลับปกติ"),
DRAction("LAPI ล่มทั้งหมด",
"Prometheus: crowdsec_lapi_up=0 / HTTP 503",
"Alert PagerDuty → Bouncer ใช้ Cache → Fix LAPI",
"Restore LAPI จาก Backup Config + DB Restore"),
DRAction("Database ล่ม",
"PostgreSQL: connection refused",
"Promote Replica → Update LAPI Config",
"Failover < 5 นาที Rebuild Replica"),
DRAction("Bouncer ล่ม",
"iptables rules หาย / nginx ไม่ block",
"Alert → Restart Bouncer → Verify Rules",
"Restart + cscli decisions list ตรวจ Rules กลับ"),
DRAction("ถูก Attack หนัก (DDoS)",
"Alert volume > 1000/min",
"เพิ่ม Scenario Sensitivity → Cloudflare Bouncer → Rate Limit",
"ตรวจ Bandwidth → Scale Infrastructure → Post-mortem"),
DRAction("Config เสียหาย",
"CrowdSec ไม่ Start / Parse Error",
"Restore Config จาก Git → Restart",
"git checkout Config → systemctl restart crowdsec"),
]
print("=== DR Actions ===")
for d in dr_actions:
print(f"\n [{d.scenario}]")
print(f" Detect: {d.detection}")
print(f" Response: {d.response}")
print(f" Recovery: {d.recovery}")
เคล็ดลับ
- PostgreSQL: ใช้ PostgreSQL แทน SQLite สำหรับ Production
- Cache: Bouncer Cache ช่วยให้ทำงานต่อเมื่อ LAPI ล่ม
- Git: เก็บ Config Scenario Acquisition ใน Git ทั้งหมด
- CAPI: ลงทะเบียน CAPI ได้ Community Blocklist ฟรี
- Monitor: ตั้ง cscli metrics + Prometheus ดูสถานะทุก Component
การนำไปใช้งานจริงในองค์กร
สำหรับองค์กรขนาดกลางถึงใหญ่ แนะนำให้ใช้หลัก Three-Tier Architecture คือ Core Layer ที่เป็นแกนกลางของระบบ Distribution Layer ที่ทำหน้าที่กระจาย Traffic และ Access Layer ที่เชื่อมต่อกับผู้ใช้โดยตรง การแบ่ง Layer ชัดเจนช่วยให้การ Troubleshoot ง่ายขึ้นและสามารถ Scale ระบบได้ตามความต้องการ
เรื่อง Network Security ก็สำคัญไม่แพ้กัน ควรติดตั้ง Next-Generation Firewall ที่สามารถ Deep Packet Inspection ได้ ใช้ Network Segmentation แยก VLAN สำหรับแต่ละแผนก ติดตั้ง IDS/IPS เพื่อตรวจจับการโจมตี และทำ Regular Security Audit อย่างน้อยปีละ 2 ครั้ง
CrowdSec คืออะไร
Open Source IPS Crowd-sourced Log Analysis Brute Force DDoS Scenario Bouncer LAPI CAPI Community Blocklist iptables nginx Free
ติดตั้งอย่างไร
apt install crowdsec Bouncer iptables cscli collections install acquis.yaml Log Source metrics alerts decisions Docker Kubernetes
HA Setup ทำอย่างไร
Multi-instance LAPI Load Balancer PostgreSQL Replication Agent DaemonSet Bouncer Cache Mode CAPI Redundancy Health Check Failover
Business Continuity ทำอย่างไร
Backup Decision DB Bouncer Cache LAPI Failover CAPI Fallback Git Config Prometheus Monitor Alert DR Plan Runbook Drill Test
สรุป
CrowdSec IPS Business Continuity HA LAPI Bouncer Cache PostgreSQL Replication CAPI Community Monitoring DR Plan Production
