How do you generate and store SBOMs in a CI/CD pipeline?

IntermediateHands-onSBOM
Answer

Short answer

After building the image, generate the SBOM (Syft or Trivy), scan it, then store it with the release — as a CI artifact, attached to the GitHub release, uploaded to a platform like Dependency-Track, and/or attested to the image in the registry with cosign.

GitHub Actions example

- name: Build
  run: docker build -t $IMAGE:$TAG .
- name: Generate SBOM
  uses: anchore/sbom-action@v0
  with:
    image: ${{ env.IMAGE }}:${{ env.TAG }}
    format: cyclonedx-json
    output-file: sbom.cdx.json
- name: Scan SBOM
  run: grype sbom:./sbom.cdx.json --fail-on critical
- name: Push image
  run: docker push $IMAGE:$TAG
- name: Attest SBOM to image
  run: cosign attest --yes --predicate sbom.cdx.json --type cyclonedx $IMAGE@${{ steps.push.outputs.digest }}
- name: Upload to Dependency-Track
  run: |
    curl -X POST https://dtrack.company.com/api/v1/bom \
      -H "X-Api-Key: ${{ secrets.DT_API_KEY }}" \
      -F "autoCreate=true" -F "projectName=shop-api" -F "projectVersion=$TAG" -F "[email protected]"

Where SBOMs live

Place Benefit
CI artifacts / release assets Simple record per version
Registry attestation (OCI) Travels with the image, verifiable signature
Dependency-Track Central inventory, continuous CVE monitoring, policy alerts

What to say in the interview

"Generate the SBOM from the built image, scan it, then store it as a release artifact, attest it to the image digest with cosign, and push it to Dependency-Track for continuous monitoring across all services."

All Security Tools questions Roadmap: SBOM — software bill of materials

More on SBOM