CSSLP · Domain 6 · 11%

Quản lý vòng đời bảo mật

Secure Lifecycle Management

DevSecOps pipeline integration, security gates trong CI/CD, OWASP SAMM maturity model, vulnerability management, security debt — quản trị bảo mật xuyên suốt toàn bộ vòng đời phần mềm.

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

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

1.1. DevSecOps Pipeline Integration (Shift-Left Security in CI/CD)

DevSecOps là văn hóa + practice + tooling tích hợp security vào mọi giai đoạn của DevOps pipeline. Pre-commit: secret detection (detect-secrets, git-secrets), lint security rules (PSScriptAnalyzer, ESLint security plugin). CI — Build stage: SAST (Semgrep, SonarQube), SCA (OWASP Dependency-Check, Snyk). CI — Test stage: DAST trên ephemeral environment (ZAP API scan), IAST khi chạy integration tests. CD — Deploy stage: container image scan (Trivy, Grype), IaC scan (Checkov, tfsec). Post-deploy: RASP, WAF, DAST scheduled scans, penetration testing.

Security Gate vs Security Advisory: Security Gate = build fails (block merge), áp dụng cho Critical/High findings mới. Security Advisory = warning nhưng không block, áp dụng cho Medium/Low. Tránh "alert fatigue" — nếu quá nhiều thứ block build, developers bắt đầu bypass hoặc suppress warnings mà không đọc. Tune rules để giảm false positives trước khi enforce.

1.1b. IaC Security Scanning (Quét bảo mật Infrastructure as Code)

IaC scanners phát hiện misconfiguration trong template hạ tầng trước khi tài nguyên được tạo — đây là điểm shift-left cao nhất trong CI/CD pipeline. Ba công cụ phổ biến:

cfn-nag: quét AWS CloudFormation templates, flag security issues theo mã WARN/FAIL. Cài đặt và dùng: gem install cfn-nag && cfn_nag_scan --input-path template.yaml. Các flag điển hình: WARN W2 (security group ingress CIDR mở 0.0.0.0/0), WARN W9 (CIDR không phải /32), FAIL F1000 (thiếu egress rule — toàn bộ outbound được phép mặc định), W28 (tên resource explicit — cản trở replacement update), W36 (security group rule không có description). Nguồn gốc: phát triển bởi Stelligent, open-source, chuẩn cho CloudFormation review.

Checkov: multi-cloud IaC scanner hỗ trợ Terraform, CloudFormation, Kubernetes manifests, Dockerfile, ARM templates, Helm charts. Cài và chạy: pip install checkov && checkov -d ./terraform --framework terraform. Quét Dockerfile: checkov -f docker-compose.yml --framework dockerfile. Output gồm PASSED / FAILED / SKIPPED với mã check như CKV_AWS_20 (S3 bucket public ACL), CKV_AWS_3 (EC2 EBS encryption) kèm CIS Benchmark references. Checkov có thể generate SARIF output để upload lên GitHub Code Scanning.

KICS (Keeping Infrastructure as Code Secure): open-source của Checkmarx, hơn 1.900 checks, hỗ trợ Ansible, Terraform, Kubernetes, Dockerfile. Lệnh: docker run -v $(pwd):/path checkmarx/kics:latest scan -p /path --report-formats json.

Security Gate — Block vs. Report (Chặn vs. Báo cáo)

Implementation trong GitHub Actions:

- name: IaC Security Scan
  run: checkov -d . --framework terraform --hard-fail-on HIGH
  # --hard-fail-on HIGH: exit code 1 nếu có bất kỳ HIGH finding nào → block pipeline

Waiver process: security team phê duyệt exception qua PR comment + ticket reference — không được tắt scanner không có audit trail. CSSLP principle: security gates là bắt buộc trong Secure SDLC, không phải optional reporting.

Lab — Checkov IaC Scan (Ubuntu 22.04)

Platform: Ubuntu 22.04 · Tools: checkov (Python 3.11), cfn-nag (Ruby)

# Bước 1: Cài Checkov
pip install checkov

# Bước 2: Tạo file Terraform cố tình có lỗ hổng bảo mật
cat > /tmp/main.tf << 'EOF'
resource "aws_s3_bucket" "bad_bucket" {
  bucket = "my-insecure-bucket"
}

resource "aws_s3_bucket_acl" "bad_acl" {
  bucket = aws_s3_bucket.bad_bucket.id
  acl    = "public-read"   # PUBLIC — vi phạm CKV_AWS_20
}

resource "aws_s3_bucket_server_side_encryption_configuration" "none" {
  # Không có encryption — vi phạm CKV_AWS_19
}

resource "aws_security_group" "open_sg" {
  name = "open-sg"
  ingress {
    from_port   = 0
    to_port     = 65535
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]  # Open to world — vi phạm CKV_AWS_25
  }
}
EOF

# Bước 3: Chạy Checkov — thấy FAILED
checkov -f /tmp/main.tf --framework terraform

# Bước 4: Xem kết quả (expected: FAILED với các mã CKV_AWS_xxx)
# Sau khi fix: xóa public-read ACL, thêm server_side_encryption, restrict CIDR
# Re-run → tất cả PASSED

Kết quả mong đợi / Expected output: Checkov báo FAILED: CKV_AWS_20 (S3 public ACL), CKV_AWS_19 (S3 encryption disabled), CKV_AWS_25 (security group ingress 0.0.0.0/0 port range). Sau khi sửa: Passed checks: 3, Failed checks: 0. Pipeline tích hợp flag --hard-fail-on HIGH → exit code 1 khi có FAILED → build bị block trước khi deploy lên AWS.

1.2. OWASP SAMM Maturity Assessment (Software Assurance Maturity Model)

OWASP SAMM v2.0 đánh giá AppSec maturity theo 5 Business Functions, mỗi function có 3 Practices, mỗi Practice có 3 Maturity Levels (1-3): Governance (Strategy & Metrics, Policy & Compliance, Education & Guidance); Design (Threat Assessment, Security Requirements, Security Architecture); Implementation (Secure Build, Secure Deployment, Defect Management); Verification (Architecture Assessment, Requirements-driven Testing, Security Testing); Operations (Incident Management, Environment Management, Operational Management). Điểm tối đa: 3.0/practice. Tổ chức mới thường đạt 0.5-1.0. Target thực tế sau 1 năm: 1.5.

1.3. Vulnerability Management (CVE / CVSS / Patch SLA)

CVE (Common Vulnerabilities and Exposures): định danh duy nhất cho vulnerability. NVD (National Vulnerability Database): enrichment với CVSS score, CPE, CWE. CVSS v3.1: Base Score (0-10) tính từ Attack Vector, Attack Complexity, Privileges Required, User Interaction, Scope, CIA Impact. Patch SLA theo severity điển hình: Critical (CVSS 9.0-10.0) → 24-72 giờ; High (7.0-8.9) → 7-14 ngày; Medium (4.0-6.9) → 30-60 ngày; Low (0.1-3.9) → 90 ngày hoặc next release. Risk-based patching: CVSS + exploitability (EPSS score) + asset criticality → ưu tiên patch thực tế.

1.4. Security Champions & Developer Training (AppSec Culture)

Security Champions program: mỗi development team có 1-2 "Security Champions" — developer kiêm nhiệm vai trò security advocate trong team. Champions: attend security training sâu hơn, review security items trong sprint, bridge giữa AppSec team và dev team, không phải security expert nhưng là "security-aware developer". Developer security training: hands-on beats lecture — OWASP WebGoat (SQL injection, XSS labs), OWASP Juice Shop (gamified OWASP Top 10), DVWA (Damn Vulnerable Web App). Platform: Secure Code Warrior, Checkmarx Codebashing, SANS Developer Security Training. Cadence: onboarding training + quarterly refreshers + post-incident lessons learned.

1.5. AppSec Metrics & Security Debt Management (Measuring What Matters)

Metrics đo lường hiệu quả AppSec: Vulnerability Density = số vulnerabilities / KLOC (thousand lines of code) — giảm theo thời gian = cải thiện; Mean Time to Fix (MTTF) = thời gian trung bình từ khi phát hiện đến khi fix theo severity; Coverage = % codebase được SAST scan, % endpoints được DAST scan; Security Debt Ratio = số open vulnerabilities × CVSS / team velocity. Security backlog: mỗi vulnerability là một item trong backlog với severity-based priority. Sprint allocation: nhiều teams dành 10-15% sprint capacity cho security debt.

1.6. STRIDE Áp dụng cho CI/CD Pipeline (STRIDE Applied to CI/CD Pipeline)

STRIDE thường được dạy trong bối cảnh thiết kế ứng dụng (application design). Tuy nhiên, pipeline CI/CD cũng là một hệ thống có attack surface riêng — và CSSLP yêu cầu threat modeling bao gồm toàn bộ SDLC. Bảng dưới áp dụng STRIDE cho từng giai đoạn pipeline:

STRIDE Threat trong CI/CD Pipeline Giai đoạn Biện pháp giảm thiểu
Spoofing Commit giả mạo danh tính; service account bị chiếm dùng để trigger pipeline Source / SCM Signed commits (GPG); OIDC tokens thay vì long-lived credentials; branch protection rules
Tampering Artifact bị sửa đổi giữa build và deploy (supply chain attack) Build / Artifact registry Artifact signing (Sigstore/cosign); immutable artifact versions; checksum verification
Repudiation Không có audit trail — ai approve deployment? Ai merge code? Toàn pipeline Immutable deployment logs; required PR approvals; audit log retention ≥ 1 năm
Info Disclosure Secrets trong environment variables, build logs, hoặc artifact metadata Build / CD Vault/Secrets Manager integration; secret scanning trong logs; mask secrets trong CI output
Denial of Service Pipeline resource exhaustion — tràn queue build, runner cạn kiệt khiến không deploy được CI runners Runner concurrency limits; build timeouts; rate limiting trên webhook triggers
Elevation of Privilege CI runner có quá nhiều IAM permissions — bị exploit để deploy trái phép hoặc access production data Deploy / Cloud Least-privilege runner roles; separate IAM roles per environment; no wildcard (*) permissions

CSSLP exam note: STRIDE cho pipeline là chủ đề kết hợp giữa Threat Modeling (Domain 3) và Secure Lifecycle Management (Domain 6). Khi đề bài nói "threat model cho CI/CD", áp dụng STRIDE theo bảng trên. Biện pháp quan trọng nhất: signed commits (Spoofing), artifact signing (Tampering), và least-privilege runner IAM (Elevation of Privilege).

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

🖥️ Nền tảng / Platform: Windows 11 · Ubuntu 22.04 LTS
🛠️ Công cụ / Tools: PowerShell 7 · Bash + Docker + Trivy

Lab 1 — Mô phỏng CI/CD Security Gate (PowerShell)

OS: Windows 11 · Tool: PowerShell 7 — mô phỏng security gate logic trong pipeline.

# Mô phỏng Security Gate trong CI/CD pipeline
# Logic: Critical findings → fail build; High → warn; Medium/Low → report only

Write-Host "=== DevSecOps Security Gate Simulation ===" -ForegroundColor Cyan
Write-Host "Simulating SAST scan results...`n"

# Giả lập kết quả SAST scan (trong thực tế: đọc từ Semgrep/SonarQube JSON output)
$scanFindings = @(
    [PSCustomObject]@{ Severity="CRITICAL"; Rule="sql-injection";      File="src/login.cs";    Line=45 },
    [PSCustomObject]@{ Severity="HIGH";     Rule="hardcoded-password"; File="src/config.cs";   Line=12 },
    [PSCustomObject]@{ Severity="HIGH";     Rule="xxe-injection";      File="src/parser.cs";   Line=78 },
    [PSCustomObject]@{ Severity="MEDIUM";   Rule="weak-cipher";        File="src/crypto.cs";   Line=23 },
    [PSCustomObject]@{ Severity="LOW";      Rule="verbose-errors";     File="src/api.cs";      Line=156 }
)

# Display findings
$scanFindings | Format-Table Severity, Rule, File, Line -AutoSize

# Security gate logic
$critical = $scanFindings | Where-Object { $_.Severity -eq "CRITICAL" }
$high      = $scanFindings | Where-Object { $_.Severity -eq "HIGH" }
$medium    = $scanFindings | Where-Object { $_.Severity -eq "MEDIUM" }

Write-Host "--- Security Gate Evaluation ---" -ForegroundColor Yellow
Write-Host "Critical: $($critical.Count)  High: $($high.Count)  Medium: $($medium.Count)"

if ($critical.Count -gt 0) {
    Write-Host "`n[BUILD FAILED] $($critical.Count) CRITICAL finding(s) — must fix before merge!" -ForegroundColor Red
    $critical | ForEach-Object { Write-Host "  FIX REQUIRED: $($_.Rule) in $($_.File):$($_.Line)" -ForegroundColor Red }
    exit 1
} elseif ($high.Count -gt 0) {
    Write-Host "`n[BUILD WARNING] $($high.Count) HIGH finding(s) — review required within 7 days." -ForegroundColor Yellow
    Write-Host "[BUILD PASSED] No critical blockers — proceeding with warnings." -ForegroundColor Green
    exit 0
} else {
    Write-Host "`n[BUILD PASSED] No critical or high findings!" -ForegroundColor Green
    exit 0
}

✅ Kết quả mong đợi / Expected output: Script hiển thị bảng findings, sau đó evaluate: 1 CRITICAL (sql-injection) → [BUILD FAILED] với exit code 1. CI/CD system nhận exit code 1 → fail pipeline, block merge. Ý nghĩa: Logic này là core của mọi security gate — thay thế $scanFindings bằng output JSON thực từ Semgrep/SonarQube để integrate vào GitHub Actions, Azure DevOps, Jenkins.

Lab 2 — DevSecOps Pipeline với Docker + Trivy (Bash)

OS: Ubuntu 22.04 · Tool: Bash + Docker + Trivy + sample GitHub Actions YAML.

# Build Docker image và scan vulnerabilities với Trivy
echo "=== DevSecOps: Container Image Security Scan ==="

# Tạo Dockerfile mẫu (intentionally using older base for demo)
cat > /tmp/Dockerfile.demo << 'EOF'
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]
EOF

# Tạo requirements.txt với dependencies (có thể có CVEs)
cat > /tmp/requirements.txt << 'EOF'
flask==2.0.1
requests==2.25.1
pyyaml==5.3.1
EOF

# Build image (nếu Docker available)
if command -v docker &>/dev/null; then
    cd /tmp && docker build -f Dockerfile.demo -t demo-app:latest . 2>/dev/null
    echo "--- Trivy Image Scan ---"
    trivy image --severity HIGH,CRITICAL demo-app:latest 2>/dev/null | grep -E "Total|HIGH|CRITICAL|Library" | head -20
else
    echo "Docker not available — showing Trivy filesystem scan instead"
    trivy fs --severity HIGH,CRITICAL /tmp/ 2>/dev/null | head -20
fi

# Hiển thị sample GitHub Actions security pipeline
echo ""
echo "=== Sample GitHub Actions: Security Pipeline YAML ==="
cat << 'YAML'
# .github/workflows/security.yml
name: Security Pipeline
on: [push, pull_request]
jobs:
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: SAST - Semgrep
        run: semgrep --config p/owasp-top-ten --error .
      - name: SCA - OWASP Dependency Check
        run: dependency-check --scan . --format JSON --failOnCVSS 9
      - name: Build Docker Image
        run: docker build -t myapp:${{ github.sha }} .
      - name: Container Scan - Trivy
        run: trivy image --exit-code 1 --severity CRITICAL myapp:${{ github.sha }}
      - name: DAST - ZAP Baseline
        run: docker run zaproxy/zap-stable zap-baseline.py -t http://staging.example.com
YAML

✅ Kết quả mong đợi / Expected output: Trivy scan báo vulnerabilities trong base image và Python packages (pyyaml 5.3.1 có CVE-2020-14343 CRITICAL). GitHub Actions YAML minh họa pipeline hoàn chỉnh: SAST → SCA → Build → Container Scan → DAST. Ý nghĩa: pipeline này là template cho bất kỳ team nào muốn implement DevSecOps trong vòng 1 sprint.

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

Bối cảnh:

Một công ty SaaS với 50 developers, 3 team, không có AppSec program. Sau audit ISO 27001, họ cần cải thiện SAMM score từ 0.7 lên 1.5 trong 6 tháng với budget hạn chế.

Roadmap 6 tháng:

  1. Tháng 1: SAMM baseline assessment. Chọn 1 Security Champion mỗi team. Cài Semgrep vào CI (warn-only, không block).
  2. Tháng 2: Security backlog: inventory tất cả known vulnerabilities. Định nghĩa patch SLA. Developer training với OWASP Juice Shop (1 buổi/team).
  3. Tháng 3: Enable SAST security gates (Critical only). Integrate SCA (Snyk). Threat modeling cho top 3 critical services.
  4. Tháng 4-5: Expand gates sang High findings. DAST pipeline cho staging. Security Champions meeting monthly.
  5. Tháng 6: SAMM re-assessment. External pentest. Publish AppSec metrics dashboard cho leadership.

Bài học: SAMM improvement không cần budget lớn — tất cả tools trên đều có free tier. Investment chính là developer time và cultural change. Security Champions program là ROI cao nhất.

4. Tự kiểm tra / Knowledge check

  1. Security gate trong CI/CD nên block build ở severity nào? Tại sao không block tất cả findings?
  2. OWASP SAMM có mấy Business Functions và mấy Maturity Levels? Tổ chức startup nên nhắm mức nào?
  3. CVSS score 8.5 thuộc severity nào? Patch SLA điển hình là bao nhiêu ngày?
  4. Security Champions program khác gì với dedicated AppSec team? Ưu và nhược điểm?
  5. "Vulnerability Density" metric đo lường gì và cách interpret xu hướng tăng/giảm?
C05: Kiểm thử bảo mật C07: Triển khai & Vận hành
Thực hành trên công cụPowerShell 7 · Docker · Trivy · GitHub Actions
Nền tảngWindows 11 · Ubuntu 22.04 LTS
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