AWS WAF (Web Application Firewall)
Web Application Firewall, Web ACLs, Bot Control, Fraud Control, Shield Integration
Giới thiệu
AWS WAF là Web Application Firewall giúp bảo vệ ứng dụng web và API khỏi các web exploits phổ biến như SQL injection, XSS, và các bot độc hại.
WAF bảo vệ khỏi những gì?
Đặc điểm chính
| Đặc điểm | Mô tả |
|---|---|
| Layer | Layer 7 (Application Layer) |
| Managed Service | Fully managed, không cần quản lý infrastructure |
| Real-time | Block requests ngay lập tức |
| Visibility | CloudWatch metrics và logs |
| Flexibility | Custom rules + Managed rules |
Kiến trúc và thành phần
Các thành phần chính
| Thành phần | Mô tả |
|---|---|
| Web ACL | Container chính chứa tất cả rules |
| Rule | Điều kiện kiểm tra request |
| Rule Group | Nhóm nhiều rules lại với nhau |
| IP Set | Danh sách IP addresses để allow/block |
| Regex Pattern Set | Patterns để match request content |
Web ACL
Web ACL (Web Access Control List) là resource chính trong AWS WAF, chứa các rules để inspect và quyết định action cho mỗi request.
Actions
| Action | Mô tả | Khi nào dùng |
|---|---|---|
| ALLOW | Cho phép request đi qua | Whitelist IPs, known good traffic |
| BLOCK | Chặn request, trả về 403 | Malicious requests |
| COUNT | Đếm nhưng không block | Testing rules trước khi enforce |
| CAPTCHA | Yêu cầu giải CAPTCHA | Nghi ngờ bot |
| Challenge | JavaScript challenge | Silent bot detection |
Web ACL Capacity Units (WCUs)
Mỗi rule tiêu thụ một lượng WCU nhất định. Web ACL có giới hạn 1,500 WCUs mặc định.
Rules và Rule Groups
Các loại Rules
1. Regular Rules
Match dựa trên conditions như IP, headers, body, query string...
2. Rate-based Rules
Block IP khi vượt quá threshold requests trong khoảng thời gian.
3. Rule Groups
Nhóm nhiều rules lại với nhau để tái sử dụng.
| Loại | Mô tả |
|---|---|
| AWS Managed | Rules do AWS tạo và maintain |
| AWS Marketplace | Rules từ third-party vendors |
| Your Own | Custom rule groups bạn tự tạo |
Managed Rules
Managed Rules là các rule groups được cấu hình sẵn, tự động update bởi AWS hoặc vendors.
AWS Managed Rule Groups
Lựa chọn Managed Rules
| Ứng dụng | Recommended Rule Groups |
|---|---|
| Mọi web app | Core Rule Set, Known Bad Inputs |
| WordPress | + WordPress Rule Set |
| PHP app | + PHP Rule Set |
| Linux server | + Linux Rule Set |
| API | + API Gateway optimized rules |
| Admin panels | + Admin Protection |
Bot Control
AWS WAF Bot Control giúp phát hiện và quản lý bot traffic.
Hai mức độ
Bot Categories
| Category | Ví dụ | Action thường dùng |
|---|---|---|
| Verified Bots | Googlebot, Bingbot | ALLOW |
| Unverified Bots | Unknown crawlers | COUNT or BLOCK |
| Good Bots | Monitoring tools | ALLOW |
| Bad Bots | Scrapers, spammers | BLOCK |
Fraud Control
Fraud Control bảo vệ login và signup pages khỏi các cuộc tấn công fraud.
Hai features chính
Integration với AWS Services
Supported Resources
| Service | Region | Notes |
|---|---|---|
| Amazon CloudFront | Global (us-east-1) | CDN protection |
| Application Load Balancer | Regional | Web app protection |
| Amazon API Gateway | Regional | REST API protection |
| AWS AppSync | Regional | GraphQL API protection |
| Amazon Cognito | Regional | User pool protection |
| AWS App Runner | Regional | Container apps |
| AWS Verified Access | Regional | Zero trust |
Ví dụ tích hợp với CloudFront
So sánh WAF vs Shield vs Firewall Manager
So sánh chi tiết
| Tiêu chí | AWS WAF | Shield Standard | Shield Advanced | Firewall Manager |
|---|---|---|---|---|
| Layer | 7 | 3, 4 | 3, 4, 7 | N/A (management) |
| DDoS | L7 only | L3/L4 basic | L3/L4/L7 advanced | N/A |
| Web exploits | ✅ | ❌ | ✅ (via WAF) | N/A |
| Cost | Pay-per-use | FREE | $3,000/month | $100/region/month |
| Auto-enabled | ❌ | ✅ | ❌ | ❌ |
| Multi-account | ❌ | ❌ | ✅ | ✅ |
| DRT Support | ❌ | ❌ | ✅ 24/7 | ❌ |
Khi nào dùng gì?
| Scenario | Solution |
|---|---|
| Bảo vệ web app khỏi SQL injection, XSS | WAF |
| DDoS protection cơ bản | Shield Standard (đã có sẵn) |
| Enterprise, high-profile target | Shield Advanced + WAF |
| Nhiều AWS accounts | Firewall Manager |
| VPC network protection | Network Firewall (khác service) |
Pricing
AWS WAF Base Pricing
| Component | Cost |
|---|---|
| Web ACL | $5.00/month |
| Rule | $1.00/month per rule |
| Managed Rule Group | $1.00/month + vendor fee |
| Requests | $0.60/million requests |
| Extra WCUs | $0.20/million requests per 500 WCUs |
Bot Control Pricing
| Level | Free Tier | After Free Tier |
|---|---|---|
| Common | 10M requests/month | $1/million requests |
| Targeted | 1M requests/month | $10/million requests |
Fraud Control Pricing
| Component | Cost |
|---|---|
| Subscription | $10/month per Web ACL |
| Requests | ~$1/1,000 requests |
| Free Tier | 10,000 requests/month |
Ví dụ tính giá
💡 Tip: Nếu dùng Shield Advanced, WAF base costs (Web ACL, rules, requests) được miễn phí cho protected resources!
Best Practices
1. Start with Managed Rules
2. Use COUNT mode first
3. Rule Priority Order
4. Logging
- Enable WAF Logs → S3, CloudWatch Logs, hoặc Kinesis Firehose
- Analyze blocked/counted requests
- Set up CloudWatch alarms for attack detection
Exam Tips
Key Points for AWS Exams
-
WAF = Layer 7 protection
- SQL injection, XSS, bad bots
- Attach to CloudFront, ALB, API Gateway
-
Shield = DDoS protection
- Standard = FREE, auto-enabled
- Advanced = $3,000/month, 24/7 DRT
-
Firewall Manager = Central management
- Across AWS Organization
- Manages WAF, Shield, Security Groups
-
WAF Rules
- Regular rules = match conditions
- Rate-based rules = threshold blocking
- Managed rules = pre-configured, auto-updated
-
Actions
- ALLOW, BLOCK, COUNT
- CAPTCHA và Challenge cho bot detection
Common Exam Scenarios
| Scenario | Answer |
|---|---|
| Block SQL injection | AWS WAF |
| DDoS protection (free) | Shield Standard |
| 24/7 DDoS response team | Shield Advanced |
| Centrally manage WAF across accounts | Firewall Manager |
| Block IPs exceeding request threshold | Rate-based rule |
| Test rules without blocking | COUNT action |
| Protect CloudFront from bots | WAF Bot Control |
| Block traffic from specific countries | Geo Match condition |
Liên kết liên quan
- CloudFront
- API Gateway
- ELB
- AWS Organizations - Firewall Manager
- Security Groups