We are going to design a build pipeline that is hardened against supply-chain attacks. We'll incorporate:
Attestation: To ensure the integrity of the build process and artifacts.
Dependency Pinning: To ensure that dependencies are at known, vetted versions.
SBOM (Software Bill of Materials): To list all components (direct and transitive) for vulnerability management and compliance.
We'll design a pipeline that can be implemented in a CI/CD system (like GitHub Actions, GitLab CI, Jenkins, etc.). We'll break down the stages and the tools/techniques for each.
Pipeline Stages:
Source Code Checkout:
Checkout code from version control (e.g., Git).
Ensure the commit is signed (if using GPG signing) and/or comes from a trusted branch/tag.
Dependency Pinning and Verification:
Use a package manager that supports lock files (e.g., package-lock.json for npm, Pipfile.lock for pipenv, Cargo.lock for Rust, go.sum for Go, etc.).
Ensure the lock file is up-to-date and checked into version control.
During the build, use the lock file to fetch exact versions.
Static Analysis and Vulnerability Scanning:
Scan dependencies for known vulnerabilities (using tools like npm audit, snyk, osv-scanner, trivy, etc.).
Fail the build if critical vulnerabilities are found.
SBOM Generation:
Generate an SBOM in a standard format (e.g., SPDX, CycloneDX) that lists all dependencies (including transitive).
The SBOM should be signed and stored as an artifact.
Build and Test:
Build the application (e.g., compile code, create Docker image).
Run unit tests, integration tests, etc.
Post-Build Attestation:
After building, create an attestation for the build artifact (e.g., Docker image, binary) that includes:
The source code commit hash.
The build environment (CI/CD job, runner, etc.).
The SBOM.
The build steps (from a reproducible build if possible).
Use a signing key to sign the attestation (e.g., using Sigstore's cosign or a private key).
Store the attestation and the signed artifact.
Artifact Storage and Publishing:
Store the built artifact (e.g., in a container registry) along with the attestation and SBOM.
Ensure the artifact is stored in a way that the attestation can be verified (e.g., in an OCI registry with cosign or using in-toto).
Deployment with Attestation Verification:
Before deploying, verify the attestation of the artifact to ensure it was built from the expected source and with the expected dependencies.
This step can be part of the deployment process (e.g., in Kubernetes using admission controllers, or in a CI/CD deployment job).
Tools and Technologies:
Dependency Pinning: Use the native package manager's lock file.
Vulnerability Scanning: Use tools that are integrated with the package manager or general scanners (e.g., Trivy, Grype, Snyk).
SBOM Generation: Use tools that are appropriate for the language and build system. Syft is a good choice for multi-language.
Attestation and Signing: Use Sigstore (cosign, rekor, fulcio) for a free and open solution, or use a private PKI.
Reproducible Builds: If possible, use build systems that support reproducible builds (e.g., go build with -buildid, cargo with --locked, etc.) so that the same source and dependencies produce the same binary.
Implementation Example (using GitHub Actions and a Node.js project):
Source Code Checkout:
yaml
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# Ensure the commit is signed? This is more about the git commit.
# We can also check the branch/tag.
Dependency Pinning:
We assume package-lock.json is present and committed.
Use npm ci (instead of npm install) to install exactly what's in the lock file.
Vulnerability Scan:
yaml
steps:
- name: Run npm audit
run: npm audit --audit-level=critical
Generate SBOM:
Install syft and generate an SBOM.
yaml
steps:
- name: Install Syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Generate SBOM
run: syft . -o cyclonedx > sbom.cdx.json
- name: Sign SBOM (optional, but we can sign the SBOM and the artifact separately)
run: cosign sign-blob --key ${{ secrets.COSIGN_PRIVATE_KEY }} sbom.cdx.json
Build and Test:
yaml
steps:
- name: Build
run: npm run build
- name: Test
run: npm test
Post-Build Attestation:
Build a Docker image (or other artifact) and then create an attestation.
We'll use cosign to sign the image and also generate an attestation (using cosign attest).
We can also use cosign to attach the SBOM to the image (as an OCI annotation) or as a separate attestation.
Example with Docker and cosign:
Additional Considerations:
Reproducible Builds: If we can ensure that the build is reproducible, we can have an additional layer of trust. For example, in Go, we can use go build -trimpath -ldflags="-s -w" and set GIT_COMMIT and GIT_TREEISH to ensure the same source produces the same binary.
Identity and Access Management: Ensure that the CI/CD system has minimal permissions and that signing keys are stored securely (e.g., in a vault or GitHub Secrets with proper access controls).
Transparency Logs: Using Rekor (or another transparency log) for attestations so that even if the registry is compromised, we have a log of what was signed.
Infrastructure Attestation: Also consider attesting the build environment (e.g., the runner image, the CI/CD job definition) to ensure the build happened in a trusted environment. This can be done with tools like slsa-github-generator for GitHub Actions.
Dependency Pinning for System Dependencies: Not just language dependencies, but also system packages (if using a Dockerfile). Use specific versions and hashes for apt/yum packages.
Continuous Monitoring: The SBOM can be used for continuous monitoring of vulnerabilities. We can re-scan the SBOM periodically (or on new vulnerability disclosures) and trigger rebuilds if necessary.
This design provides multiple layers of security:
We use exact dependencies (pinning) to prevent unexpected updates.
We scan for vulnerabilities.
We generate an SBOM to know exactly what is in the build.
We attest the build, so we can verify later that the artifact was built from the expected source and dependencies.
By integrating these steps into the CI/CD pipeline, we can significantly reduce the risk of supply-chain attacks.
Here's a comprehensive build pipeline hardened against supply-chain attacks using attestation, dependency pinning, and SBOMs:
Zero Trust Artifacts: Never trust an artifact without cryptographic verification.
Least Privilege: CI/CD runners use short-lived credentials (OIDC tokens).
Immutable History: SBOMs and attestations are immutable; store in tamper-evident logs (Rekor).
Defense in Depth:
Pinning prevents unexpected updates.
SBOMs enable impact analysis.
Attestations prove provenance.
Automation: All steps automated; manual overrides require multi-party approval.
5. Toolchain Recommendations
Category
Open Source Options
Enterprise Options
Signing/Attesting
Sigstore (cosign, rekor, fulcio)
Google TUF, Notary v2
SBOM Generation
Syft, Trivy, SPDX tools
FOSSA, Sonatype lifecycle
Scanning
Grype, OSV scanner, Trivy
Snyk, Anchore Enterprise
Policy Enforcement
OPA Gatekeeper, Kyverno, policy-controller
Twistlock, Aqua Security
CI/CD
GitHub Actions, GitLab CI, Jenkins
Tekton, Spinnaker
6. Compliance Mapping
NIST SSDF: Enforces all practices (SA-11, SA-12).
SLSA: Achieve SLSA 3+ via provenance attestation.
ISO 27001: Controls for vendor management (supply chain).
Executive Order 14028: Meets requirements for SBOMs and attestations.
7. Monitoring & Response
Rekor Monitor: Watch for malicious attestations.
SBOM Diffing: Compare SBOMs across builds to detect rogue dependencies.
Vulnerability Alerts: Feed SBOM into vulnerability feed (e.g., OSV) for automated CVE matching.
Audit Trail: All attestations and signatures stored in transparency logs for forensics.
This pipeline ensures verifiable integrity from source to deployment, making supply-chain attacks significantly harder. Adjust tools based on your stack (e.g., replace npm with pip, maven, etc.).
yaml
steps:
- name: Build Docker image
run: |
docker build -t my-image:${{ github.sha }} .
- name: Sign image with cosign
run: |
cosign sign --key ${{ secrets.COSIGN_PRIVATE_KEY }} my-image:${{ github.sha }}
- name: Attest image with SBOM
run: |
# Generate an in-toto attestation that includes the SBOM and other predicates.
# We can use cosign attest with a custom predicate or use the built-in one for SLSA.
# For simplicity, let's use the SBOM as a predicate.
cosign attest --key ${{ secrets.COSIGN_PRIVATE_KEY }} --predicate sbom.cdx.json --type spdx my-image:${{ github.sha }}
Alternatively, we can attach the SBOM as an OCI annotation to the image.
Artifact Storage:
The Docker image is stored in a registry (e.g., GitHub Container Registry). The attestation is stored in the registry (if using cosign) and also in Rekor (a transparency log).
Deployment:
In the deployment step, verify the attestation and signature.