# Multi-Layer Security Architecture with CrowdSec and OpenAppSec ## ๐Ÿ—๏ธ Infrastructure Overview This document describes a multi-layer security architecture implemented using Incus containers, featuring CrowdSec community-driven threat intelligence and OpenAppSec ML-based WAF protection. ## ๐Ÿ“‹ Container Inventory | Container | IP Address | Role | Technology | |-----------|------------|------|------------| | `ab-test` | 10.90.135.123 | Attack Simulation | curl/testing tools | | `openresty` | 10.90.135.17 | Layer 1 Security | OpenResty + CrowdSec Bouncer | | `crowdsec` | 10.90.135.49 | Threat Intelligence | CrowdSec Engine | | `openappsec` | 10.90.135.186 | Layer 2 Security | ML-based WAF | | `caddy` | 10.90.135.16 | Backend Server | Caddy HTTP Server | | `php-auth` | 10.90.135.83 | Test Endpoint | PHP Authentication Service | ## ๐Ÿ—๏ธ Architecture Diagram ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Incus Container Infrastructure โ”‚ โ”‚ (10.90.135.0/24) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐ŸŒ External Traffic Entry Point โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ ab-test โ”‚ โ† Attack simulation container โ”‚ โ”‚ โ”‚ 10.90.135.123 โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿ›ก๏ธ Layer 1: Community-Driven Threat Intelligence โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ openresty โ”‚โ—„โ”€โ”€โ–บโ”‚ crowdsec โ”‚ โ”‚ โ”‚ โ”‚ 10.90.135.17 โ”‚ โ”‚ 10.90.135.49 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ€ข OpenResty โ”‚ โ”‚ โ€ข Threat Intel โ”‚ โ”‚ โ”‚ โ”‚ โ€ข CrowdSec โ”‚ โ”‚ โ€ข Scenarios โ”‚ โ”‚ โ”‚ โ”‚ Bouncer โ”‚ โ”‚ โ€ข Community DB โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Rate Limiting โ”‚ โ”‚ โ€ข API Server โ”‚ โ”‚ โ”‚ โ”‚ โ€ข IP Blocking โ”‚ โ”‚ โ€ข Log Analysis โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€ nginx-logs โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ (Shared Volume: /var/log/nginx) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿง  Layer 2: ML-Based Application Security โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ openappsec โ”‚ โ”‚ โ”‚ โ”‚ 10.90.135.186 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ€ข ML WAF โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Simple Model โ”‚ โ”‚ โ”‚ โ”‚ V1.0 โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Zero-day โ”‚ โ”‚ โ”‚ โ”‚ Detection โ”‚ โ”‚ โ”‚ โ”‚ โ€ข No Signatures โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿ”— Layer 3: Backend Application Server โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ caddy โ”‚ โ”‚ โ”‚ โ”‚ 10.90.135.16 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ€ข HTTP Server โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Reverse Proxy โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Auto HTTPS โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿงช Supporting Services โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ php-auth โ”‚ โ† Authentication test endpoint โ”‚ โ”‚ โ”‚ 10.90.135.83 โ”‚ (Returns 401 for brute force testing) โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` ## ๐Ÿ“Š Traffic Flow & Security Processing ``` ๐ŸŒ Attack Request โ”‚ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ openresty โ”‚ โ† CrowdSec Bouncer โ”‚ 10.90.135.17 โ”‚ โ€ข Community threat intel โ”‚ โ”‚ โ€ข Behavioral analysis โ”‚ โ”‚ โ€ข IP reputation โ”‚ โ”‚ โ€ข Rate limiting โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โœ… Allowed โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ openappsec โ”‚ โ† ML-based WAF โ”‚ 10.90.135.186 โ”‚ โ€ข Zero-day detection โ”‚ โ”‚ โ€ข ML pattern analysis โ”‚ โ”‚ โ€ข Application-layer security โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โœ… Clean โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ caddy โ”‚ โ† Backend Server โ”‚ 10.90.135.16 โ”‚ โ€ข Content delivery โ”‚ โ”‚ โ€ข Application logic โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` ## ๐Ÿ”’ Security Layers Detail ### Layer 1: CrowdSec Community Intelligence **Container**: `openresty` + `crowdsec` **Key Features**: - ๐ŸŒ Global threat intelligence sharing - ๐Ÿ” HTTP brute force detection (`LePresidente/http-generic-401-bf`) - ๐Ÿ“Š Scenario-based behavioral analysis - โฑ๏ธ Real-time IP blocking (4-hour default ban) - ๐Ÿ”„ Dynamic bouncer integration with OpenResty **Scenarios Enabled**: - `crowdsecurity/http-generic-bf` - Generic HTTP brute force detection - `crowdsecurity/http-admin-interface-probing` - Admin interface scanning - `crowdsecurity/http-probing` - General HTTP probing - `crowdsecurity/http-cve-probing` - CVE exploitation attempts - `crowdsecurity/http-sqli-probing` - SQL injection attempts **Configuration**: ```yaml # CrowdSec Acquisition filenames: - /var/log/nginx/access.log - /var/log/nginx/error.log labels: type: nginx ``` **Acquisition ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐํ™”** (๊ถŒ์žฅ): ```bash # /etc/crowdsec/acquis.d/ ๋””๋ ‰ํ† ๋ฆฌ์— ์„œ๋น„์Šค๋ณ„ ํŒŒ์ผ ๋ถ„๋ฆฌ /etc/crowdsec/acquis.d/ โ”œโ”€โ”€ nginx.yaml # Nginx ๋กœ๊ทธ โ”œโ”€โ”€ apache.yaml # Apache ๋กœ๊ทธ (ํ•„์š”์‹œ) โ”œโ”€โ”€ sshd.yaml # SSH ๋กœ๊ทธ โ””โ”€โ”€ traefik.yaml # Traefik ๋กœ๊ทธ (ํ•„์š”์‹œ) ``` **nginx.yaml ์˜ˆ์‹œ**: ```yaml filenames: - /var/log/nginx/access.log - /var/log/nginx/error.log labels: type: nginx --- # JSON ํ˜•์‹ ๋กœ๊ทธ (๋ณ„๋„ ์ฒ˜๋ฆฌ) filenames: - /var/log/nginx/json_access.log labels: type: nginx format: json ``` **sshd.yaml ์˜ˆ์‹œ**: ```yaml filenames: - /var/log/auth.log labels: type: syslog ``` ### Layer 2: OpenAppSec ML WAF **Container**: `openappsec` **Key Features**: - ๐Ÿง  Machine learning-based attack detection - ๐Ÿ†• Zero-day vulnerability protection - ๐Ÿ“ No signature updates required - โšก Simple Model V1.0 for fast processing - ๐Ÿ”„ Automatic threat adaptation **ML Model**: Simple Model V1.0 - Behavioral analysis - Pattern recognition - Anomaly detection - Real-time learning ### Layer 3: Backend Application **Container**: `caddy` **Key Features**: - ๐Ÿ” Automatic HTTPS with Let's Encrypt - ๐Ÿ”„ Reverse proxy capabilities - ๐Ÿ“ˆ High-performance HTTP/2 support - ๐ŸŽฏ Clean traffic processing ## ๐Ÿงช Testing Infrastructure ### Attack Simulation - **Container**: `ab-test` - **Purpose**: Simulate various attack patterns for testing - **Tools**: curl, custom scripts ### Authentication Endpoint - **Container**: `php-auth` - **Purpose**: Generate 401/403 responses for brute force testing - **Endpoint**: `/login.php` - Always returns 401 Unauthorized ## ๐Ÿ”ง Implementation Details ### Volume Mounts ```bash # Shared nginx logs between openresty and crowdsec nginx-logs: /var/log/nginx ``` ### Network Configuration - **Network**: incus default bridge (10.90.135.0/24) - **Traffic Flow**: ab-test โ†’ openresty โ†’ openappsec โ†’ caddy - **Special Routes**: `/admin/login` โ†’ php-auth (testing) ### Security Configuration #### CrowdSec Bouncer (์ˆ˜๋™ ๋“ฑ๋ก) ```yaml API_URL: http://10.90.135.49:8080 API_KEY: s0ENc/6Tw+6m6tr0Qkjt/WAYU1QlC5/MzH7SQOCJX50 ``` #### Bouncer ์ž๋™ ๋“ฑ๋ก (๊ถŒ์žฅ) > ์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘ ์‹œ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ Bouncer ์ž๋™ ๋“ฑ๋ก. ์ˆ˜๋™ `cscli bouncers add` ๋ถˆํ•„์š”. **ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋ฐฉ์‹**: ```bash # CrowdSec ์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘ ์‹œ Bouncer ์ž๋™ ๋“ฑ๋ก incus launch docker.io/crowdsecurity/crowdsec crowdsec \ --config environment.BOUNCER_KEY_openresty=my-secure-bouncer-key-here \ --config environment.BOUNCER_KEY_firewall=another-bouncer-key-here ``` **Docker Compose ์˜ˆ์‹œ**: ```yaml services: crowdsec: image: crowdsecurity/crowdsec:latest environment: # Bouncer ์ž๋™ ๋“ฑ๋ก (BOUNCER_KEY_=) - BOUNCER_KEY_openresty=${OPENRESTY_BOUNCER_KEY} - BOUNCER_KEY_firewall=${FIREWALL_BOUNCER_KEY} # ์ปฌ๋ ‰์…˜ ์ž๋™ ์„ค์น˜ - COLLECTIONS=crowdsecurity/nginx crowdsecurity/http-cve volumes: - crowdsec-data:/var/lib/crowdsec/data - crowdsec-config:/etc/crowdsec - /var/log/nginx:/var/log/nginx:ro restart: unless-stopped openresty: image: openresty/openresty:latest environment: - CROWDSEC_API_URL=http://crowdsec:8080 - CROWDSEC_API_KEY=${OPENRESTY_BOUNCER_KEY} depends_on: - crowdsec ``` **Docker Secret ๋ฐฉ์‹ (๋” ์•ˆ์ „)**: ```yaml services: crowdsec: image: crowdsecurity/crowdsec:latest secrets: - bouncer_key_openresty - bouncer_key_firewall # Secret ํŒŒ์ผ์€ /run/secrets/bouncer_key_ ์œผ๋กœ ๋งˆ์šดํŠธ๋จ secrets: bouncer_key_openresty: file: ./secrets/openresty_bouncer_key bouncer_key_firewall: file: ./secrets/firewall_bouncer_key ``` ```bash # Secret ํŒŒ์ผ ์ƒ์„ฑ mkdir -p secrets openssl rand -base64 32 > secrets/openresty_bouncer_key openssl rand -base64 32 > secrets/firewall_bouncer_key chmod 600 secrets/* ``` > **์ฃผ์˜**: ํ™˜๊ฒฝ๋ณ€์ˆ˜/Secret ๋ฐฉ์‹์€ ์ดˆ๊ธฐ ๋ฐฐํฌ ์‹œ์—๋งŒ ๋™์ž‘. ๊ธฐ์กด Bouncer ์—…๋ฐ์ดํŠธ๋Š” `cscli` ์‚ฌ์šฉ. #### OpenResty Configuration ```nginx upstream openappsec_backend { server 10.90.135.186:80; } upstream auth_backend { server 10.90.135.83:8080; } server { listen 80; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location /admin/login { proxy_pass http://auth_backend/login.php; } location / { proxy_pass http://openappsec_backend; } } ``` ## โœ… Testing Results ### Successful Test Cases 1. **Brute Force Detection** - โœ… 6 failed login attempts โ†’ CrowdSec alert triggered - โœ… IP `10.90.135.123` automatically banned - โœ… Scenario: `LePresidente/http-generic-401-bf` 2. **IP Blocking** - โœ… Banned IP receives `403 Forbidden` - โœ… Traffic completely blocked at Layer 1 3. **IP Unbanning** - โœ… Manual unban via `cscli decisions delete` - โœ… Immediate traffic restoration 4. **Multi-Layer Coordination** - โœ… OpenResty logs โ†’ CrowdSec analysis - โœ… Real-time threat intelligence updates - โœ… Seamless traffic flow through all layers ### Attack Patterns Tested - HTTP brute force attacks (401 responses) - Multiple rapid authentication attempts - IP-based blocking and recovery ## ๐Ÿš€ Deployment Commands ### Container Management ```bash # List all containers incus list # Start security stack incus start crowdsec openresty openappsec caddy # Monitor CrowdSec incus exec crowdsec -- cscli alerts list incus exec crowdsec -- cscli decisions list incus exec crowdsec -- cscli metrics ``` ### Security Operations ```bash # Ban an IP manually incus exec crowdsec -- cscli decisions add --ip 1.2.3.4 --duration 4h --reason "manual-ban" # Unban an IP incus exec crowdsec -- cscli decisions delete --ip 1.2.3.4 # Check bouncer status incus exec crowdsec -- cscli bouncers list # View real-time logs incus exec openresty -- tail -f /var/log/nginx/access.log ``` ### Testing Commands ```bash # Simulate brute force attack incus exec ab-test -- bash -c 'for i in {1..6}; do curl -X POST http://10.90.135.17/admin/login -d "username=admin&password=wrong$i" sleep 1 done' # Test blocked IP incus exec ab-test -- curl -X POST http://10.90.135.17/admin/login -d "test=blocked" ``` ## ๐Ÿ” Monitoring & Alerting ### CrowdSec Metrics - **Acquisition**: Lines read, parsed, whitelisted - **Scenarios**: Active scenarios, overflows, instantiations - **Decisions**: Active bans, ban duration, ban reasons - **API**: Bouncer heartbeats, decision pulls ### Log Locations - **OpenResty**: `/var/log/nginx/access.log`, `/var/log/nginx/error.log` - **CrowdSec**: Built-in metrics via `cscli metrics` - **OpenAppSec**: Container logs via `incus exec openappsec -- logs` ## ๐Ÿ“š Key Learnings 1. **Whitelist Management**: Internal IP ranges need careful configuration for testing 2. **Log Format Compatibility**: OpenResty logs work well with CrowdSec nginx parsers 3. **Volume Sharing**: Critical for log analysis between containers 4. **Response Codes**: 401/403 responses trigger different CrowdSec scenarios 5. **Real-time Detection**: Sub-minute detection and blocking capabilities ## ๐Ÿ”ฎ Future Enhancements - [ ] Custom CrowdSec scenarios for application-specific attacks - [ ] Integration with external threat intelligence feeds - [ ] Automated incident response workflows - [ ] Performance monitoring and optimization - [ ] Distributed deployment across multiple nodes - [ ] SSL/TLS termination at OpenResty layer - [ ] Rate limiting configuration fine-tuning --- **Created**: 2025-08-17 **Last Updated**: 2025-08-17 **Architecture Version**: 1.0 **Status**: Production Ready โœ