Feb 2026 • Supply Chain Security

Docker SBOM & Provenance Attestations

คู่มือ Supply Chain Security ฉบับสมบูรณ์สำหรับ Docker Images

เรียนรู้การสร้างและตรวจสอบ SBOM และ Provenance Attestations เพื่อป้องกัน Supply Chain Attacks และสร้างความน่าเชื่อถือให้ซอฟต์แวร์ของคุณ

Docker
SLSA
SPDX
Sigstore

1. บทนำ

ในปี 2025-2026 Supply Chain Security กลายเป็นหัวข้อที่สำคัญที่สุดด้านความปลอดภัยของซอฟต์แวร์ โดย Supply Chain Attacks สร้างความเสียหายกว่า 60 พันล้านดอลลาร์สหรัฐ ในปี 2025

SBOM (Software Bill of Materials) และ Provenance Attestations เป็นเครื่องมือสำคัญที่ช่วยให้เราทราบว่าซอฟต์แวร์ของเรามีอะไรบ้าง และมาจากไหน ทำให้สามารถตรวจสอบและติดตามช่องโหว่ได้อย่างรวดเร็ว

ทำไม Supply Chain Security ถึงสำคัญ?

  • SolarWinds attack (2020) - ส่งผลกระทบ 18,000+ องค์กร
  • Log4j vulnerability (2021) - พบใน 35%+ ของแอปพลิเคชันทั่วโลก
  • Codecov breach (2021) - กระทบหลายพันโปรเจค
  • xz-utils backdoor (2024) - พยายามแทรกโค้ดอันตรายใน compression library

ตรวจสอบช่องโหว่ได้เร็ว

ทราบทันทีว่ามี package ใดบ้างที่มีช่องโหว่

Compliance Ready

สอดคล้องกับมาตรฐาน SLSA, NIST, SOC2

สร้างความน่าเชื่อถือ

ลูกค้ามั่นใจในความปลอดภัยของซอฟต์แวร์

2. SBOM คืออะไร

SBOM (Software Bill of Materials) คือรายการสินค้าครบชุดของซอฟต์แวร์ คล้ายกับรายการส่วนผสมในอาหาร ที่แสดงว่าซอฟต์แวร์นั้นประกอบด้วยอะไรบ้าง

โครงสร้าง SBOM

Docker Image Software Bill of Materials (SBOM) Base OS Alpine 3.19 Runtime Node.js 20.11 Application express, lodash... Dependencies (Transitive) body-parser cookie debug ms +127

รูปแบบ SBOM ที่นิยม

SPDX Linux Foundation

มาตรฐานเปิดที่ได้รับการสนับสนุนจาก Linux Foundation ใช้กันอย่างแพร่หลาย

CycloneDX OWASP

พัฒนาโดย OWASP เน้นที่ความปลอดภัยและการจัดการช่องโหว่

ตัวอย่างข้อมูลใน SBOM

sbom.spdx.json (ตัวอย่าง)
{
  "SPDXID": "SPDXRef-DOCUMENT",
  "name": "myapp",
  "packages": [
    {
      "SPDXID": "SPDXRef-package-express",
      "name": "express",
      "versionInfo": "4.18.2",
      "licenseConcluded": "MIT",
      "externalRefs": [
        {
          "referenceCategory": "PACKAGE_MANAGER",
          "referenceLocator": "pkg:npm/express@4.18.2",
          "referenceType": "purl"
        }
      ]
    }
  ]
}

3. Provenance คืออะไร

Provenance Attestation คือหลักฐานที่แสดงว่า software artifact ถูกสร้างขึ้นอย่างไร รวมถึงข้อมูลเกี่ยวกับ:

  • Who - ใครเป็นคน build (builder identity)
  • What - ใช้ source code อะไร (repository, commit)
  • Where - build ที่ไหน (CI/CD platform)
  • When - build เมื่อไหร่ (timestamp)
  • How - build อย่างไร (build commands, environment)

Provenance Flow

Source Code GitHub Repo CI/CD Build Process Provenance SLSA Attestation Signed Image + Attestations commit: abc123 GitHub Actions in-toto format Sigstore/Cosign

4. SLSA Framework

SLSA (Supply-chain Levels for Software Artifacts) เป็นกรอบมาตรฐานด้านความปลอดภัยของ Supply Chain ที่พัฒนาโดย Google และ OpenSSF โดยแบ่งเป็น 4 ระดับ:

L1

Level 1: Documentation

มีเอกสารบันทึกกระบวนการ build อย่างครบถ้วน

Requirements: Provenance exists, basic build info

L2

Level 2: Tamper Resistance

มีการป้องกันการแก้ไข provenance หลังจาก build

Requirements: Signed provenance, hosted build platform

L3

Level 3: Hardened Builds

กระบวนการ build มีความปลอดภัยสูง ป้องกันการแทรกแซง

Requirements: Non-falsifiable provenance, isolated builds

Docker Hardened Images รองรับ
L4

Level 4: Maximum Assurance

ระดับสูงสุด มีการตรวจสอบย้อนกลับได้อย่างสมบูรณ์

Requirements: Two-party review, hermetic builds

5. สิ่งที่ต้องเตรียม

Requirements

Software

  • Docker 23.0+ (BuildKit default)
  • Docker Buildx 0.10+
  • Cosign (optional, สำหรับ signing)
  • Trivy (optional, สำหรับ scanning)

Knowledge

  • Docker fundamentals
  • Basic CI/CD concepts
  • Container security basics

ติดตั้งเครื่องมือ

ตรวจสอบ Docker Version

Terminal
# ตรวจสอบ Docker version
docker version

# ตรวจสอบ BuildKit
docker buildx version

# สร้าง builder สำหรับ attestations (ถ้ายังไม่มี)
docker buildx create --name mybuilder --use
docker buildx inspect --bootstrap

ติดตั้ง Cosign (Optional)

Terminal
# macOS
brew install cosign

# Linux
curl -O https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64
sudo mv cosign-linux-amd64 /usr/local/bin/cosign
sudo chmod +x /usr/local/bin/cosign

# ตรวจสอบ version
cosign version

6. เริ่มต้นเร็ว

วิธีที่เร็วที่สุดในการสร้าง SBOM และ Provenance Attestations:

Quick Start Command
# Build พร้อมทั้ง SBOM และ Provenance
docker buildx build \
  --sbom=true \
  --provenance=true \
  -t myapp:latest \
  --push .

# หรือใช้ shorthand
docker buildx build --sbom --provenance -t myapp:latest --push .

หมายเหตุสำคัญ

Default image store ไม่รองรับ attestations ต้องใช้ --push เพื่อ push ไป registry หรือเปิดใช้งาน containerd image store

7. สร้าง SBOM Attestation

7.1 Basic SBOM Creation

สร้าง SBOM
# สร้าง SBOM attestation
docker buildx build \
  --tag myregistry/myapp:v1.0 \
  --attest type=sbom \
  --push .

# หรือใช้ shorthand
docker buildx build \
  --tag myregistry/myapp:v1.0 \
  --sbom=true \
  --push .

7.2 ตัวเลือกขั้นสูง

Scan Build Context

รวม build context ในการสแกน (ไฟล์ในโฟลเดอร์ที่ build)

Dockerfile
# syntax=docker/dockerfile:1
ARG BUILDKIT_SBOM_SCAN_CONTEXT=true
FROM alpine:3.19
# ...

Scan Build Stages

รวม build stages ในการสแกน (สำหรับ multi-stage builds)

Dockerfile (Multi-stage)
# syntax=docker/dockerfile:1
FROM node:20-alpine AS builder
ARG BUILDKIT_SBOM_SCAN_STAGE=true
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
# Final stage จะถูกสแกนอัตโนมัติ

ใช้ Custom SBOM Generator

ใช้ Syft หรือ Docker Scout เป็น generator

Terminal
# ใช้ default Syft generator
docker buildx build --sbom=true -t myapp:latest --push .

# ใช้ custom generator
docker buildx build \
  --attest type=sbom,generator=docker/scout-sbom \
  -t myapp:latest \
  --push .

7.3 Export SBOM เป็นไฟล์

Export SBOM
# Build และ export SBOM ไว้ที่ local
docker buildx build \
  --sbom=true \
  --output type=local,dest=./output \
  .

# ตรวจสอบไฟล์ SBOM
ls -la ./output/
# sbom.spdx.json

# ดูเนื้อหา SBOM
cat ./output/sbom.spdx.json | jq '.'

8. สร้าง Provenance Attestation

8.1 Basic Provenance

สร้าง Provenance
# สร้าง provenance attestation (default: mode=min)
docker buildx build \
  --tag myregistry/myapp:v1.0 \
  --provenance=true \
  --push .

# หรือใช้ mode=max เพื่อข้อมูลเต็ม
docker buildx build \
  --tag myregistry/myapp:v1.0 \
  --provenance=mode=max \
  --push .

8.2 Provenance Modes

mode=min Default

ข้อมูลพื้นฐาน: build timestamp, build parameters

mode=max Full

ข้อมูลครบถ้วน: source repo, commit, build commands, environment

Provenance Mode Options
# mode=min (default)
docker buildx build --provenance=true -t myapp:v1 --push .

# mode=max (full provenance)
docker buildx build --provenance=mode=max -t myapp:v1 --push .

# ปิด provenance
docker buildx build --provenance=false -t myapp:v1 --push .

# ใช้ environment variable เพื่อ disable default attestations
BUILDX_NO_DEFAULT_ATTESTATIONS=1 docker buildx build -t myapp:v1 --push .

9. ตรวจสอบ Attestations

9.1 ตรวจสอบ SBOM

Inspect SBOM
# ดู SBOM แบบ raw
docker buildx imagetools inspect myregistry/myapp:v1.0 \
  --format '{{ json .SBOM.SPDX }}'

# ดูรายการ packages
docker buildx imagetools inspect myregistry/myapp:v1.0 \
  --format '{{ range .SBOM.SPDX.packages }}{{ .name }}@{{ .versionInfo }}{{ println }}{{ end }}'

# สำหรับ multi-platform images
docker buildx imagetools inspect myregistry/myapp:v1.0 \
  --format '{{ json (index .SBOM "linux/amd64").SPDX }}'

9.2 ตรวจสอบ Provenance

Inspect Provenance
# ดู provenance แบบ raw
docker buildx imagetools inspect myregistry/myapp:v1.0 \
  --format '{{ json .Provenance }}'

# ดู source repository
docker buildx imagetools inspect myregistry/myapp:v1.0 \
  --format '{{ .Provenance.SLSA.source }}'

# ดู build timestamp
docker buildx imagetools inspect myregistry/myapp:v1.0 \
  --format '{{ .Provenance.SLSA.metadata.buildStartedOn }}'

9.3 ใช้ Docker Scout

Docker Scout Commands
# Quick view ของ image
docker scout quickview myregistry/myapp:v1.0

# ดู SBOM
docker scout sbom myregistry/myapp:v1.0

# สแกน vulnerabilities
docker scout cves myregistry/myapp:v1.0

# เปรียบเทียบ images
docker scout compare --to myregistry/myapp:v1.0 myregistry/myapp:v2.0

10. CI/CD Integration (GitHub Actions)

ตัวอย่าง GitHub Actions workflow สำหรับ build Docker image พร้อม SBOM และ Provenance Attestations:

.github/workflows/docker-build.yml
name: Build and Push Docker Image

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
      id-token: write  # จำเป็นสำหรับ OIDC token

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log into registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker image
        id: build-and-push
        uses: docker/build-push-action@v5
        with:
          context: .
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
          sbom: true
          provenance: true
          cache-from: type=gha
          cache-to: type=gha,mode=max

      - name: Scan for vulnerabilities
        uses: docker/scout-action@v1
        with:
          command: cves
          image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
          sarif-file: scout-report.sarif
          write-comment: true
          github-token: ${{ secrets.GITHUB_TOKEN }}

GitLab CI/CD Example

.gitlab-ci.yml
docker-build:
  image: docker:cli
  stage: build
  services:
    - docker:dind
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - docker buildx create --use
    - |
      docker buildx build \
        --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA \
        --tag $CI_REGISTRY_IMAGE:latest \
        --sbom=true \
        --provenance=mode=max \
        --push \
        .
  only:
    - main

11. Signing ด้วย Cosign

Cosign เป็นเครื่องมือจาก Sigstore สำหรับ sign และ verify container images และ attestations

11.1 Sign Docker Image

Cosign Sign
# Sign ด้วย key pair (สร้าง key ก่อน)
cosign generate-key-pair
cosign sign --key cosign.key myregistry/myapp:v1.0

# Sign ด้วย Sigstore (keyless - แนะนำ)
cosign sign myregistry/myapp:v1.0

# Sign พร้อม annotations
cosign sign \
  --annotations "commit=$COMMIT_SHA" \
  --annotations "repo=github.com/org/repo" \
  myregistry/myapp:v1.0

11.2 Verify Signature

Cosign Verify
# Verify signature
cosign verify myregistry/myapp:v1.0

# Verify ด้วย public key
cosign verify --key cosign.pub myregistry/myapp:v1.0

# Verify ด้วย certificate identity
cosign verify \
  --certificate-identity=user@example.com \
  --certificate-oidc-issuer=https://accounts.google.com \
  myregistry/myapp:v1.0

11.3 Verify Attestations

Verify SBOM & Provenance
# Verify SBOM attestation
cosign verify-attestation \
  --type spdx \
  myregistry/myapp:v1.0

# Verify Provenance attestation
cosign verify-attestation \
  --type slsaprovenance \
  myregistry/myapp:v1.0

# Verify และแสดงเนื้อหา
cosign verify-attestation \
  --type spdx \
  myregistry/myapp:v1.0 | jq '.payload | @base64d | fromjson'

# Verify policy ด้วย Kyverno/Cue
cosign verify-attestation \
  --type slsaprovenance \
  --policy policy.cue \
  myregistry/myapp:v1.0

12. แก้ไขปัญหาที่พบบ่อย

1

Attestations หายหลังจาก build

สาเหตุ: Default image store ไม่รองรับ attestations

แก้ไข:

ใช้ --push flag หรือเปิด containerd image store
# Enable containerd image store
docker info | grep "Storage Driver"
# แก้ไข /etc/docker/daemon.json
{
  "storage-driver": "overlay2",
  "features": {
    "containerd-snapshotter": true
  }
}
2

BuildKit version ไม่รองรับ

สาเหตุ: ต้องการ BuildKit 0.10+ สำหรับ attestations

แก้ไข:

อัปเกรด Docker หรือ Buildx
# ตรวจสอบ version
docker buildx version

# อัปเกรด buildx
docker buildx create --name upgraded --driver docker-container --use
docker buildx inspect --bootstrap
3

Registry ไม่รองรับ attestations

สาเหตุ: Registry บางตัวไม่รองรับ OCI artifacts

Registries ที่รองรับ:

  • • Docker Hub (Pro/Team/Business)
  • • GitHub Container Registry (ghcr.io)
  • • Google Artifact Registry
  • • AWS ECR
  • • Azure Container Registry
  • • Quay.io
4

Cosign verify ล้มเหลว

สาเหตุ: OIDC token หรือ certificate issue

แก้ไข:

ใช้ --allow-insecure-registry สำหรับ testing
หรือ verify ด้วย public key แทน keyless

cosign verify --key cosign.pub myregistry/myapp:v1.0

สรุป

สิ่งที่ได้เรียนรู้

  • ความสำคัญของ Supply Chain Security
  • SBOM และ Provenance คืออะไร
  • SLSA Framework และระดับต่างๆ
  • การสร้าง Attestations ด้วย Docker
  • การตรวจสอบและ Verify
  • CI/CD Integration
  • Signing ด้วย Cosign

ขั้นตอนถัดไป

  • เพิ่ม attestations ใน CI/CD pipeline
  • ตั้งค่า policy verification
  • ใช้ Docker Scout สำหรับ scanning
  • บรรลุ SLSA Level 3

บทความที่เกี่ยวข้อง