How do you implement container image signing, verification, and SBOM (Software Bill of Materials) in a production CI/CD pipeline? Describe the trust chain from build to deployment.
Quick Answer
Use cosign (Sigstore) to sign images with keyless signing (OIDC identity from CI provider), store signatures in the OCI registry alongside the image, generate SBOMs with Syft/Trivy, and enforce signature verification at deployment using Kyverno or OPA Gatekeeper admission controllers in Kubernetes.
Detailed Answer
Supply Chain Security Architecture
The goal is to ensure that only images built by your CI/CD system from your source code, passing all checks, are deployed to production. This requires: provenance (who built it), integrity (not tampered), and transparency (what's inside).
Image Signing with Cosign (Sigstore)
Cosign provides keyless signing using short-lived certificates from Fulcio CA, tied to OIDC identities. In GitHub Actions, the workflow's OIDC token proves identity. The signature includes: who built it (CI workflow), what commit, what repo. Signatures are stored as OCI artifacts in the same registry as the image.
SBOM Generation
SBOM documents every package/library in the image. Formats: SPDX (ISO standard) or CycloneDX. Generate with Syft or Trivy during build. Attach to the image as an OCI artifact with cosign.
Verification at Deploy Time
Deploy a Kubernetes admission controller (Kyverno or Gatekeeper) that intercepts pod creation, extracts the image reference, verifies the cosign signature against the expected identity (e.g., must be signed by your GitHub Actions workflow from your repo), and rejects unsigned or tampered images.
SLSA Framework Integration
SLSA (Supply-chain Levels for Software Artifacts) defines maturity levels. Level 3 requires: source provenance, build provenance, isolated build environment. Use GitHub's artifact attestations or SLSA GitHub generator for automated provenance generation.
Vulnerability Scanning Integration
Scan the SBOM against vulnerability databases (Grype, Trivy). Gate deployments on vulnerability severity (block critical/high CVEs). Store scan results as attestations alongside the image.
Code Example
# CI/CD Pipeline: Build, Sign, SBOM, Scan
# GitHub Actions workflow
name: Build and Sign
on: push
permissions:
contents: read
packages: write
id-token: write # Required for keyless signing
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build image
run: |
docker build -t ghcr.io/myorg/myapp:${{ github.sha }} .
docker push ghcr.io/myorg/myapp:${{ github.sha }}
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Sign image (keyless)
run: |
cosign sign --yes \
ghcr.io/myorg/myapp@$(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/myorg/myapp:${{ github.sha }} | cut -d@ -f2)
- name: Generate SBOM
run: |
syft ghcr.io/myorg/myapp:${{ github.sha }} -o spdx-json > sbom.spdx.json
- name: Attach SBOM to image
run: |
cosign attach sbom --sbom sbom.spdx.json \
ghcr.io/myorg/myapp:${{ github.sha }}
- name: Scan for vulnerabilities
run: |
grype sbom:sbom.spdx.json --fail-on critical
# Kyverno policy to enforce image signatures
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: verify-image-signature
spec:
validationFailureAction: Enforce
webhookTimeoutSeconds: 30
rules:
- name: verify-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
# Verify signature manually
cosign verify \
--certificate-identity-regexp 'https://github.com/myorg/.*' \
--certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
ghcr.io/myorg/myapp:latestInterview Tip
Supply chain security is a top priority post-SolarWinds/Log4j. Know the Sigstore ecosystem: cosign (signing), Fulcio (CA), Rekor (transparency log). The key concept is keyless signing - no long-lived keys to manage, identity comes from OIDC. Mention SLSA levels to show you understand the maturity framework. Always connect signing to enforcement (admission controllers).