Bảo mật Container và Supply Chain Security 2026 — SBOM, Cosign, SLSA, Trivy cho DevSecOps
Posted on: 4/21/2026 11:15:15 PM
Table of contents
- 1. Bức tranh toàn cảnh — Tại sao Supply Chain Security trở thành ưu tiên số 1
- 2. SBOM — Software Bill of Materials: Biết chính xác bạn đang chạy gì
- 3. Image Signing với Sigstore/Cosign — Xác minh nguồn gốc container
- 4. SLSA Framework — Supply-chain Levels for Software Artifacts
- 5. Vulnerability Scanning — Phát hiện lỗ hổng trước khi chúng đến production
- 6. Pipeline DevSecOps End-to-End — Kết hợp tất cả
- 7. Continuous Monitoring — Bảo mật không dừng ở CI/CD
- 8. Checklist triển khai cho team
- 9. Kết luận
Năm 2026, container không còn chỉ là cách đóng gói ứng dụng — chúng trở thành đơn vị triển khai cốt lõi của mọi hệ thống production. Nhưng cùng với sự phổ biến đó, software supply chain attack đã tăng 742% trong 3 năm qua. Từ vụ SolarWinds đến các cuộc tấn công typosquatting trên npm/PyPI, rủi ro không còn nằm ở code bạn viết — mà ở code bạn kéo về.
Bài viết này đi sâu vào 4 trụ cột bảo mật container hiện đại: SBOM (biết bạn đang chạy gì), Image Signing (tin tưởng nguồn gốc), SLSA (xác minh quy trình build), và Vulnerability Scanning (phát hiện lỗ hổng sớm). Tất cả kết hợp thành một pipeline DevSecOps end-to-end.
1. Bức tranh toàn cảnh — Tại sao Supply Chain Security trở thành ưu tiên số 1
Trước 2020, bảo mật container chủ yếu dừng ở việc scan CVE định kỳ. Nhưng hàng loạt sự cố đã thay đổi cục diện:
⚠ Thực tế đáng lo ngại
Theo nghiên cứu của Sonatype, 96% các open-source package có lỗ hổng đều đã có phiên bản đã vá — nhưng developer không cập nhật. Supply chain security không chỉ là công cụ, mà là văn hóa và quy trình.
2. SBOM — Software Bill of Materials: Biết chính xác bạn đang chạy gì
SBOM là danh sách đầy đủ mọi component bên trong container image — từ base OS packages, language-specific dependencies đến transitive dependencies mà bạn không trực tiếp khai báo.
2.1 Tại sao SBOM quan trọng?
Khi Log4Shell xảy ra, các tổ chức có SBOM đã trả lời được câu hỏi "chúng tôi có bị ảnh hưởng không?" trong vài phút. Những tổ chức không có mất vài tuần để audit thủ công. SBOM biến reactive incident response thành proactive risk management.
2.2 Hai chuẩn SBOM phổ biến
| Tiêu chí | SPDX (Linux Foundation) | CycloneDX (OWASP) |
|---|---|---|
| Tiêu chuẩn | ISO/IEC 5962:2021 | ECMA-424, OWASP standard |
| Focus | License compliance + security | Security-first, VEX tích hợp |
| Format | JSON, XML, RDF, Tag-Value | JSON, XML, Protobuf |
| Tooling | Rộng hơn (dùng lâu hơn) | Hiện đại hơn, có VDR/VEX |
| Phù hợp cho | Compliance, license audit | DevSecOps, vulnerability mgmt |
2.3 Tạo SBOM với Trivy
Trivy (của Aqua Security) là scanner đa năng nhất hiện tại — vừa scan vulnerability, vừa generate SBOM, vừa kiểm tra misconfiguration. Phiên bản mới nhất (v0.69+) hỗ trợ concurrent DB access cho parallel CI pipelines.
# Generate SBOM ở format CycloneDX cho .NET image
trivy image --format cyclonedx --output sbom.json myapp:latest
# Generate SBOM ở format SPDX
trivy image --format spdx-json --output sbom-spdx.json myapp:latest
# Scan từ SBOM có sẵn (không cần pull image lại)
trivy sbom sbom.json
✅ Best Practice: SBOM at Build Time
Luôn generate SBOM tại thời điểm build (trong CI/CD pipeline), KHÔNG phải sau khi deploy. SBOM tạo từ build input chính xác hơn SBOM reverse-engineer từ image đã build, vì có đầy đủ thông tin dependency resolution.
2.4 Docker Scout — SBOM native trong Docker
Docker Scout tích hợp trực tiếp vào Docker Desktop và Docker Hub, tổng hợp dữ liệu từ 23 advisory sources bao gồm NVD, GitHub Advisory Database, và các vendor-specific feeds. Ưu điểm lớn nhất là Package URL (PURL) matching giúp giảm đáng kể false positives.
# Phân tích image ngay trong Docker CLI
docker scout cves myapp:latest
# Generate SBOM
docker scout sbom myapp:latest --format cyclonedx --output sbom.json
# So sánh hai image versions
docker scout compare myapp:v2 --to myapp:v1
3. Image Signing với Sigstore/Cosign — Xác minh nguồn gốc container
SBOM cho bạn biết có gì trong container, nhưng ai đảm bảo image bạn pull về đúng là image được build bởi CI/CD pipeline đáng tin cậy? Đây là bài toán của image signing.
3.1 Sigstore — Hạ tầng signing cho open-source
Sigstore là dự án của OpenSSF (Open Source Security Foundation), bao gồm 3 thành phần chính:
graph TD
A[Developer / CI Pipeline] -->|Request certificate| B[Fulcio
Certificate Authority]
B -->|Short-lived cert
OIDC-verified| A
A -->|Sign artifact| C[Container Registry
OCI Artifact]
A -->|Record signature| D[Rekor
Transparency Log]
E[Consumer / K8s] -->|Verify signature| C
E -->|Check transparency log| D
style A fill:#e94560,stroke:#fff,color:#fff
style B fill:#2c3e50,stroke:#fff,color:#fff
style C fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style D fill:#2c3e50,stroke:#fff,color:#fff
style E fill:#4CAF50,stroke:#fff,color:#fff
Kiến trúc Sigstore: Fulcio cấp certificate, Rekor ghi nhận minh bạch, Consumer verify
- Fulcio — Certificate Authority miễn phí, cấp short-lived certificate (thường 10 phút) dựa trên OIDC identity (GitHub, Google, Microsoft).
- Rekor — Transparency log công khai, ghi lại mọi signing event để bất kỳ ai cũng có thể audit.
- Cosign — CLI tool để sign và verify container images, SBOM, và các OCI artifacts khác.
3.2 Keyless Signing — Không cần quản lý key
Cách tiếp cận truyền thống yêu cầu bạn tạo key pair, bảo vệ private key, rotate định kỳ — phức tạp và rủi ro nếu key bị lộ. Keyless signing của Cosign v3 loại bỏ hoàn toàn vấn đề này:
# Sign image — Cosign tự động dùng OIDC identity từ GitHub Actions
cosign sign ghcr.io/myorg/myapp:v2.1.0
# Verify image — kiểm tra identity + OIDC issuer
cosign verify ghcr.io/myorg/myapp:v2.1.0 \
--certificate-identity=https://github.com/myorg/myapp/.github/workflows/build.yml@refs/heads/main \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com
# Sign kèm SBOM attestation
cosign attest --predicate sbom.json --type cyclonedx ghcr.io/myorg/myapp:v2.1.0
Keyless Signing hoạt động thế nào?
1) CI job authenticate với OIDC provider (GitHub Actions) → 2) Fulcio verify OIDC token và cấp short-lived certificate chứa identity claim → 3) Cosign sign image bằng certificate này → 4) Signature + certificate được ghi vào Rekor transparency log → 5) Ephemeral private key bị hủy ngay lập tức. Kết quả: bạn có cryptographic proof mà không bao giờ cần giữ private key.
3.3 Verify trong Kubernetes với Policy Controller
Signing image chỉ có ý nghĩa khi Kubernetes cluster enforce verification. Sigstore Policy Controller (hoặc Kyverno/OPA Gatekeeper) chặn image chưa được sign:
# Kyverno ClusterPolicy — chỉ cho phép image đã ký bởi CI pipeline
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: verify-image-signature
spec:
validationFailureAction: Enforce
rules:
- name: check-cosign-signature
match:
any:
- resources:
kinds: ["Pod"]
verifyImages:
- imageReferences: ["ghcr.io/myorg/*"]
attestors:
- entries:
- keyless:
subject: "https://github.com/myorg/*"
issuer: "https://token.actions.githubusercontent.com"
rekor:
url: https://rekor.sigstore.dev
4. SLSA Framework — Supply-chain Levels for Software Artifacts
SLSA (phát âm "salsa") là framework từ Google/OpenSSF, định nghĩa 4 cấp độ bảo mật cho build pipeline. Mục tiêu: đảm bảo artifact bạn deploy đúng là artifact được tạo từ source code đã review.
4.1 Bốn cấp độ SLSA Build Track
graph LR
L0[L0
Không có provenance] --> L1[L1
Provenance tồn tại]
L1 --> L2[L2
Hosted build
Signed provenance]
L2 --> L3[L3
Hardened build
Isolated environment]
style L0 fill:#f8f9fa,stroke:#e0e0e0,color:#888
style L1 fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style L2 fill:#e94560,stroke:#fff,color:#fff
style L3 fill:#2c3e50,stroke:#fff,color:#fff
SLSA Build Track: từ L0 (không có gì) đến L3 (hardened, isolated build)
| Level | Yêu cầu | Bảo vệ chống lại | Ví dụ |
|---|---|---|---|
| L0 | Không có provenance | Không | Build trên máy developer |
| L1 | Provenance được generate tự động | Sai lệch không cố ý | GitHub Actions ghi log build |
| L2 | Hosted build + Signed provenance | Giả mạo provenance | GitHub Actions + SLSA generator |
| L3 | Isolated build environment, không reuse | Build system bị compromise | Ephemeral container runners |
4.2 Đạt SLSA L3 với GitHub Actions
GitHub Actions cung cấp SLSA Container Generator chính thức, giúp bạn đạt SLSA L3 mà không cần tự xây dựng infrastructure:
# .github/workflows/release.yml
name: Build and Push with SLSA Provenance
on:
push:
tags: ['v*']
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write # Cần cho keyless signing
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- uses: actions/checkout@v4
- name: Build and push
id: build
uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/myorg/myapp:${{ github.ref_name }}
provenance:
needs: build
permissions:
actions: read
id-token: write
packages: write
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.1.0
with:
image: ghcr.io/myorg/myapp
digest: ${{ needs.build.outputs.digest }}
registry-username: ${{ github.actor }}
secrets:
registry-password: ${{ secrets.GITHUB_TOKEN }}
✅ SLSA Level 2 là mục tiêu thực tế cho hầu hết team
SLSA L3 yêu cầu ephemeral, isolated build environment — điều mà GitHub Actions hosted runners đã đáp ứng. Tuy nhiên, nếu bạn dùng self-hosted runners, cần đảm bảo chúng là ephemeral (tạo mới cho mỗi job, không reuse). Đa số team nên bắt đầu ở L2 rồi tiến dần lên L3.
5. Vulnerability Scanning — Phát hiện lỗ hổng trước khi chúng đến production
5.1 So sánh các scanner phổ biến
| Tool | Loại | SBOM | License | Đặc điểm nổi bật |
|---|---|---|---|---|
| Trivy | Multi-purpose | ✅ CycloneDX, SPDX | Apache 2.0 | Scan image, filesystem, IaC, K8s config. Nhanh nhất trong nhóm OSS |
| Docker Scout | Docker-native | ✅ CycloneDX, SPDX | Proprietary (free tier) | 23 advisory sources, PURL matching, tích hợp Docker Desktop |
| Grype | Vulnerability | ✅ (qua Syft) | Apache 2.0 | Nhẹ, nhanh, pair với Syft cho SBOM. Của Anchore |
| Snyk Container | Commercial | ✅ | Proprietary (free tier) | Base image recommendation, fix PR tự động |
5.2 Pipeline scan thực tế với Trivy trong GitHub Actions
# Scan trong CI — fail build nếu có HIGH/CRITICAL
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ghcr.io/myorg/myapp:${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'HIGH,CRITICAL'
exit-code: '1' # Fail pipeline nếu phát hiện
- name: Upload Trivy scan results to GitHub Security
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
⚠ Đừng chỉ scan — hãy hành động
Sai lầm phổ biến nhất: chạy scanner trong CI nhưng chỉ generate report mà không fail build. Nếu bạn không block deployment khi có HIGH/CRITICAL CVE, scanner chỉ là decoration. Thiết lập exit-code: 1 và xử lý exception cho các false positive bằng .trivyignore file.
5.3 Scan .NET container image hiệu quả
Với .NET, best practice là dùng chiseled images (Ubuntu distroless) để giảm attack surface trước khi scan:
# Multi-stage build — .NET 10 chiseled image
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /app --no-restore
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled AS runtime
WORKDIR /app
COPY --from=build /app .
# Non-root user (chiseled images mặc định non-root)
USER $APP_UID
ENTRYPOINT ["dotnet", "MyApp.dll"]
# So sánh CVE count giữa image thường và chiseled
trivy image mcr.microsoft.com/dotnet/aspnet:10.0 # ~50-80 CVEs
trivy image mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled # ~5-10 CVEs
6. Pipeline DevSecOps End-to-End — Kết hợp tất cả
Dưới đây là kiến trúc pipeline hoàn chỉnh kết hợp cả 4 trụ cột:
graph TD
A[Source Code
GitHub] -->|Push / PR| B[Build
docker build]
B --> C[SBOM Generation
Trivy / Syft]
B --> D[Vulnerability Scan
Trivy + Docker Scout]
D -->|CRITICAL found?| E{Gate}
E -->|Yes| F[❌ Block Deploy]
E -->|No| G[Image Signing
Cosign keyless]
C --> G
G --> H[Push to Registry
+ SBOM attestation]
H --> I[SLSA Provenance
L3 Generator]
I --> J[Deploy to K8s]
J --> K[Admission Control
Kyverno verify]
K -->|Signature valid?| L{Gate}
L -->|Yes| M[✅ Pod Running]
L -->|No| N[❌ Rejected]
style A fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style B fill:#2c3e50,stroke:#fff,color:#fff
style G fill:#e94560,stroke:#fff,color:#fff
style I fill:#e94560,stroke:#fff,color:#fff
style K fill:#4CAF50,stroke:#fff,color:#fff
style M fill:#4CAF50,stroke:#fff,color:#fff
style F fill:#ff9800,stroke:#fff,color:#fff
style N fill:#ff9800,stroke:#fff,color:#fff
Pipeline DevSecOps end-to-end: Build → Scan → Sign → Provenance → Verify → Deploy
6.1 GitHub Actions Workflow hoàn chỉnh
name: Secure Container Pipeline
on:
push:
branches: [main]
permissions:
contents: read
packages: write
id-token: write
security-events: write
env:
IMAGE: ghcr.io/${{ github.repository }}
jobs:
build-scan-sign:
runs-on: ubuntu-latest
outputs:
digest: ${{ steps.push.outputs.digest }}
steps:
- uses: actions/checkout@v4
# 1. Build image
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ env.IMAGE }}:${{ github.sha }}
# 2. Generate SBOM
- name: Generate SBOM
run: |
trivy image --format cyclonedx \
--output sbom.cdx.json \
${{ env.IMAGE }}:${{ github.sha }}
# 3. Vulnerability scan — fail on HIGH/CRITICAL
- name: Scan vulnerabilities
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMAGE }}:${{ github.sha }}
severity: 'HIGH,CRITICAL'
exit-code: '1'
format: 'sarif'
output: 'trivy.sarif'
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: trivy.sarif
# 4. Sign image (keyless via GitHub OIDC)
- uses: sigstore/cosign-installer@v3
- name: Sign image
run: cosign sign --yes ${{ env.IMAGE }}@${{ steps.push.outputs.digest }}
# 5. Attach SBOM attestation
- name: Attest SBOM
run: |
cosign attest --yes \
--predicate sbom.cdx.json \
--type cyclonedx \
${{ env.IMAGE }}@${{ steps.push.outputs.digest }}
# 6. SLSA L3 provenance
provenance:
needs: build-scan-sign
permissions:
actions: read
id-token: write
packages: write
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.1.0
with:
image: ${{ needs.build-scan-sign.outputs.image }}
digest: ${{ needs.build-scan-sign.outputs.digest }}
registry-username: ${{ github.actor }}
secrets:
registry-password: ${{ secrets.GITHUB_TOKEN }}
7. Continuous Monitoring — Bảo mật không dừng ở CI/CD
Vulnerability mới xuất hiện mỗi ngày. Image "sạch" hôm nay có thể có CRITICAL CVE vào tuần sau. Cần monitoring liên tục:
7.1 Registry-level scanning
- GitHub Container Registry — tích hợp Dependabot alerts cho container images
- AWS ECR — Enhanced scanning với Amazon Inspector, scan tự động khi push và scan lại định kỳ
- Azure ACR — Microsoft Defender for Containers scan continuous
- Docker Hub — Docker Scout monitoring dashboard
7.2 Runtime scanning trong Kubernetes
# Trivy Operator — scan mọi workload trong cluster liên tục
helm install trivy-operator aquasecurity/trivy-operator \
--namespace trivy-system --create-namespace \
--set trivy.severity="HIGH,CRITICAL" \
--set operator.scanJobTimeout=10m
# Xem vulnerability reports
kubectl get vulnerabilityreports -A -o wide
8. Checklist triển khai cho team
Dưới đây là lộ trình thực tế để áp dụng supply chain security từ zero:
| Tuần | Hành động | Tool | SLSA Level |
|---|---|---|---|
| 1-2 | Chuyển sang chiseled/distroless base images | Docker multi-stage build | — |
| 3-4 | Thêm vulnerability scan vào CI, fail on CRITICAL | Trivy + GitHub Actions | L0 → L1 |
| 5-6 | Generate SBOM tại build time, lưu cạnh image | Trivy / Syft / Docker Scout | L1 |
| 7-8 | Keyless image signing trong CI | Cosign + Sigstore | L2 |
| 9-10 | SLSA provenance generation | slsa-github-generator | L2 → L3 |
| 11-12 | Admission control trong K8s — enforce signed images | Kyverno / Sigstore Policy Controller | L3 |
✅ Bắt đầu nhỏ, mở rộng dần
Đừng cố triển khai tất cả cùng lúc. Bắt đầu bằng vulnerability scanning (tuần 3-4) — đây là bước có ROI cao nhất. Sau khi team quen với việc fix CVE trước deploy, mới thêm signing và provenance. Supply chain security là marathon, không phải sprint.
9. Kết luận
Container supply chain security năm 2026 không còn là "nice-to-have" — với EU Cyber Resilience Act bắt buộc SBOM từ tháng 9/2026 và sự gia tăng không ngừng của supply chain attacks, đây là yêu cầu bắt buộc. Tin tốt là hệ sinh thái công cụ đã đủ trưởng thành: Trivy cho scanning + SBOM, Cosign cho keyless signing, SLSA cho build provenance — tất cả open-source, miễn phí, và tích hợp tốt với GitHub Actions.
Chiến lược đúng đắn là áp dụng defense-in-depth: không phụ thuộc vào một lớp bảo vệ duy nhất, mà kết hợp nhiều lớp (scan → sign → provenance → admission control) để ngay cả khi một lớp bị bypass, các lớp còn lại vẫn bắt được mối đe dọa.
Nguồn tham khảo:
SLSA — Supply-chain Levels for Software Artifacts ·
Sigstore Documentation ·
Trivy by Aqua Security ·
Docker Scout Documentation ·
Aqua Security — Supply Chain Security with Trivy ·
Cosign — GitHub ·
Chainguard — How to Sign a Container with Cosign ·
OpenSSF — Open Source Security Foundation
CQRS và Event Sourcing — Khi CRUD không còn đủ
GraphQL Federation — Gộp API Microservices thành một Supergraph thống nhất
Disclaimer: The opinions expressed in this blog are solely my own and do not reflect the views or opinions of my employer or any affiliated organizations. The content provided is for informational and educational purposes only and should not be taken as professional advice. While I strive to provide accurate and up-to-date information, I make no warranties or guarantees about the completeness, reliability, or accuracy of the content. Readers are encouraged to verify the information and seek independent advice as needed. I disclaim any liability for decisions or actions taken based on the content of this blog.