Cloud Armor — WAF, OWASP CRS & Adaptive Protection
Tại sao quan trọng trong production
Cloud Armor là điểm phòng thủ đầu tiên cho traffic từ internet vào ứng dụng GCP. Không giống VPC firewall rules (enforce tại vNIC của VM), Cloud Armor enforce tại edge của Google's network infrastructure — trước khi traffic thậm chí đến Google Cloud region, trước khi đến load balancer backend.
Điều này có một hệ quả quan trọng: với DDoS attacks ở quy mô lớn (hàng Tbps volumetric, hàng triệu requests/giây L7), nếu bạn đợi traffic đến application server rồi mới filter, application đã bị overwhelm. Cloud Armor scrub traffic ở edge — nơi Google có capacity để absorb và filter trước khi forward traffic sạch vào VPC.
Nhưng Cloud Armor không phải silver bullet. Hiểu tại sao và ở đâu nó enforce là critical để không có security gap.
Internal Model — Enforce Tại GFE Edge
Vị trí trong data path
Cloud Armor chỉ hoạt động với proxy-mode load balancers — không phải passthrough. Lý do cơ học:
Passthrough LBs (Network LB, Internal Passthrough LB) không terminate connections — packets đi thẳng đến backend, chỉ thay đổi MAC address ở L2. Không có "proxy" để inspect HTTP headers hay apply WAF rules.
Proxy-mode LBs terminate connection tại GFE (Google Front End) hoặc Envoy proxy. GFE/Envoy là nơi Cloud Armor policy được evaluate — sau khi TLS terminated, trước khi request được forward đến backend.
Internet Request
│
▼
Google Edge PoP (Anycast)
│
▼
GFE (proxy termination)
│
▼ ← Cloud Armor policy evaluated HERE
│ (allow / deny / rate-limit)
▼
GKE/VM BackendCloud Armor security policies được attach trực tiếp vào backend services của load balancer, không phải frontend:
Forwarding Rule → Target Proxy → URL Map → Backend Service ← Cloud Armor PolicyLý do attach tại backend service (không phải frontend): vì một LB có thể có nhiều backend services với security requirements khác nhau. API backend (/api/*) có thể cần WAF strict hơn, còn static content backend (/static/*) chỉ cần DDoS protection cơ bản.
Rule evaluation model
Cloud Armor security policy là một ordered list của rules. Mỗi rule có:
- Priority: integer, số nhỏ = độ ưu tiên cao hơn
- Match condition: expression language matching request attributes
- Action:
allow,deny(HTTP_STATUS),rate_based_ban,throttle,redirect
rules:
- priority: 1000
match:
expr:
expression: "evaluatePreconfiguredWaf('sqli-v33-stable')"
action: "deny(403)"
description: "Block SQLi attacks"
- priority: 2000
match:
expr:
expression: "origin.region_code == 'CN'"
action: "deny(403)"
description: "Block traffic from China"
- priority: 2147483647 # Default rule (max priority = lowest precedence)
match:
expr:
expression: "true"
action: "allow"
description: "Allow all other traffic"Default rule bắt buộc: mọi security policy phải có một default rule ở priority 2147483647 (int max). Rule này match tất cả traffic không được match bởi các rules có priority cao hơn. Action của default rule quyết định "fail-open" (allow) hay "fail-closed" (deny).
Request attributes có thể match
Cloud Armor rule expressions có thể match trên:
request.path: URL pathrequest.method: GET, POST, v.v.request.headers["User-Agent"]: HTTP headersorigin.ip: source IPorigin.region_code: geolocation country coderequest.body: POST body (giới hạn 8KB đầu)has(request.headers["X-Custom-Header"]): kiểm tra header tồn tại
Language: Common Expression Language (CEL) — cùng language được dùng trong IAM Conditions và Kubernetes admission policies.
Preconfigured WAF Rules — OWASP CRS
ModSecurity Core Rule Set
Cloud Armor preconfigured WAF rules dựa trên OWASP ModSecurity Core Rule Set (CRS) — tiêu chuẩn industry cho web application firewall. Phiên bản hiện tại được support là CRS 4.x (phiên bản mới nhất, recommend dùng).
Preconfigured rules cover các attack categories:
| Category | Expression Function | Attacks Covered |
|---|---|---|
| SQL Injection | evaluatePreconfiguredWaf('sqli-v33-stable') | SQLi, blind SQLi, time-based |
| XSS | evaluatePreconfiguredWaf('xss-v33-stable') | Reflected, stored, DOM-based XSS |
| Remote File Inclusion | evaluatePreconfiguredWaf('rfi-v33-stable') | Remote file inclusion |
| Local File Inclusion | evaluatePreconfiguredWaf('lfi-v33-stable') | Path traversal, LFI |
| Remote Code Execution | evaluatePreconfiguredWaf('rce-v33-stable') | RCE, command injection |
| Method Enforcement | evaluatePreconfiguredWaf('methodenforcement-v33-stable') | Allowed HTTP methods |
| Scanner Detection | evaluatePreconfiguredWaf('scannerdetection-v33-stable') | Web scanners, crawlers |
| Protocol Attack | evaluatePreconfiguredWaf('protocolattack-v33-stable') | HTTP protocol abuse |
| PHP | evaluatePreconfiguredWaf('php-v33-stable') | PHP injection attacks |
Sensitivity Levels (Paranoia Levels)
Mỗi preconfigured WAF rule set có sensitivity levels từ 0 đến 4, tương ứng với OWASP paranoia levels:
- Level 1: ít false positives nhất, chỉ detect attacks rõ ràng nhất
- Level 2: cân bằng giữa detection rate và false positives
- Level 3: aggressive detection, có thể block legitimate traffic
- Level 4: maximum sensitivity, nhiều false positives nhất
Default là level 4 (tất cả signatures enabled). Trong production, bắt đầu từ level 1 và tăng dần sau khi verify false positive rate.
Để set sensitivity level:
- priority: 1000
match:
expr:
expression: "evaluatePreconfiguredWaf('sqli-v33-stable', {'sensitivity': 1})"
action: "deny(403)"Tuning — Exclude Specific Signatures
Khi một preconfigured rule gây false positives cho specific legitimate traffic, thay vì disable toàn bộ rule set, có thể exclude specific signatures:
- priority: 1000
match:
expr:
expression: "evaluatePreconfiguredWaf('sqli-v33-stable', {'sensitivity': 2, 'opt_out_rule_ids': ['owasp-crs-v030301-id942140-sqli', 'owasp-crs-v030301-id942160-sqli']})"
action: "deny(403)"Hoặc dùng preconfigured expression set với sensitivity: 0 (disable rule set) kết hợp với opt-in specific signatures:
expression: "evaluatePreconfiguredWaf('sqli-v33-stable', {'sensitivity': 0, 'opt_in_rule_ids': ['owasp-crs-v030301-id942140-sqli']})"Rate Limiting — Kiểm Soát Request Volume
Cloud Armor rate limiting không phải chỉ để chống DDoS — nó còn hữu ích cho:
- Prevent abuse API endpoints (credential stuffing, brute force)
- Enforce fair use giữa các clients
- Protect backend khỏi burst traffic
Các actions rate limiting
throttle: giới hạn request rate. Khi client vượt threshold, requests bị drop cho đến khi rate xuống dưới threshold.
- priority: 3000
match:
versioned_expr: SRC_IPS_V1
config:
src_ip_ranges: ["0.0.0.0/0"]
action: throttle
rate_limit_options:
rate_limit_threshold:
count: 100
interval_sec: 60
conform_action: allow
exceed_action: deny(429)
enforce_on_key: IPrate_based_ban: khi client vượt threshold, ban IP đó cho một duration cụ thể.
action: rate_based_ban
rate_limit_options:
rate_limit_threshold:
count: 50
interval_sec: 60
ban_threshold:
count: 1000
interval_sec: 600
ban_duration_sec: 600
enforce_on_key: IPEnforce keys
enforce_on_key quyết định cách group requests để tính rate:
IP: per source IP (phổ biến nhất)ALL: tổng tất cả requests (global rate limit)HTTP_HEADER: group theo một specific header value (ví dụ: API key header)HTTP_COOKIE: group theo cookie valueXFF_IP: X-Forwarded-For IP (cho deployments phía sau reverse proxy)HTTP_PATH: group theo URL pathSNI: group theo TLS SNI
Với credential stuffing (brute force với nhiều accounts), IP enforcement có thể bị bypass nếu attacker dùng nhiều IPs. Kết hợp với HTTP_PATH enforcement cho /login endpoint là effective hơn.
Adaptive Protection — ML-Based L7 DDoS Detection
Vấn đề mà Adaptive Protection giải quyết
L7 DDoS attacks khó phòng thủ vì từng request trông "hợp lệ" theo HTTP standard. Không có single IP, không có obvious malformed request. Attacker dùng botnet với hàng nghìn IPs, mỗi IP gửi vài requests — dưới threshold rate limiting thông thường.
Adaptive Protection sử dụng ML để phát hiện patterns trong aggregate traffic, không phải trong từng request riêng lẻ.
Cơ chế ML model
Training phase: khi enable Adaptive Protection cho một backend service, hệ thống observe traffic trong ít nhất 1 giờ để build baseline model. Model learn:
- Typical request rate từ các regions
- Distribution của User-Agent headers
- Typical request patterns (paths, headers, methods)
- Referrer patterns
Ongoing monitoring: sau training, model continuously monitor traffic và so sánh với baseline theo nhiều dimensions (IP, header, geography). Nếu một combination của attributes xuất hiện với tần suất cao bất thường (anomalous relative to baseline), model flag đó là potential attack.
Detection signal: model tính confidence score (0 đến 1) cho mỗi potential attack. Score cao = model tự tin đây là attack. Score thấp = uncertain.
Model không process raw request content hay IP addresses trong training data — theo GCP documentation: "The actual features used by the models are derived statistical properties... the training data for the models do not include the actual values of any metadata, such as IP addresses."
Alert và signature generation
Khi anomaly được detect với confidence đủ cao, Adaptive Protection:
Generate alert với:
- Attack signature (set of attributes mô tả attack traffic)
- Confidence score (0–1)
- Impact estimate (% traffic bị ảnh hưởng)
- Baseline traffic stats
Generate rule suggestion — Cloud Armor expression để block attack traffic mà không block legitimate traffic
Log alert vào Cloud Logging dưới resource type
network_security_policy
Automated rule deployment
Để tự động apply suggested rules khi Adaptive Protection phát hiện attack:
- priority: 10000
match:
expr:
expression: "evaluateAdaptiveProtectionAutoDeploy()"
action: "deny(403)"
preview: false # true = preview mode, không actually blockevaluateAdaptiveProtectionAutoDeploy() tự động evaluate tất cả active attack signatures và return true cho requests matching attack traffic.
Cẩn trọng với auto-deploy: nên bắt đầu với preview: true để quan sát rule sẽ match gì trước khi enable block action.
Khi nào Adaptive Protection hoạt động tốt và khi nào không
Hoạt động tốt:
- Attacks với duration đủ dài để model detect (vài phút)
- Attacks có clear pattern phân biệt với legitimate traffic
- Services với stable traffic baseline (traffic patterns không thay đổi nhiều)
Không hoạt động tốt:
- Short burst attacks (dưới vài phút — chưa đủ time để trigger alert)
- Attacks simulation legitimate user behavior perfectly
- Services mới (chưa đủ baseline)
- Services có highly variable traffic (baseline không ổn định)
Edge Security Policies — Cho Passthrough LB
Cloud Armor có một tier riêng cho Network LB (passthrough) gọi là Network Edge Security Services. Đây không phải L7 WAF mà là L3/L4 DDoS mitigation ở edge, bảo vệ:
- External Network LB (passthrough)
- Protocol Forwarding
- Các services không có proxy layer
Lưu ý: không có preconfigured WAF rules hay L7 capabilities trong Network Edge Security.
Constraints & Anti-Patterns
Không thể protect internal services
Cloud Armor không thể attach vào internal LBs (Internal Application LB kết hợp proxy-only subnet). Nó chỉ bảo vệ external-facing services. Cho internal service protection, dùng VPC firewall rules, Cloud NGFW, hoặc IAP (Identity-Aware Proxy).
XML body parsing không được support
Theo GCP documentation, WAF rules không thể parse XML body. Nếu application nhận XML request và cần protect against XML-based attacks (XXE, XML injection), cần handle ở application layer hoặc dùng WAF appliance riêng.
Rule conflicts và priority management
Một anti-pattern phổ biến: tạo nhiều rules overlapping nhau mà không track priority cẩn thận. Khi deny(403) rule ở priority 500 và allow rule ở priority 600 cho cùng traffic, priority 500 thắng → traffic bị block. Phải luôn model "effective policy" từ góc nhìn priority ordering, không phải nhìn từng rule riêng lẻ.
Adaptive Protection cần cold start
Nếu attack xảy ra ngay sau khi service mới launch (không có baseline), Adaptive Protection không có đủ context để detect. Đây là lý do cần manual rules (preconfigured WAF, rate limiting) làm baseline protection, không dựa hoàn toàn vào Adaptive Protection.