CCSP · Domain 4 · 17%

Bảo mật ứng dụng đám mây

Cloud Application Security

Secure SDLC trong cloud-native context: OWASP Cloud-Native Top 10, API Gateway security, microservices với mTLS/service mesh, secrets injection, CI/CD pipeline security, container registry signing, và cloud application monitoring — từ code đến production.

Mục tiêu chương / Learning objectives

1. Lý thuyết cốt lõi / Core theory

1.1. Secure SDLC trong Cloud — Shift-Left Security (Secure SDLC)

Shift-left có nghĩa là đưa bảo mật vào sớm nhất trong vòng đời phát triển, thay vì chỉ test ở giai đoạn cuối. Trong cloud-native CI/CD:

DevSecOps pipeline stages: Code → SAST+SCA → Build → Container Scan → Test → DAST → Staging → Penetration Test → Production → CSPM+RASP monitoring. Mỗi stage là một security gate.

1.2. OWASP Cloud-Native Application Security Top 10 (OWASP Cloud-Native Top 10)

1.3. API Gateway Security (API security)

API Gateway là entry point cho cloud-native applications — điểm hội tụ của nhiều security controls:

1.4. Microservices Security — mTLS & Service Mesh (Microservices security)

Trong microservices architecture, service-to-service communication bên trong cluster cần bảo mật. mTLS (Mutual TLS) xác thực hai chiều: client và server đều present certificate, đảm bảo cả authentication và encryption.

1.5. Secrets Management & Container Image Security (Secrets & image security)

Secrets management tiers:

Container image security chain:

2. Bài thực hành / Hands-on lab

🖥️ Nền tảng / Platform: Any (Cloud Shell) + Ubuntu 22.04
🛠️ Công cụ / Tools: Azure CLI · Bash + curl + OWASP ZAP

Lab 1 — Azure DevOps Pipeline Security: Trivy + SAST + Secrets Management

OS: Any · Tool: Azure CLI.

  1. Kiểm tra Azure DevOps pipelines và variable groups (tìm secrets lưu sai chỗ):
# Kiểm tra pipelines và variable groups
az pipelines list --org https://dev.azure.com/myorg --project myproject -o table 2>/dev/null || \
  echo "Install Azure DevOps extension: az extension add --name azure-devops"

az pipelines variable-group list \
  --org https://dev.azure.com/myorg \
  --project myproject -o table 2>/dev/null

# Tạo secret trong Azure Key Vault (đúng cách)
az keyvault secret set \
  --vault-name myVault \
  --name "appDbPassword" \
  --value "$(openssl rand -base64 32)" \
  --description "Application database password - auto-generated"

# Xem secret metadata (không xem value)
az keyvault secret show \
  --vault-name myVault \
  --name "appDbPassword" \
  --query "{Name:name,Created:attributes.created,Expires:attributes.expires,Enabled:attributes.enabled}" \
  -o json

Ví dụ Azure DevOps pipeline YAML với security gates:

# azure-pipeline-secure.yml
trigger:
  branches:
    include: [ main, develop ]

stages:
- stage: SecurityScan
  displayName: 'Security Gates'
  jobs:
  - job: SAST
    steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '3.11'
    # SAST with Semgrep
    - script: |
        pip install semgrep
        semgrep --config=auto --error --json > semgrep-results.json
        python3 -c "
        import json
        r = json.load(open('semgrep-results.json'))
        highs = [f for f in r.get('results',[]) if f.get('extra',{}).get('severity') in ['ERROR','WARNING']]
        print(f'SAST findings: {len(highs)} HIGH/CRITICAL')
        if highs: exit(1)
        "
      displayName: 'Semgrep SAST Scan'

    # SCA with OWASP Dependency Check
    - script: |
        docker run --rm \
          -v $(Build.SourcesDirectory):/src \
          owasp/dependency-check:latest \
          --scan /src --format JSON --out /src/dc-report \
          --failOnCVSS 7
      displayName: 'OWASP Dependency Check'

  - job: ContainerScan
    steps:
    # Container image vulnerability scan
    - script: |
        docker build -t myapp:$(Build.BuildId) .
        docker run --rm \
          -v /var/run/docker.sock:/var/run/docker.sock \
          aquasec/trivy:latest image \
          --severity HIGH,CRITICAL \
          --exit-code 1 \
          myapp:$(Build.BuildId)
      displayName: 'Trivy Image Scan - Block on CRITICAL'

✅ Kết quả mong đợi / Expected output: Key Vault secret tạo thành công với auto-generated random password. Pipeline YAML: Semgrep exit code 1 (block build) nếu có SAST findings severity ERROR. Trivy exit code 1 nếu có CRITICAL CVEs — build bị dừng, không deploy image vulnerable. Variable groups không nên chứa plaintext passwords — chỉ Key Vault references.

Lab 2 — API Security Testing với curl + OWASP ZAP

OS: Ubuntu 22.04 · Tool: Bash + curl + OWASP ZAP.

#!/bin/bash
# API Security testing script
API_BASE="https://api.example.com/v1"

echo "=== Test 1: Authentication bypass ==="
# Attempt access with invalid Bearer token
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
  -H "Authorization: Bearer invalidtoken123" \
  "$API_BASE/admin/users")
echo "Invalid token response: $HTTP_CODE (expected: 401 or 403)"

echo ""
echo "=== Test 2: SQL Injection in query parameter ==="
# Test SQLi in query string
RESPONSE=$(curl -s -v \
  -X GET "$API_BASE/users?id=1%27%20OR%20%271%27%3D%271" \
  2>&1 | grep -E "< HTTP|error|SQL|syntax")
echo "SQLi test response headers:"
echo "$RESPONSE"

echo ""
echo "=== Test 3: OWASP ZAP API Scan ==="
# Full automated API security scan (requires ZAP running or Docker)
# docker run --rm -v $(pwd):/zap/wrk:rw \
#   ghcr.io/zaproxy/zaproxy:stable \
#   zap-api-scan.py \
#   -t https://api.example.com/openapi.json \
#   -f openapi \
#   -r /zap/wrk/zap-report.html \
#   -J /zap/wrk/zap-report.json \
#   -z "-config api.disablekey=true"
echo "(ZAP scan: replace with actual API URL and OpenAPI spec path)"

echo ""
echo "=== Test 4: Rate limiting check ==="
# Send 20 rapid requests and check for 429 Too Many Requests
for i in $(seq 1 20); do
  CODE=$(curl -s -o /dev/null -w "%{http_code}" "$API_BASE/health")
  echo -n "$CODE "
done
echo ""
echo "If no 429 seen above: Rate limiting may not be configured!"

✅ Kết quả mong đợi / Expected output: Test 1: 401/403 = authentication working. Nếu 200 = critical vulnerability. Test 2: phải không thấy SQL error messages — nếu có = injection vulnerability exposed. Test 4: sau 10-15 requests nên thấy 429 Too Many Requests — nếu tất cả 200 = rate limiting chưa cấu hình. ZAP report HTML chứa findings phân loại theo risk level (High/Medium/Low).

3. Tình huống doanh nghiệp / Real-world scenario

Bối cảnh:

Một startup SaaS B2B phát hiện trong log rằng AWS access keys của họ đã bị exfiltrate từ một public GitHub repository (developer commit nhầm). Attacker đã dùng keys để tạo EC2 instances cho crypto mining trước khi bị phát hiện. Security team cần post-incident hardening và ngăn tái diễn.

Root cause & Remediation:

  1. Root cause: AWS access keys hardcoded trong application config, committed to public GitHub. Không có pre-commit hook để detect secrets. Không có GitGuardian/TruffleHog monitoring.
  2. Immediate response: Revoke compromised keys ngay lập tức (aws iam delete-access-key). Rotate tất cả credentials. Enable AWS GuardDuty để detect subsequent unauthorized activity.
  3. OWASP CN-5 remediation: Migrate từ static access keys sang IAM Roles (EC2 instance profile). Cấu hình AWS Secrets Manager cho database credentials với auto-rotation 30 ngày. Add pre-commit hook: detect-secrets scan block commits chứa high-entropy strings.
  4. Pipeline hardening (CN-4): Implement GitHub Advanced Security secret scanning. Thêm Trivy secret scan trong CI/CD. Enforce branch protection rules: require PR review, no force push.
  5. Monitoring: CloudTrail → EventBridge rule alert on RunInstances từ unfamiliar regions. Budget alert nếu spending tăng bất thường >20%.

Bài học CCSP: Supply chain security (CN-8) và secrets management (CN-5) là hai trong số những vectors phổ biến nhất. Defense: không bao giờ dùng static long-lived credentials — luôn dùng IAM Roles hoặc managed identities.

4. Tự kiểm tra / Knowledge check

  1. Giải thích "shift-left security" và lợi ích về chi phí so với phát hiện lỗ hổng ở production. Nêu 3 security tools tương ứng với 3 giai đoạn khác nhau trong CI/CD pipeline.
  2. OWASP Cloud-Native Top 10 khác gì so với OWASP Web Application Top 10 truyền thống? Lấy 2 ví dụ về vulnerabilities đặc thù cho cloud-native context.
  3. mTLS giải quyết vấn đề gì mà TLS thông thường không giải quyết được? Trade-off khi implement Istio service mesh là gì?
  4. So sánh 3 tier của secrets management: environment variables, Kubernetes Secrets, và HashiCorp Vault. Khi nào upgrade từ K8s Secrets sang external vault?
  5. Container image signing với cosign bảo vệ chống lại loại tấn công nào trong software supply chain? Mô tả luồng từ build đến deployment.
  6. Một microservice gọi API của microservice khác với HTTP (không có TLS). Liệt kê tất cả security risks và đề xuất remediation với service mesh.
Chương 3: Bảo mật nền tảng Chương 5: Vận hành bảo mật đám mây
Thực hành trên công cụAzure CLI · Bash · OWASP ZAP
Nền tảngAny · Ubuntu 22.04
Thời điểm phát hànhQ2/2026
Ngày biên soạn24/05/2026
Người biên soạnTrần Văn Hòa (MCT)
Phiên bảnv1.0
Zalo