Skip to content

🔒 Security Posture

Level: Advanced Solves: Thiết kế và implement comprehensive security strategy cho enterprise AWS environments

🎯 Mục tiêu (Outcomes)

Sau khi áp dụng kiến thức trong trang này, bạn sẽ có khả năng:

  • Thiết kế Defense-in-Depth Strategy với multiple security layers
  • Triển khai Security Hub cho centralized security findings aggregation
  • Cấu hình GuardDuty cho threat detection và automated response
  • Áp dụng WAF Rules cho application-level protection
  • Implement Auto-Remediation cho common security findings
  • Xây dựng Security Monitoring với dashboards và alerting

Khi nào dùng

Security ToolUse CaseLý do
Security HubCentralized findingsAggregate từ tất cả security services
GuardDutyThreat detectionML-based, managed, low overhead
WAFWeb app protectionOWASP Top 10, bot mitigation
Shield AdvancedDDoS protectionHigh-traffic, critical apps
MacieSensitive data discoveryPII, compliance requirements
InspectorVulnerability scanningEC2, Lambda, ECR

Khi nào KHÔNG dùng

PatternVấn đềThay thế
Enable tất cả không tuneAlert fatigue, noiseStart small, tune gradually
WAF block-all approachBlock legitimate trafficMonitor first, then block
Auto-remediate productionUnexpected changesManual approval for prod
Ignore low findingsMay escalateReview và accept/fix

⚠️ Cảnh báo từ Raizo

"Một team enable GuardDuty và Security Hub nhưng không set up alerting. 3 tháng sau review, phát hiện 500+ critical findings đã tồn tại từ ngày 1. Security tools vô nghĩa nếu không ai xem."

Defense in Depth

Security Layers

┌─────────────────────────────────────────────────────────────────┐
│                 DEFENSE IN DEPTH                                │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │ Layer 1: PERIMETER                                      │    │
│  │ • WAF, Shield, CloudFront                               │    │
│  │ • DDoS protection, Bot mitigation                       │    │
│  └─────────────────────────────────────────────────────────┘    │
│      │                                                          │
│      ▼                                                          │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │ Layer 2: NETWORK                                        │    │
│  │ • VPC, Security Groups, NACLs                           │    │
│  │ • Network segmentation, Private subnets                 │    │
│  └─────────────────────────────────────────────────────────┘    │
│      │                                                          │
│      ▼                                                          │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │ Layer 3: IDENTITY                                       │    │
│  │ • IAM, SSO, MFA                                         │    │
│  │ • Least privilege, Role assumption                      │    │
│  └─────────────────────────────────────────────────────────┘    │
│      │                                                          │
│      ▼                                                          │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │ Layer 4: APPLICATION                                    │    │
│  │ • Input validation, Output encoding                     │    │
│  │ • Secrets management, Secure coding                     │    │
│  └─────────────────────────────────────────────────────────┘    │
│      │                                                          │
│      ▼                                                          │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │ Layer 5: DATA                                           │    │
│  │ • Encryption at rest/transit                            │    │
│  │ • Data classification, Access controls                  │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Threat Modeling for Cloud

STRIDE Framework

ThreatDescriptionAWS Mitigation
SpoofingImpersonating identityIAM, MFA, SSO
TamperingModifying dataEncryption, integrity checks
RepudiationDenying actionsCloudTrail, logging
Information DisclosureExposing dataEncryption, access controls
Denial of ServiceDisrupting serviceShield, WAF, Auto Scaling
Elevation of PrivilegeGaining unauthorized accessLeast privilege, boundaries

Cloud-Specific Threats

┌─────────────────────────────────────────────────────────────────┐
│              CLOUD-SPECIFIC THREAT MODEL                        │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  1. CREDENTIAL EXPOSURE                                         │
│     • Hardcoded secrets in code                                 │
│     • Leaked access keys                                        │
│     • Overly permissive IAM policies                            │
│     Mitigation: Secrets Manager, IAM Access Analyzer            │
│                                                                 │
│  2. MISCONFIGURATION                                            │
│     • Public S3 buckets                                         │
│     • Open security groups                                      │
│     • Disabled encryption                                       │
│     Mitigation: Config Rules, Security Hub                      │
│                                                                 │
│  3. LATERAL MOVEMENT                                            │
│     • Compromised instance → other resources                    │
│     • Cross-account access abuse                                │
│     Mitigation: Network segmentation, least privilege           │
│                                                                 │
│  4. DATA EXFILTRATION                                           │
│     • Unauthorized data access                                  │
│     • DNS tunneling                                             │
│     Mitigation: VPC endpoints, Macie, GuardDuty                 │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

AWS Security Hub

Architecture

Security Standards

StandardFocusUse Case
AWS FoundationalAWS best practicesAll workloads
CIS AWS FoundationsCIS benchmarksCompliance
PCI DSSPayment card securityFinancial
NIST CSFCybersecurity frameworkGovernment

Finding Severity

┌─────────────────────────────────────────────────────────────────┐
│              SECURITY HUB SEVERITY LEVELS                       │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  CRITICAL (90-100)                                              │
│  • Immediate action required                                    │
│  • Active exploitation possible                                 │
│  • Example: Public S3 bucket with sensitive data                │
│                                                                 │
│  HIGH (70-89)                                                   │
│  • Address within 24 hours                                      │
│  • Significant security risk                                    │
│  • Example: Root account without MFA                            │
│                                                                 │
│  MEDIUM (40-69)                                                 │
│  • Address within 1 week                                        │
│  • Moderate security risk                                       │
│  • Example: Unused IAM credentials                              │
│                                                                 │
│  LOW (1-39)                                                     │
│  • Address in next sprint                                       │
│  • Minor security improvement                                   │
│  • Example: Missing resource tags                               │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Amazon GuardDuty

Threat Detection Categories

┌─────────────────────────────────────────────────────────────────┐
│                 GUARDDUTY FINDING TYPES                         │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  EC2 Findings:                                                  │
│  ├── Backdoor:EC2/DenialOfService.Tcp                           │
│  ├── CryptoCurrency:EC2/BitcoinTool.B                           │
│  ├── Trojan:EC2/BlackholeTraffic                                │
│  └── UnauthorizedAccess:EC2/SSHBruteForce                       │
│                                                                 │
│  IAM Findings:                                                  │
│  ├── CredentialAccess:IAMUser/AnomalousBehavior                 │
│  ├── PenTest:IAMUser/KaliLinux                                  │
│  └── UnauthorizedAccess:IAMUser/ConsoleLoginSuccess.B           │
│                                                                 │
│  S3 Findings:                                                   │
│  ├── Policy:S3/BucketAnonymousAccessGranted                     │
│  ├── Exfiltration:S3/MaliciousIPCaller                          │
│  └── Discovery:S3/MaliciousIPCaller                             │
│                                                                 │
│  Kubernetes Findings:                                           │
│  ├── CredentialAccess:Kubernetes/MaliciousIPCaller              │
│  ├── Execution:Kubernetes/ExecInKubeSystemPod                   │
│  └── PrivilegeEscalation:Kubernetes/PrivilegedContainer         │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Auto-Remediation Example

python
import boto3

def lambda_handler(event, context):
    """Auto-remediate GuardDuty findings"""
    
    finding = event['detail']
    finding_type = finding['type']
    
    if finding_type.startswith('UnauthorizedAccess:EC2/SSHBruteForce'):
        # Block the attacking IP
        instance_id = finding['resource']['instanceDetails']['instanceId']
        attacker_ip = finding['service']['action']['networkConnectionAction']['remoteIpDetails']['ipAddressV4']
        
        ec2 = boto3.client('ec2')
        
        # Add NACL rule to block attacker
        ec2.create_network_acl_entry(
            NetworkAclId='acl-xxx',
            RuleNumber=100,
            Protocol='-1',
            RuleAction='deny',
            Egress=False,
            CidrBlock=f'{attacker_ip}/32'
        )
        
        # Notify security team
        sns = boto3.client('sns')
        sns.publish(
            TopicArn='arn:aws:sns:us-east-1:123456789012:security-alerts',
            Message=f'Blocked SSH brute force attacker: {attacker_ip}',
            Subject='GuardDuty Auto-Remediation'
        )
    
    return {'statusCode': 200}

AWS WAF

Rule Groups

┌─────────────────────────────────────────────────────────────────┐
│                    WAF RULE STRATEGY                            │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Priority Order (evaluated top to bottom):                      │
│                                                                 │
│  1. IP Reputation (AWS Managed)                                 │
│     • Block known malicious IPs                                 │
│     • Amazon IP reputation list                                 │
│                                                                 │
│  2. Rate Limiting                                               │
│     • 2000 requests per 5 minutes per IP                        │
│     • Prevent DDoS and brute force                              │
│                                                                 │
│  3. Bot Control (AWS Managed)                                   │
│     • Block bad bots                                            │
│     • Allow good bots (Googlebot, etc.)                         │
│                                                                 │
│  4. SQL Injection (AWS Managed)                                 │
│     • SQLi attack patterns                                      │
│     • Common injection strings                                  │
│                                                                 │
│  5. XSS (AWS Managed)                                           │
│     • Cross-site scripting patterns                             │
│     • Script injection attempts                                 │
│                                                                 │
│  6. Custom Rules                                                │
│     • Application-specific patterns                             │
│     • Geo-blocking if needed                                    │
│                                                                 │
│  7. Default Action: ALLOW                                       │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

WAF Rule Example

json
{
  "Name": "RateLimitRule",
  "Priority": 1,
  "Statement": {
    "RateBasedStatement": {
      "Limit": 2000,
      "AggregateKeyType": "IP",
      "ScopeDownStatement": {
        "ByteMatchStatement": {
          "SearchString": "/api/",
          "FieldToMatch": {
            "UriPath": {}
          },
          "TextTransformations": [
            {
              "Priority": 0,
              "Type": "LOWERCASE"
            }
          ],
          "PositionalConstraint": "STARTS_WITH"
        }
      }
    }
  },
  "Action": {
    "Block": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "RateLimitRule"
  }
}

Security Monitoring Dashboard

Key Metrics

MetricSourceAlert Threshold
Critical FindingsSecurity Hub> 0
High Severity FindingsSecurity Hub> 5
GuardDuty FindingsGuardDuty> 0
Failed Login AttemptsCloudTrail> 10/hour
Root Account UsageCloudTrail> 0
WAF Blocked RequestsWAFSpike detection

Best Practices Checklist

  • [ ] Enable Security Hub with all standards
  • [ ] Enable GuardDuty in all regions
  • [ ] Configure WAF for public-facing applications
  • [ ] Enable Shield Advanced for DDoS protection
  • [ ] Implement automated remediation for common findings
  • [ ] Conduct regular security assessments
  • [ ] Review and rotate credentials regularly
  • [ ] Enable Macie for sensitive data discovery

⚖️ Trade-offs

Trade-off 1: Security Strictness vs Operational Agility

ApproachSecurityAgilityBest For
Block-first WAFCaoThấpFinancial, healthcare
Monitor-first WAFTrung bìnhCaoE-commerce, startups
Auto-remediate allCaoThấpNon-production
Manual reviewTrung bìnhĐiều chỉnh đượcProduction

Trade-off 2: Security Tool Coverage vs Cost

ToolMonthly Cost (rough)Value
Security Hub$0.0010/findingCentral visibility
GuardDuty$4/GB analyzedThreat detection
Macie$1/GB scannedPII discovery
Inspector$0.15/assessmentVulnerability scan
Shield Advanced$3,000/monthDDoS protection

Khuyến nghị priority:

  1. Security Hub + GuardDuty (baseline)
  2. WAF (public apps)
  3. Inspector (compute)
  4. Macie (nếu có PII)
  5. Shield Advanced (high-profile targets)

Trade-off 3: Finding Volume vs Actionability

Severity FilterFindings/dayActionable %Team Load
Critical only1-590%+Low
High + Critical10-5070%Medium
All severities100-50030%Very High

🚨 Failure Modes

Failure Mode 1: Alert Fatigue Leading to Missed Threats

🔥 Incident thực tế

Security team nhận 300 alerts/ngày. Real credential compromise finding bị miss trong 2 tuần. Attacker đã exfiltrate customer data. $5M breach cost + reputation damage.

Cách phát hiệnCách phòng tránh
Alert response time > 24hTiered alerting (Critical = PagerDuty)
High suppress/snooze rateTune rules, reduce noise
Team burnoutAutomate low-severity responses

Failure Mode 2: False Positive với WAF

Cách phát hiệnCách phòng tránh
User complaintsCount mode trước, block sau
Business metrics dropMonitor block rate vs conversions
Legitimate traffic blockedRegular rule review

Failure Mode 3: Blind Spots trong Coverage

Cách phát hiệnCách phòng tránh
New accounts không có GuardDutyOrganizations-level enablement
New regions không monitorMulti-region automation
Shadow IT resourcesRegular resource discovery

🔐 Security Baseline

Mandatory Security Services

ServiceScopeConfiguration
Security HubAll accounts, all regionsCIS, AWS Foundational
GuardDutyAll accounts, all regionsS3, EKS protection enabled
CloudTrailOrganization trailAll regions, data events
ConfigAll accountsConformance packs

Security Standards

StandardCoveragePass Target
CIS AWS BenchmarkInfrastructure> 90%
AWS FoundationalBest practices> 95%
PCI-DSSPayment systems100%
SOC 2All production> 85%

Incident Response

┌─────────────────────────────────────────────────────────────────┐
│               INCIDENT RESPONSE FLOW                            │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Detection → Triage → Contain → Eradicate → Recover → Lessons   │
│      │          │         │          │          │          │      │
│      │          │         │          │          │          │      │
│  GuardDuty   5 min    Isolate    Remove     Restore    Doc     │
│  Security    SLA      affected   threat     service    PIR     │
│  Hub                  resources  actor      ops                │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

📊 Ops Readiness

Metrics cần Monitoring

MetricSourceAlert Threshold
Critical findingsSecurity Hub> 0
High findingsSecurity Hub> 10 unresolved
GuardDuty findingsGuardDutyAny high/critical
Root loginCloudTrail> 0
Failed MFACloudTrail> 5/hour
WAF block rateWAFSpike > 3x

Runbook Entry Points

Tình huốngRunbook
Critical Security Hub findingrunbook/security-hub-critical.md
GuardDuty high severityrunbook/guardduty-response.md
Compromised credentialsrunbook/credential-compromise.md
WAF blocking spikerunbook/waf-investigation.md
Root account activityrunbook/root-account-investigation.md
DDoS attackrunbook/ddos-response.md

Design Review Checklist

Tool Coverage

  • [ ] Security Hub enabled all accounts/regions
  • [ ] GuardDuty enabled all accounts/regions
  • [ ] WAF cho tất cả public endpoints
  • [ ] Inspector cho compute resources

Monitoring

  • [ ] Alerting configured và routed
  • [ ] Security dashboard available
  • [ ] On-call rotation defined
  • [ ] Escalation path documented

Response

  • [ ] Incident response runbooks
  • [ ] Auto-remediation cho common issues
  • [ ] Regular tabletop exercises
  • [ ] Post-incident review process

Governance

  • [ ] Security standards mapped
  • [ ] Compliance score tracking
  • [ ] Exception process defined
  • [ ] Regular security reviews

📎 Liên kết