🔒 Security

SBOM

Software Bill of Materials

A detailed inventory of all components, libraries, and dependencies that make up software. Like a manufacturing BOM (Bill of Materials), it provides a software "ingredient list," enabling supply chain security, license compliance, and vulnerability management. CycloneDX and SPDX are the representative standard formats.

📖 Detailed Explanation

An SBOM (Software Bill of Materials) is a list of all the components included in a software product. Just as a BOM (Bill of Materials) in manufacturing specifies every part that goes into a car or an electronic product, it provides an "ingredients list" for software. This includes open-source libraries, commercial components, in-house developed modules, and their dependencies. The name, version, license, and supplier information of each component are recorded.

The importance of SBOMs rose sharply after large-scale supply chain attacks such as SolarWinds and Log4Shell (Log4j). In 2021, the U.S. White House, through an executive order (EO 14028), made it mandatory for all companies supplying software to the federal government to provide an SBOM. When a vulnerability is discovered, you must be able to immediately answer the question "Does our system have this component?", and without an SBOM, thousands of applications would have to be inspected manually.

CycloneDX and SPDX are representative SBOM standard formats. CycloneDX is a lightweight standard developed by OWASP and is optimized for security use cases. SPDX (Software Package Data Exchange) is maintained by the Linux Foundation, is strong in license compliance, and has been adopted as an ISO standard (ISO/IEC 5962:2021). Both formats can be expressed in JSON, XML, and more, and can be converted between tools.

In modern DevSecOps, SBOM generation is automated in the build pipeline. SBOMs are generated at build time with tools such as Syft, Trivy, and OWASP Dependency-Track, and risk is assessed by cross-checking them against vulnerability databases (NVD, OSV). VEX (Vulnerability Exploitability eXchange) is used together with an SBOM to document "Is this vulnerability actually exploitable in our environment?". SBOMs are becoming essential material for regulatory compliance, customer requirements, and security due diligence.

💻 Code Example

# Syft - Anchore의 SBOM 생성 도구
# 컨테이너 이미지, 파일시스템, 아카이브에서 SBOM 생성

# 1. 설치
# macOS
brew install syft
# Linux
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin

# 2. Docker 이미지에서 SBOM 생성
syft nginx:latest
# 기본 출력: 테이블 형식

# CycloneDX JSON 형식으로 저장
syft nginx:latest -o cyclonedx-json > sbom.json

# SPDX 형식으로 저장
syft nginx:latest -o spdx-json > sbom.spdx.json

# 3. 로컬 디렉토리에서 SBOM 생성
syft dir:/path/to/project -o cyclonedx-json > project-sbom.json

# 4. 컨테이너 tar 파일에서 SBOM 생성
docker save myapp:v1.0 -o myapp.tar
syft myapp.tar -o cyclonedx-json > myapp-sbom.json

# 5. 다양한 출력 형식
syft alpine:latest -o table          # 터미널 테이블 (기본)
syft alpine:latest -o json           # Syft JSON
syft alpine:latest -o cyclonedx-json # CycloneDX JSON
syft alpine:latest -o cyclonedx-xml  # CycloneDX XML
syft alpine:latest -o spdx-json      # SPDX JSON
syft alpine:latest -o spdx-tag-value # SPDX Tag-Value

# 6. 특정 패키지 카탈로거만 사용
syft packages alpine:latest --catalogers apk,python

# 7. 프라이빗 레지스트리 인증
syft registry.example.com/myapp:latest \
    --registry-auth "username:password"

# 8. SBOM 분석 (Grype로 취약점 스캔)
# Syft로 생성한 SBOM을 Grype로 분석
syft nginx:latest -o json > nginx-sbom.json
grype sbom:nginx-sbom.json

# 9. OCI 레지스트리에 SBOM 저장 (Attestation)
syft nginx:latest -o cyclonedx-json | \
    cosign attest --predicate - \
    --type cyclonedx nginx:latest

# 10. 멀티 플랫폼 이미지 지원
syft --platform linux/amd64 nginx:latest
// CycloneDX SBOM 예제 (JSON 형식)
// https://cyclonedx.org/specification/overview/

{
  "bomFormat": "CycloneDX",
  "specVersion": "1.5",
  "serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79",
  "version": 1,
  "metadata": {
    "timestamp": "2024-01-15T10:30:00Z",
    "tools": [
      {
        "vendor": "anchore",
        "name": "syft",
        "version": "0.100.0"
      }
    ],
    "component": {
      "type": "application",
      "name": "my-web-app",
      "version": "2.1.0",
      "bom-ref": "my-web-app@2.1.0"
    }
  },
  "components": [
    {
      "type": "library",
      "name": "express",
      "version": "4.18.2",
      "purl": "pkg:npm/express@4.18.2",
      "bom-ref": "express@4.18.2",
      "licenses": [
        {
          "license": {
            "id": "MIT"
          }
        }
      ],
      "externalReferences": [
        {
          "type": "website",
          "url": "https://expressjs.com/"
        },
        {
          "type": "vcs",
          "url": "https://github.com/expressjs/express"
        }
      ],
      "properties": [
        {
          "name": "cdx:npm:package:development",
          "value": "false"
        }
      ]
    },
    {
      "type": "library",
      "name": "lodash",
      "version": "4.17.21",
      "purl": "pkg:npm/lodash@4.17.21",
      "bom-ref": "lodash@4.17.21",
      "licenses": [
        {
          "license": {
            "id": "MIT"
          }
        }
      ]
    },
    {
      "type": "library",
      "name": "axios",
      "version": "1.6.0",
      "purl": "pkg:npm/axios@1.6.0",
      "bom-ref": "axios@1.6.0",
      "licenses": [
        {
          "license": {
            "id": "MIT"
          }
        }
      ]
    }
  ],
  "dependencies": [
    {
      "ref": "my-web-app@2.1.0",
      "dependsOn": [
        "express@4.18.2",
        "lodash@4.17.21",
        "axios@1.6.0"
      ]
    },
    {
      "ref": "express@4.18.2",
      "dependsOn": [
        "body-parser@1.20.2",
        "cookie@0.5.0"
      ]
    }
  ],
  "vulnerabilities": [
    {
      "id": "CVE-2023-12345",
      "source": {
        "name": "NVD",
        "url": "https://nvd.nist.gov/"
      },
      "ratings": [
        {
          "source": { "name": "NVD" },
          "score": 7.5,
          "severity": "high",
          "method": "CVSSv31"
        }
      ],
      "affects": [
        {
          "ref": "axios@1.6.0"
        }
      ],
      "analysis": {
        "state": "not_affected",
        "justification": "code_not_reachable",
        "detail": "해당 취약점은 프록시 기능에서 발생하며, 우리 애플리케이션에서는 프록시를 사용하지 않음"
      }
    }
  ]
}
# GitHub Actions - SBOM 생성 및 취약점 스캔 파이프라인

name: SBOM Generation and Security Scan

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

jobs:
  sbom-and-scan:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      security-events: write

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

      - name: Build Docker image
        run: docker build -t myapp:${{ github.sha }} .

      # 1. Syft로 SBOM 생성
      - name: Generate SBOM with Syft
        uses: anchore/sbom-action@v0
        with:
          image: myapp:${{ github.sha }}
          format: cyclonedx-json
          output-file: sbom.json
          artifact-name: sbom.cyclonedx.json

      # 2. Grype로 취약점 스캔
      - name: Scan SBOM for vulnerabilities
        uses: anchore/scan-action@v3
        id: scan
        with:
          sbom: sbom.json
          fail-build: true
          severity-cutoff: high

      # 3. 취약점 보고서 업로드
      - name: Upload vulnerability report
        uses: github/codeql-action/upload-sarif@v3
        if: always()
        with:
          sarif_file: ${{ steps.scan.outputs.sarif }}

      # 4. SBOM을 릴리스 아티팩트로 저장
      - name: Upload SBOM as artifact
        uses: actions/upload-artifact@v4
        with:
          name: sbom
          path: sbom.json

---
# GitLab CI - SBOM 파이프라인

stages:
  - build
  - sbom
  - scan

variables:
  IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

build:
  stage: build
  script:
    - docker build -t $IMAGE_NAME .
    - docker push $IMAGE_NAME

generate-sbom:
  stage: sbom
  image: anchore/syft:latest
  script:
    - syft $IMAGE_NAME -o cyclonedx-json > sbom.json
    - syft $IMAGE_NAME -o spdx-json > sbom.spdx.json
  artifacts:
    paths:
      - sbom.json
      - sbom.spdx.json
    expire_in: 1 week

vulnerability-scan:
  stage: scan
  image: anchore/grype:latest
  needs: [generate-sbom]
  script:
    - grype sbom:sbom.json --fail-on high
  allow_failure: false

---
# Dependency-Track 연동 (SBOM 중앙 관리)

# SBOM을 Dependency-Track에 업로드
upload-to-dependency-track:
  stage: sbom
  script:
    - |
      curl -X POST "https://dtrack.example.com/api/v1/bom" \
        -H "X-Api-Key: $DEPENDENCY_TRACK_API_KEY" \
        -H "Content-Type: multipart/form-data" \
        -F "projectName=my-app" \
        -F "projectVersion=$CI_COMMIT_SHA" \
        -F "autoCreate=true" \
        -F "bom=@sbom.json"

🗣️ Say It Like This in Practice

💬 In Responding to Supply Chain Security Issues
"Two hours after the Log4j vulnerability was disclosed, we had identified the impact scope across all our systems. Because the SBOMs of all services were registered in Dependency-Track, we immediately identified 15 services using the vulnerable version. If we had checked manually without SBOMs, it would have taken several days."
💬 In Responding to Customer Security Due Diligence
"We can provide you with our product's SBOM in CycloneDX format. It includes all open-source components, versions, and license information, and we will also send our analysis of currently known vulnerabilities as a VEX document. We also have a process for providing an updated SBOM every quarter."
💬 In Designing a DevSecOps Pipeline
"At the build stage, we automatically generate the SBOM with Syft and run a vulnerability scan with Grype. If there is a vulnerability with a CVSS score of 7 or higher, we fail the build, and we upload the generated SBOM to Dependency-Track to track the dependencies of all services centrally. When a new CVE is disclosed, you can automatically get notified of the list of affected services."

⚠️ Cautions & Best Practices

❌
Generating an SBOM once and then neglecting it

An SBOM must be newly generated with every build. Dependencies keep changing, and an SBOM from a month ago is already outdated. Integrate it into the CI/CD pipeline to automatically generate and manage an SBOM for every release.

❌
Including only direct dependencies

You must not include only the direct dependencies specified in package.json or pom.xml in the SBOM. Transitive dependencies must also be included. Most Log4j vulnerabilities also came in through transitive dependencies. Scan the entire dependency tree with tools such as Syft and Trivy.

❌
SBOM format incompatibility

CycloneDX and SPDX are different standards, but they can be converted between each other. Customers or regulators may require a specific format, so choose a tool that can export to multiple formats. SBOMs in a proprietary format should be avoided because they lack tool compatibility.

✅
SBOM Best Practices

Automatically generate an SBOM in every build and manage it in a central repository (such as Dependency-Track). Generate a VEX together with the SBOM to document the actual impact of vulnerabilities. Generate SBOMs for container images, binaries, and source code alike, and automate license compliance checks and vulnerability monitoring. Establish a process for providing an SBOM together with the software when delivering it.

🔗 Related Terms

📚 Learn More