Skip to content

CloudTrail vs CloudWatch vs Config vs GuardDuty vs Security Hub

What — Mỗi service trả lời câu hỏi khác nhau

ServiceCâu hỏi cốt lõiLoại data
CloudTrailAi đã làm gì, lúc nào, từ đâu?API call logs
CloudWatchHệ thống đang hoạt động thế nào?Metrics + logs + alarms
AWS ConfigResource được config như thế nào tại thời điểm X?Configuration snapshots
GuardDutyCó threat/hoạt động bất thường không?Threat intelligence + ML findings
Security HubTổng thể security posture đang ở mức nào?Aggregated findings

Why — Tại sao cần phân biệt?

Cả 5 service đều liên quan đến "monitoring" nhưng ở các tầng khác nhau. Dùng sai = không trả lời được câu hỏi cần thiết khi có incident. DOP-C02 hay hỏi scenario kiểu: "cần audit ai đã xóa S3 bucket" → đáp án là CloudTrail, không phải CloudWatch.

How — Chi tiết từng service

CloudTrail — API audit log

Ghi lại mọi API call đến AWS: ai gọi, service nào, action gì, từ IP nào, lúc mấy giờ, kết quả thành công hay thất bại.

Ai đó xóa S3 bucket lúc 3am
→ CloudTrail log: DeleteBucket, user=john, IP=1.2.3.4, time=03:17:42
  • Lưu vào S3 (long-term archive) + CloudWatch Logs (real-time query/alert)
  • Management events: miễn phí. Data events: tốn phí.
  • Có thể query bằng Athena trực tiếp từ S3

CloudWatch — Operational monitoring

Monitor hiệu năng và health của system. Nhận metrics từ mọi AWS service, tạo alarm, dashboard, log aggregation.

Lambda timeout rate > 5% trong 5 phút
→ CloudWatch Alarm → SNS → email/PagerDuty
  • Metrics: CPU, memory, latency, error rate...
  • Logs: application logs, Lambda logs, VPC Flow Logs
  • Events/EventBridge: trigger action khi có sự kiện

AWS Config — Configuration history

Track trạng thái cấu hình của resource theo thời gian. Trả lời: "S3 bucket này có bật encryption không? Từ bao giờ? Ai thay đổi?"

S3 bucket bật public access lúc 14:00
→ Config ghi lại configuration change
→ Config Rule "s3-bucket-public-read-prohibited" → NON_COMPLIANT
→ Auto-remediation trigger
  • Config Rules: enforce compliance tự động (managed rules + custom Lambda rules)
  • Configuration timeline: xem lịch sử config của từng resource
  • Tốn phí: ~$0.003/configuration item

GuardDuty — Threat detection

Dùng ML + threat intelligence để phát hiện hoạt động bất thường. Phân tích CloudTrail, VPC Flow Logs, DNS logs — nhưng tự động, không cần bạn viết rule.

EC2 instance đột nhiên gửi traffic đến IP thuộc mạng botnet
→ GuardDuty finding: UnauthorizedAccess:EC2/MaliciousIPCaller

Finding types hay gặp:

  • CryptoCurrency:EC2 — instance đang mine crypto
  • UnauthorizedAccess:IAMUser/ConsoleLoginSuccess.B — login từ địa điểm bất thường
  • Recon:EC2/PortProbeUnprotectedPort — port scanning

30 ngày free trial. Sau trial: ~$3–9/tháng cho account nhỏ.

Security Hub — Security posture aggregation

Tổng hợp findings từ GuardDuty, Config, Inspector, Macie vào một dashboard. Không tự detect — chỉ aggregate và score.

GuardDuty finding + Config NON_COMPLIANT + Inspector vulnerability
→ Security Hub: Security score = 67%
→ Dashboard: filter theo severity, account, resource type
  • AWS Foundational Security Best Practices: 200+ security checks
  • Tích hợp EventBridge để auto-remediate findings
  • Quan trọng trong multi-account: Security Hub + AWS Organizations = single view across accounts

Gotchas

  • CloudTrail ≠ CloudWatch: CloudTrail là "ai làm gì", CloudWatch là "system đang ở trạng thái gì". Hay nhầm trong câu hỏi DOP-C02.
  • GuardDuty per-region: Phải bật riêng ở từng region. Dùng AWS Organizations để bật tập trung.
  • Security Hub phụ thuộc data source: Bật Security Hub mà không có GuardDuty/Config → findings rất ít. Thứ tự đúng: GuardDuty → Config → Security Hub.
  • Config không phải real-time: Config record configuration state, không phải activity log. Để biết "ai thay đổi?" cần kết hợp với CloudTrail.
  • CloudWatch Logs vs CloudTrail Logs: Khác nhau hoàn toàn. CloudTrail có thể ship logs sang CloudWatch Logs để query/alert real-time — đây là integration, không phải cùng một thứ.

When / When not

ScenarioService đúng
Ai đã xóa resource lúc mấy giờ?CloudTrail
Lambda đang bị timeout nhiều không?CloudWatch
S3 bucket có đang bật public access?AWS Config
EC2 có đang bị attack không?GuardDuty
Security posture tổng thể của account?Security Hub
Alert khi IAM policy bị thay đổi?CloudTrail + CloudWatch Events
Enforce "mọi EBS phải encrypt"?Config Rules
Instance đang mine crypto?GuardDuty

Connection — Cách 5 service phối hợp

                    ┌─────────────┐
                    │  CloudTrail │ ← ghi mọi API call
                    └──────┬──────┘
                           │ ship logs
              ┌────────────┼────────────┐
              ▼            ▼            ▼
       ┌──────────┐  ┌──────────┐  ┌──────────┐
       │CloudWatch│  │GuardDuty │  │AWS Config│
       │(metrics  │  │(threat   │  │(config   │
       │ + alerts)│  │detection)│  │ history) │
       └────┬─────┘  └────┬─────┘  └────┬─────┘
            │             │             │
            └─────────────┼─────────────┘
                          │ aggregate findings

                  ┌──────────────┐
                  │ Security Hub │
                  │(single pane) │
                  └──────────────┘

Hands-on

Sau khi setup account theo checklist, thử sequence sau để cảm nhận sự khác biệt:

  1. CloudTrail: Vào CloudTrail → Event history → tìm event CreateTrail → xem full detail (user, IP, time, request params)
  2. CloudWatch: Billing → Preferences → bật billing alert → vào CloudWatch us-east-1 → Alarms → xem billing metric
  3. Config: Tạo 1 S3 bucket → vào Config → Resources → tìm bucket đó → xem Configuration timeline
  4. GuardDuty: Settings → Generate sample findings → xem các finding type, chú ý severity levels
  5. Security Hub: Sau khi có findings từ GuardDuty → Security Hub → Summary → xem Security score

Glossary

TOTP / OTP [^totp]

What: Time-based One-Time Password — mã 6 số tạo từ seed key + thời gian hiện tại, thay đổi mỗi 30 giây.

Why: Không thể dùng lại nếu bị nghe lén, khác password tĩnh.

Connection: AWS MFA dùng TOTP. App Google Authenticator/Authy tạo TOTP.

VPC Flow Logs [^vpc-flow-logs]

What: Log ghi lại traffic vào/ra các network interface trong VPC — source IP, dest IP, port, protocol, bytes, accept/reject.

Why: Cần để debug network connectivity và phát hiện bất thường (GuardDuty dùng Flow Logs làm input).

Gotchas: Không capture content của packet, chỉ capture metadata. Lưu vào CloudWatch Logs hoặc S3.

Threat intelligence [^threat-intelligence]

What: Database các IP, domain, pattern đã biết là độc hại (botnet C&C, malware distribution, known scanners).

Why: GuardDuty dùng threat intel feed của AWS + third-party để so sánh với traffic trong account — nếu EC2 communicate với IP trong danh sách → tạo finding.

Connection: Tương đương antivirus signature database nhưng ở network level.

Today I Learned