devHọc Dev
EN
Bài học

Tuần 3 - Ngày 2: WAF & Shield, GuardDuty/Inspector/Macie và Cognito

Tuần 3 – Ngày 2

Bài này gộp 3 chủ đề: AWS WAF và Shield, GuardDuty, Inspector, Macie, Amazon Cognito.

Mục tiêu học tập

  • Hiểu WAF: filter HTTP requests tại Layer 7
  • Phân biệt Shield Standard vs Shield Advanced
  • Nắm Managed Rule Groups và Custom Rules
  • Áp dụng rate limiting và geo blocking
  • Phân biệt 3 security detection services
  • Hiểu GuardDuty threat detection
  • Nắm Inspector vulnerability assessment
  • Áp dụng Macie cho PII detection
  • Phân biệt User Pool và Identity Pool
  • Hiểu authentication flow (JWT tokens)
  • Nắm federation với social providers
  • Áp dụng Cognito cho mobile/web apps

Phần 1: AWS WAF và Shield

1. AWS WAF (Web Application Firewall)

Định nghĩa

WAF = Layer 7 firewall protect web apps khỏi common exploits (SQL injection, XSS, etc.).

Deploy targets

  • CloudFront distribution (global)
  • ALB (regional)
  • API Gateway (regional)
  • AppSync (regional)
  • App Runner
  • Cognito User Pool
  • Verified Access

Key concepts

  • Web ACL (Access Control List): container of rules
  • Rules: define conditions to evaluate
  • Rule Groups: collection of rules
  • Actions: ALLOW, BLOCK, COUNT (monitor), CAPTCHA, Challenge

2. WAF Rules

2 types

IP-based / regex-based simple rules
  • Block by IP, country, header, query string, body
Rate-based rules
  • Block when single IP exceeds rate threshold (e.g., 1000 req/5 min)
  • Use case: rate limiting, brute-force protection

Match conditions

  • IP set: list of IPs/CIDRs
  • Geographic match: country code
  • String match: header, body, URI contains
  • Regex match: pattern matching
  • Size constraint: body length
  • SQL injection match: detect SQLi patterns
  • XSS match: detect XSS patterns

Example rule

Rule: BlockLargePayloads
Condition: Body size > 8 KB
Action: BLOCK
Rule: RateLimitByIP
Condition: Requests from single IP > 1000 in 5 min
Action: BLOCK (TTL 1 hour)

3. AWS Managed Rule Groups

Free tier (AWS Managed Rules)

  • AWSManagedRulesCommonRuleSet: OWASP Top 10
  • AWSManagedRulesKnownBadInputsRuleSet: known bad patterns
  • AWSManagedRulesSQLiRuleSet: SQL injection
  • AWSManagedRulesLinuxRuleSet: Linux-specific (LFI, etc.)
  • AWSManagedRulesUnixRuleSet
  • AWSManagedRulesWindowsRuleSet
  • AWSManagedRulesAdminProtectionRuleSet: protect admin paths
  • AWSManagedRulesAmazonIpReputationList: bad IPs list
  • Third-party rules (Fortinet, F5, Imperva, Trend Micro)
  • $/month subscription

4. WAF Workflow

Internet→CloudFront/ALB→WAF(evaluaterules)├──ALLOW→Passtoapp├──BLOCK→Return403├──COUNT→Log,passtoapp├──CAPTCHA→ShowCAPTCHAtouser└──Challenge→Browserchallenge(silent)

Rule evaluation

  • Rules evaluated in order of priority
  • First matching action wins
  • Default action (no rules match): ALLOW or BLOCK (configurable)

5. Common WAF Use Cases

Block SQL injection

Rule: SQLiProtection
Type: Managed Rule Group AWSManagedRulesSQLiRuleSet
Action: BLOCK

Geo blocking

Rule: BlockChinaRussia
Condition: Country IN [CN, RU]
Action: BLOCK

Rate limit per IP

Rule: RateLimit
Condition: 1000 req / 5 min from single IP
Action: BLOCK

Allow only specific IPs (admin endpoint)

Rule: AdminAccess
Condition: URI = /admin AND IP NOT IN allowlist
Action: BLOCK

Block bots

  • AWS Managed Rule: Bot Control (paid)
  • Distinguish good bots (Googlebot) from bad bots (scrapers)

6. WAF Pricing

  • $5/month per Web ACL
  • $1/month per rule
  • $0.60/million requests
  • Bot Control: +$10/M requests (advanced)

Cost optimization

  • Combine rules into rule groups
  • Use AWS Managed Rule Groups (free included rules)

7. AWS Shield

Shield Standard

  • Free, automatic for all AWS customers
  • Protects against most common DDoS attacks (L3, L4):
    • SYN/UDP floods
    • Reflection attacks (NTP, DNS amplification)
  • Always-on for CloudFront, Route 53
  • Suitable for basic protection

Shield Advanced

  • Paid: $3,000/month + data transfer fees
  • Protects:
    • CloudFront, Route 53, Global Accelerator, ALB, NLB, EIP (EC2)
  • Features:
    • Enhanced DDoS protection (Layer 3, 4, 7)
    • 24/7 DDoS Response Team (DRT) access
    • Cost protection: refund for scaling charges during attack
    • Real-time attack visibility (CloudWatch metrics)
    • WAF included (no separate cost)
    • Application Layer (L7) protection with WAF auto-rule
    • Health check-based detection

When to use Shield Advanced

  • Mission-critical apps
  • History of DDoS attacks
  • Regulatory requires DDoS protection
  • Want financial protection from scaling costs

8. AWS Firewall Manager

Định nghĩa

Firewall Manager = centrally manage WAF, Shield, Security Groups, Network Firewall across multiple accounts (Organizations).

Đặc điểm

  • Apply policies to all accounts / OUs in organization
  • Auto-protect new resources created
  • Compliance reporting
  • Cost: $/policy/region/month

Use case

  • Multi-account AWS Organization
  • Enforce baseline security across all accounts
  • Compliance (PCI, HIPAA across org)

9. AWS Network Firewall

Định nghĩa

Network Firewall = managed network firewall ở VPC level (L3-7), stateful inspection.

Đặc điểm

  • Filter ingress/egress traffic at subnet/VPC level
  • Supports Suricata-compatible rules (open source IDS/IPS)
  • Stateful inspection
  • Deep packet inspection
  • Integration với Firewall Manager

Pricing

  • ~$0.395/hour per firewall endpoint
  • $0.065/GB data processed

Use case

  • Centralized traffic inspection cho VPC
  • Block egress to malicious domains
  • Compliance requires network-level firewall

10. Security Service Layers

┌─────────────────────────────────────────┐│Internet│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│AWSShieldStandard(always-on,free)││├──DDoSL3/L4protection││└──Edgelocations│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│CloudFront+WAF││├──L7filtering(SQLi,XSS,rate)││└──Geoblocking│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│ShieldAdvanced(paid)││└──EnhancedDDoS+DRTsupport│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│ALB+SecurityGroups+NACLs│└─────────────────────────────────────────┘│▼┌─────────────────────────────────────────┐│Application(EC2/Lambda/ECS)│└─────────────────────────────────────────┘

11. WAF Best Practices

  1. Start with COUNT mode to evaluate rules without blocking
  2. Use AWS Managed Rule Groups for baseline
  3. Add rate-based rules for brute-force protection
  4. Geo-block unnecessary countries
  5. Monitor with CloudWatch metrics (BlockedRequests, AllowedRequests)
  6. Centrally manage via Firewall Manager if multi-account
  7. Enable logging to Kinesis Firehose → S3 for analysis

12. Common Patterns

Pattern 1: E-commerce site

  • CloudFront + WAF (managed rules + rate limit)
  • Shield Standard (free)
  • ALB → EC2

Pattern 2: API protection

  • CloudFront + API Gateway + WAF
  • Rate limit per API key
  • IP allowlist for partners

Pattern 3: High-value target (gov, financial)

  • CloudFront + WAF + Shield Advanced
  • DRT on-call
  • 24/7 monitoring

Phần 2: GuardDuty, Inspector, Macie

1. AWS GuardDuty

Định nghĩa

GuardDuty = intelligent threat detection dùng ML phát hiện malicious activity và unauthorized behavior.

Data sources analyzed

  • VPC Flow Logs (network traffic)
  • CloudTrail event logs (API calls)
  • CloudTrail S3 data events (object access)
  • DNS logs (Route 53 Resolver queries)
  • EKS audit logs
  • EKS runtime monitoring
  • RDS login events
  • Lambda network activity
  • S3 protection
  • EBS volume scanning (Malware Protection)

Findings categories

  • Reconnaissance: port scanning, IAM enumeration
  • Instance compromise: bitcoin mining, malware C&C
  • Account compromise: stolen credentials usage
  • Bucket compromise: S3 unusual access patterns
  • Cryptocurrency mining

Severity levels

  • Critical (9.0-10.0): bổ sung 2024 — compromise đã xác nhận, xử lý ngay lập tức
  • High (7.0-8.9): immediate action needed
  • Medium (4.0-6.9): investigate
  • Low (1.0-3.9): informational

Integration

  • EventBridge: trigger Lambda for auto-remediation
  • Security Hub: aggregate findings
  • Detective: investigate root cause

Pricing

  • Per million CloudTrail events analyzed
  • Per GB VPC Flow Logs / DNS logs
  • Per GB scanned (Malware Protection)
  • 30-day free trial

Use case

  • Continuous threat monitoring
  • Detect compromised credentials
  • Detect crypto mining on EC2
  • Alert on unusual API calls

Multi-account

  • Delegate administrator account (recommended)
  • Auto-enable for new member accounts
  • Aggregate findings centrally

2. AWS Inspector

Định nghĩa

Inspector = automated vulnerability assessment for AWS workloads.

Targets scanned

  • EC2 instances (OS + app vulnerabilities)
  • ECR container images
  • Lambda functions (code + dependencies)

Vulnerability sources

  • CVE database (Common Vulnerabilities and Exposures)
  • AWS-curated rules
  • Network reachability (EC2 internet exposure)

Findings

  • Severity: Critical, High, Medium, Low
  • CVSS score (Common Vulnerability Scoring System)
  • Suggested remediation
  • Affected packages

Inspector v2 (current)

  • Replaced Inspector Classic in 2022
  • Continuous, automated scanning
  • Integration với Systems Manager Agent

Pricing

  • Per instance scanned/month (~$1-2)
  • Per ECR image scan
  • Per Lambda function

Use case

  • Compliance scanning (PCI DSS, HIPAA)
  • Detect outdated OS, libraries
  • Container image vulnerabilities before deploy

Multi-account

  • Delegated administrator
  • Auto-enroll new accounts

3. AWS Macie

Định nghĩa

Macie = ML-based data security service để discover, classify, protect sensitive data trong S3.

Detects

  • PII (Personally Identifiable Information):
    • Names, addresses, phone numbers
    • Email addresses
    • SSN, passport numbers, driver's license
  • Credit card numbers
  • Healthcare data (HIPAA-related)
  • AWS access keys (exposed in S3!)
  • Custom data identifiers (regex)

Workflow

  1. Enable Macie on account/organization
  2. Macie scans S3 buckets (sampling or full)
  3. Findings: which buckets contain sensitive data
  4. Alert + recommendation

Findings types

  • Policy findings:
    • Bucket publicly accessible
    • Bucket not encrypted
    • Bucket replicates externally
  • Sensitive Data findings:
    • PII found in object X
    • Credit card in object Y

Pricing

  • Bucket evaluation: $0.10 per S3 bucket/month
  • Sensitive data discovery: $1 per GB analyzed

Use case

  • GDPR compliance (find personal data)
  • PCI compliance (find credit cards)
  • Audit data storage
  • Prevent data leaks

4. So sánh 3 services

GuardDutyInspectorMacie
WhatThreat detectionVulnerability assessmentSensitive data detection
WhereAccount activity (logs)EC2, ECR, LambdaS3 buckets
HowML on log streamsCVE scanningML on S3 objects
FindingsActive attacks, anomaliesVulnerabilities (CVEs)PII, credit cards
Use caseReal-time threat alertCompliance vulnerability scanData privacy compliance

When to use what

  • GuardDuty: Real-time threat detection (always-on monitoring)
  • Inspector: Periodic vulnerability scan (compliance, DevSecOps)
  • Macie: Data discovery (compliance, audit)

Best practice: enable all 3 + Security Hub to aggregate.

5. AWS Security Hub

Định nghĩa

Security Hub = central dashboard cho security findings từ AWS services + 3rd party.

Aggregates findings từ

  • GuardDuty
  • Inspector
  • Macie
  • IAM Access Analyzer
  • AWS Config
  • AWS Firewall Manager
  • 3rd party (Tenable, Qualys, Splunk)

Features

  • Compliance standards:
    • AWS Foundational Security Best Practices
    • CIS AWS Benchmark
    • PCI DSS
    • NIST CSF
  • Security score (0-100%)
  • Multi-account aggregation (qua Organizations)
  • Automated response via EventBridge

Pricing

  • Per finding ingested + per check
  • Free tier: 30 days

Use case

  • Single pane of glass cho security
  • Continuous compliance monitoring
  • Centralized response workflow

6. AWS Detective

Định nghĩa

Detective = investigate root cause của security findings (GuardDuty, etc.).

Đặc điểm

  • Auto-collects logs (VPC Flow Logs, CloudTrail, GuardDuty findings)
  • Builds interactive graph of resources, IPs, actions
  • "What happened?" investigation tool
  • Goes beyond just alerting → understanding

Use case

  • Investigate GuardDuty finding
  • Forensic analysis after incident
  • Understand attacker movement

Pricing

  • Per GB ingested (~$2-3/GB)

7. AWS Audit Manager

Định nghĩa

Audit Manager = automate audit evidence collection cho compliance.

Frameworks

  • PCI DSS, HIPAA, SOC 2, GDPR, NIST
  • Custom frameworks

Workflow

  1. Select framework (e.g., PCI DSS)
  2. Audit Manager identifies controls
  3. Continuous evidence collection from CloudTrail, Config, etc.
  4. Generate audit-ready reports

Use case

  • Annual SOC 2 audit (save manual effort)
  • Continuous compliance posture

8. AWS Config

Định nghĩa

Config = track resource configuration changes over time.

Đặc điểm

  • Configuration snapshots of resources
  • History (timeline of changes)
  • Compliance rules: check if resource configured correctly
  • Integration với Security Hub, Audit Manager

Use case

  • "What changed and when?"
  • Compliance check (e.g., "all S3 buckets must be encrypted")
  • Drift detection

Pricing

  • $0.003 per configuration item recorded
  • $0.001 per evaluation

9. AWS Security Suite (Big picture)

┌───────────────Prevention──────────────┐│IAM,KMS,VPC,SG,NACL,WAF,Shield│└─────────────────────────────────────────┘│┌───────────────────Detection─────────────┐│GuardDuty(threats),Inspector(vulns),││Macie(data),AccessAnalyzer,Config│└───────────────────────────────────────────┘│┌───────────────────Response──────────────┐│SecurityHub(centralize),EventBridge││(automate),Detective(investigate),││AuditManager(compliancereports)│└───────────────────────────────────────────┘

10. Multi-account Security Strategy

Best practice setup

  1. Dedicated Security Account (AWS Organizations)
  2. Enable across organization:
    • GuardDuty (delegated admin)
    • Inspector (delegated admin)
    • Macie (delegated admin)
    • Security Hub (delegated admin)
    • Config (organization-wide)
  3. Aggregate findings in Security Account
  4. Automated remediation via EventBridge + Lambda
  5. Quarterly reviews + Audit Manager reports

11. Common Patterns

Pattern 1: New AWS account baseline

  1. Enable GuardDuty (free trial 30 days)
  2. Enable Security Hub
  3. Enable Access Analyzer
  4. Enable IAM Identity Center (replace IAM users)

Pattern 2: Detect compromised credentials

  • GuardDuty finding: UnauthorizedAccess:IAMUser/...
  • EventBridge rule → Lambda → auto-revoke credentials

Pattern 3: S3 data privacy

  • Macie scans S3 buckets weekly
  • Alert if PII found in non-classified bucket
  • Auto-tag bucket as "sensitive"

Pattern 4: Container vulnerability scanning

  • Inspector v2 scans ECR images on push
  • Block deploy if Critical findings (CI/CD gate)

Phần 3: Amazon Cognito

1. Tổng quan Cognito

Amazon Cognito = managed user identity service cho web + mobile apps.

2 components

ComponentPurpose
User PoolUser directory: signup, signin, password management
Identity Pool (Federated Identities)Exchange identity → AWS temp credentials

Use cases

  • Mobile app authentication
  • Web app SSO
  • API authentication
  • Backend user management without building auth

Pricing

  • User Pool: từ 12/2024 tính theo tier Lite / Essentials / Plus — Essentials ~$0.015/MAU, free tier 10K MAU (tier Lite với free 50K MAU chỉ còn cho user pool tạo trước 12/2024; tài liệu cũ hay ghi "$0.0055/MAU, free 50K")
  • Identity Pool: free

2. User Pool

Đặc điểm

  • User directory (database of users)
  • Authentication: username/password, email, phone
  • MFA: SMS, TOTP, authenticator app
  • Password policy: complexity, expiration
  • Self-service: signup, password reset, email/phone verification
  • Federation: SAML, OIDC (Google, Facebook, Apple, Amazon, SAML IdPs)
  • Returns JWT tokens (ID token, Access token, Refresh token)

Token types

TokenContainsUse case
ID TokenUser attributes (email, name, sub)Identity verification
Access TokenScopes, user infoAPI authorization
Refresh Token(Opaque)Get new ID/Access tokens

Token lifetime

  • ID Token: 1 hour (default)
  • Access Token: 1 hour
  • Refresh Token: 30 days (default, configurable 60 min - 10 years)

Customization

  • Lambda triggers at key events:
    • Pre Sign-up (validation)
    • Post Confirmation
    • Pre Authentication
    • Post Authentication
    • Custom Message (email/SMS content)
    • Pre Token Generation (add custom claims)

App Client

  • App accessing User Pool có app client ID
  • Configure: which OAuth flows, which IdPs allowed, callback URLs

3. User Pool Authentication Flow

Standard flow

1. User → App: enters username + password
2. App → User Pool: InitiateAuth API
3. User Pool: verify creds
4. User Pool → App: ID Token + Access Token + Refresh Token (JWT)
5. App → API Gateway: API call với Access Token in Authorization header
6. API Gateway → User Pool: verify token signature
7. API Gateway → Lambda backend

Federated flow (Google sign-in)

1. User → App: "Sign in with Google"
2. App → Google: OAuth
3. Google → User Pool: SAML/OIDC token
4. User Pool: provision user (if first time)
5. User Pool → App: JWT tokens

4. Identity Pool (Federated Identities)

Đặc điểm

  • Provide temporary AWS credentials to users
  • For users authenticated via:
    • Cognito User Pools
    • Social IdPs (Google, Facebook, Apple, Amazon)
    • SAML / OIDC
    • Developer-authenticated
  • 2 roles:
    • Authenticated role
    • Unauthenticated (guest) role

Workflow

1. User authenticates with IdP (User Pool, Google, ...)
2. IdP returns token
3. App calls Identity Pool: GetCredentialsForIdentity
4. Identity Pool returns AWS STS temp credentials
5. App uses credentials to access AWS services (S3, DynamoDB, API Gateway)

Use case: Mobile photo app

  • User uploads photo directly to S3 (instead of through backend)
  • Identity Pool gives temp credentials scoped to user's S3 prefix
  • App uses creds for S3 upload

Policy scoping

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["s3:PutObject", "s3:GetObject"],
    "Resource": "arn:aws:s3:::my-bucket/users/${cognito-identity.amazonaws.com:sub}/*"
  }]
}

→ Each user can only access their own S3 prefix.

5. User Pool vs Identity Pool

User PoolIdentity Pool
PurposeUser management + authAWS credentials
ReturnsJWT tokensAWS temp credentials
ForApp authenticationDirect AWS access
IdPOptional (can federate)Required (User Pool, social, SAML)
Combined useOften combined: User Pool → Identity Pool → AWS

Common pattern

User → User Pool (sign in) → JWT
     → Identity Pool (exchange JWT) → AWS temp creds
     → S3 / DynamoDB / API Gateway

6. Cognito with API Gateway

Cognito Authorizer

  • API Gateway có Cognito Authorizer type
  • Validates JWT token from User Pool
  • No backend code needed for auth

Setup

APIGatewayendpoint:GET/users/me└──Authorizer:CognitoUserPoolauthorizer├──Tokensource:Authorizationheader└──ValidatesagainstUserPoolID

Lambda Authorizer (alternative)

  • Custom Lambda function validates token
  • More flexible (custom logic)
  • Use when need extra validation beyond Cognito

7. Cognito Federation Examples

Sign in with Google

  1. Setup Google OAuth credentials
  2. Add Google as IdP in User Pool
  3. Configure App Client allowed IdPs: Google
  4. User clicks "Sign in with Google" → redirects to Google → returns to app

SAML federation (corporate AD)

  1. Setup SAML IdP in User Pool (Okta, Azure AD, ADFS)
  2. Configure attribute mapping (email, name)
  3. Users sign in with corporate creds

Apple Sign-In

  1. Apple Developer account required
  2. Add Apple as IdP
  3. Handle Apple-specific tokens

8. Cognito Sync (Deprecated → use AppSync)

  • Sync user data across devices
  • Deprecated — use AWS AppSync + DataStore for new apps

9. Hosted UI

Định nghĩa

Hosted UI = AWS-provided customizable login/signup UI.

Đặc điểm

  • Pre-built sign-in, sign-up, forgot password forms
  • Customizable: logo, colors, CSS
  • OAuth 2.0 flows: Authorization Code, Implicit, PKCE
  • Custom domain support

Use case

  • Don't want to build auth UI from scratch
  • Quick prototype
  • Standard auth flows

10. Advanced Security Features (Plus tier)

Risk-based adaptive authentication

  • Detect risky sign-ins (new device, unusual location)
  • Require MFA or block

Compromised credentials check

  • Check against known compromised passwords
  • Force user to change password

Pricing

  • Plus tier: more expensive per MAU

11. Cognito vs IAM Identity Center vs IAM Users

CognitoIAM Identity CenterIAM Users
ForApp end-usersAWS workforce usersLegacy AWS access
ScaleMillions of users100s-1000s of employees< 5000/account
SSOPer appMulti-account AWSNo
Use caseMobile/web app usersInternal team accessing AWSLegacy or service accounts

Decision

  • App users: Cognito
  • Employees accessing AWS Console: IAM Identity Center
  • Service accounts: IAM Roles (not users)

12. Common Patterns

Pattern 1: Mobile photo sharing app

User → Cognito User Pool (email/password)
     → Cognito Identity Pool (AWS creds scoped to user)
     → S3 upload + DynamoDB metadata

Pattern 2: SaaS multi-tenant app

Users → User Pool per tenant
      → API Gateway with Cognito Authorizer
      → Lambda → DynamoDB (filter by user ID from JWT)

Pattern 3: Enterprise app với SAML

Employee → User Pool with SAML federation (Okta)
        → JWT
        → App

Pattern 4: Public app + admin portal

Public users → User Pool A
Admins → User Pool B with MFA required
Different API Gateway authorizers

Câu hỏi ôn tập

  1. WAF deploy được trên những targets nào?

    Xem đáp án

    WAF (Web Application Firewall) deploy được trên: CloudFront, ALB (Application Load Balancer), API Gateway, AppSync GraphQL API, Cognito User Pool. Không deploy được trên NLB (Layer 4) hay CLB. WAF hoạt động ở Layer 7 — inspect HTTP/HTTPS requests. WAF cho CloudFront là global; WAF cho ALB/API GW là regional.

  2. Shield Standard có miễn phí không? Bảo vệ ở L mấy?

    Xem đáp án

    Miễn phí và tự động cho tất cả AWS customers. Bảo vệ ở Layer 3 và Layer 4 (network + transport) — volumetric attacks (UDP floods, SYN floods, reflection attacks). Bảo vệ tất cả Edge Locations (CloudFront, Route 53, Global Accelerator). Không bảo vệ Layer 7 (HTTP floods, application-level DDoS) — cần WAF và Shield Advanced cho đó.

  3. Shield Advanced cost bao nhiêu/month?

    Xem đáp án

    $3,000/month per organization (không phải per account). Bao gồm: 24/7 DDoS Response Team (DRT) support, financial reimbursement cho DDoS-caused AWS cost spikes, automatic application layer attack detection + response (WAF rules auto-created), và protection cho EC2, ELB, CloudFront, Route 53, Global Accelerator. Hợp lý cho enterprises với business-critical applications.

  4. Rate-based rule trong WAF dùng để làm gì?

    Xem đáp án

    Rate-based rule block hoặc challenge requests từ một IP khi vượt ngưỡng request rate trong 5 phút. Ví dụ: block IP gửi > 1000 requests/5 phút. Dùng để ngăn brute-force attacks, credential stuffing, scraping, Layer 7 DDoS. Có thể group theo IP, forwarded IP, hoặc bất kỳ aggregation key. Rule tự động unblock IP khi rate giảm xuống dưới threshold.

  5. AWS Firewall Manager khác WAF console ở điểm gì?

    Xem đáp án

    Firewall Manager là centralized management cho multiple accounts trong AWS Organizations — deploy và enforce WAF rules, Shield Advanced protections, Security Groups, Network Firewall policies across tất cả accounts từ một chỗ. WAF console chỉ manage WAF trong một account. Firewall Manager phù hợp cho enterprise với nhiều accounts cần consistent security policies — tự động apply rules cho new accounts/resources.

  6. GuardDuty phân tích data sources nào?

    Xem đáp án

    GuardDuty phân tích: VPC Flow Logs, DNS Logs, CloudTrail Events, CloudTrail S3 Data Events (tùy chọn), EKS audit logs, Lambda network activity, RDS login activity. Dùng ML để detect anomalies: unusual API calls, compromised credentials, cryptocurrency mining, port scanning, known malicious IPs. Không cần enable mọi data source trong account — GuardDuty tự pull từ AWS.

  7. Inspector scan được loại resources nào?

    Xem đáp án

    Amazon Inspector scan: EC2 instances (OS vulnerabilities, network exposure), ECR container images (layer vulnerabilities), Lambda functions (package vulnerabilities, code analysis). Automated continuous scanning — không cần manual schedule. Generate findings với severity, CVE details, và remediation recommendations. Khác từ classic Inspector 2016 — thế hệ mới (Inspector v2) tích hợp với AWS Organizations.

  8. Macie chuyên detect gì trong S3?

    Xem đáp án

    Amazon Macie chuyên detect sensitive data trong S3 buckets dùng ML: PII (Personally Identifiable Information), financial data (credit cards, bank accounts), credentials, medical records. Cũng phát hiện misconfigured buckets (public access, unencrypted). Macie tạo findings khi phát hiện sensitive data exposure. Phù hợp cho GDPR, HIPAA, PCI DSS compliance — audit S3 bucket contents automatically.

  9. Security Hub khác Detective ở điểm gì?

    Xem đáp án

    Security Hub: aggregates findings từ nhiều services (GuardDuty, Inspector, Macie, IAM Access Analyzer, Config...) và third-party tools vào một dashboard. Chuẩn hóa theo ASFF format, automation via EventBridge. Amazon Detective: investigation tool — khi có finding/incident, dùng Detective để visualize, phân tích root cause, xem timeline của activity. Detective giúp "điều tra" sau khi phát hiện; Security Hub giúp "tổng hợp và prioritize".

  10. Khi nào cần Shield Advanced thay vì Shield Standard?

Xem đáp án

Cần Shield Advanced khi: (1) Applications business-critical với high revenue risk nếu downtime (e-commerce, financial), (2) Cần 24/7 DRT support để respond và mitigate complex DDoS, (3) Cần cost protection — reimbursement AWS scaling costs khi bị DDoS (EC2, NAT GW, data transfer), (4) Cần Layer 7 auto-mitigation cho sophisticated HTTP-based attacks. $3,000/month per org — justified cho enterprises.

  1. User Pool và Identity Pool khác nhau ở điểm gì?
Xem đáp án

User Pool: authentication service — quản lý user directory (sign-up, sign-in, password reset, MFA, social federation). Trả về JWT tokens (ID, Access, Refresh). Không cấp AWS credentials. Identity Pool: authorization service — exchange identity (JWT từ User Pool, Google, Facebook, SAML) lấy temporary AWS credentials (via STS) để gọi AWS APIs trực tiếp. Thường dùng cả hai: User Pool authenticate → Identity Pool cấp AWS credentials.

  1. JWT tokens trả về từ User Pool gồm những loại gì?
Xem đáp án

3 loại: (1) ID Token — chứa user attributes (email, phone, custom claims) — dùng để verify identity và pass user info đến backend, (2) Access Token — authorizes API calls đến User Pool (không phải AWS APIs) — chứa scopes và groups, (3) Refresh Token — lifetime dài (default 30 ngày) — dùng để lấy ID/Access tokens mới khi hết hạn. Refresh token không bao giờ gửi đến API — chỉ dùng với Cognito.

  1. Khi nào dùng Identity Pool?
Xem đáp án

Khi cần mobile/web app gọi AWS APIs trực tiếp (S3 upload, DynamoDB query, Kinesis...) với temporary credentials. Ví dụ: app chụp ảnh cần upload thẳng lên S3 bucket của user — không qua backend server. Identity Pool cấp IAM role credentials với quyền limited scope. Cũng dùng cho unauthenticated (guest) access — cho phép anonymous users access AWS resources với quyền giới hạn.

  1. Cognito Authorizer trong API Gateway validate gì?
Xem đáp án

Cognito Authorizer validate JWT Access Token từ User Pool. API Gateway check: (1) Token còn valid (không hết hạn), (2) Signature valid (signed bởi User Pool), (3) Token scope match required scopes (nếu cấu hình). Không cần code custom validation — API Gateway xử lý hoàn toàn. Nếu token invalid → 401 Unauthorized. Không cần Lambda Authorizer cho authentication flow đơn giản.

  1. Cognito User Pool có hỗ trợ MFA không?
Xem đáp án

Có — Cognito User Pool hỗ trợ MFA: TOTP (Time-based One-Time Password — Google Authenticator, Authy) và SMS (qua Amazon SNS). Có thể cấu hình MFA là: Off, Optional (user tự chọn), hoặc Required (bắt buộc). Từ 2023, Cognito cũng hỗ trợ email OTP và passkeys (WebAuthn). MFA cấu hình ở User Pool level, không phải per-user.

Bài tập thực hành

Phần 1: AWS WAF và Shield

  • Tạo Web ACL với managed rule AWSManagedRulesCommonRuleSet, attach vào ALB
  • Add custom rule: rate limit 100 req/5min per IP
  • Add geo block: deny country code XX
  • Test với simulated SQL injection request (should be blocked)
  • Setup CloudWatch alarm khi BlockedRequests spike
  • (Optional) Test với Firewall Manager (cần Organization)

Phần 2: GuardDuty, Inspector, Macie

  • Enable GuardDuty (30 day free trial), wait 24h xem findings
  • Enable Inspector v2 cho EC2 instances
  • Enable Macie, scan 1 S3 bucket có sample PII
  • Enable Security Hub, observe aggregated findings
  • Setup EventBridge rule: GuardDuty High severity → SNS email

Phần 3: Amazon Cognito

  • Tạo Cognito User Pool, configure password policy + MFA
  • Tạo App Client, test sign-up + sign-in via Hosted UI
  • Setup Identity Pool, get temp creds cho test user
  • Configure API Gateway với Cognito Authorizer
  • Add Google as federated IdP, test sign-in
  • Tạo Lambda trigger Post-Confirmation: add user to DynamoDB

Tài liệu tham khảo


Bài tiếp theo →