The user wants a design for a secure build pipeline.
The specific goal is to harden the pipeline against supply-chain attacks.
The key technologies/methodologies requested are:
Attestation (provenance, integrity).
Dependency pinning (locking versions).
SBOMs (Software Bill of Materials).
I need to structure the answer logically, moving from source to artifact.
A standard CI/CD pipeline flow is: Code -> Build -> Test -> Package -> Deploy.
I need to insert security controls at each stage.
Deconstruction of the Request:
Supply Chain Attacks: These happen when an attacker compromises a dependency, the build system, the source code, or the deployment process (SolarWinds, Codecov, event-stream, etc.).
Hardening: Reducing the attack surface.
Attestation: Cryptographically proving who built it, where, when, and how. SLSA (Supply-chain Levels for Software Artifacts) is the standard framework here.
Dependency Pinning: Ensuring reproducible builds by locking exact versions (hashes) of dependencies.
SBOM: Knowing exactly what is inside the artifact.
Drafting the Pipeline Stages:
Source Control (The "What"):
Need strict access control (MFA, branch protection).
Signed commits (proving authorship).
Dependency Management (The "Ingredients"):
Pinning: Use lockfiles (package-lock.json, Pipfile.lock) and verify hashes.
Vetting: Analyze dependencies for vulnerabilities (SCA).
Proxy: Use a private registry/mirror to prevent "left-pad" style disappearances or injection via DNS poisoning.
Phase 4: Attestation & SBOM Generation: The core request. Signing the build.
Phase 5: Verification & Deployment Policy: "Trust on first use" vs "Verify on every use".
Summary/Checklist.
Refining the "Hardening" Aspect:
Pinning isn't enough. It prevents "sliding" attacks (where latest changes), but not "substitution" attacks (where the registry serves bad code for a specific version). So, Content Addressing (hashes) is vital.
Attestation: Needs to be non-falsifiable. The build worker must hold the key (or a token), not the user submitting the PR.
SBOM: Needs to be generated inside the build, not after.
Self-Correction/Review during drafting:
Initial thought: Just say "use Dependabot."
Correction: Dependabot updates dependencies. While good for patching, the pipeline needs to ensure the build uses exactly what's in the lockfile. I should emphasize strict lockfile usage and hash verification.
Initial thought: Just generate an SBOM.
Correction: An SBOM is useless without integrity. I must link SBOM generation to the Attestation step (Signing). The SBOM must be signed.
Final Polish: Use standard terminology (SLSA, in-toto). Make the instructions actionable (e.g., "Use Cosign").
Let's organize the design into a logical flow.
Threat Model: Briefly define what we are stopping (dependency confusion, compromise of build worker, injection).
Core Principles: SLSA framework.
Detailed Stages:
Source (Identity).
Dependencies (Pinning + Isolation).
Build (Hermetic + Attestation).
Post-Build (SBOM + Signing).
Deployment (Policy enforcement).
This looks solid. I will write the response following this structure.
A build pipeline hardened against supply-chain attacks moves beyond simple "scan and patch" methodologies. It implements a Zero Trust approach where no code, dependency, or build step is trusted by default.
This design adheres to the SLSA (Supply-chain Levels for Software Artifacts) framework, specifically targeting Level 3 (Hardened Builds) and Level 4 (Two-Party Review).
Below is the architecture for a pipeline that enforces Dependency Pinning, generates SBOMs, and cryptographically signs Attestations.
1. Architecture Overview
The pipeline is divided into three distinct environments:
Control Plane: Where code lives (e.g., GitHub/GitLab).
Isolated Build Environment: A ephemeral, network-restricted environment (e.g., hardened Kubernetes pod, AWS CodeBuild, or GitHub Actions with hosted runners).
Policy Engine: A gatekeeper that verifies cryptographic proofs before any artifact is deployed or promoted.
2. Phase I: Source Integrity & Dependency Pinning
Goal: Ensure the code entering the pipeline is exactly what the developer intended and malicious updates cannot slip in.
A. Strict Dependency Pinning (The "Lockfile")
Using floating versions (e.g., npm install lodash or python requests > 2.0) allows an attacker to hijack a dependency registry and serve a malicious version that satisfies the version constraint.
Strategy:
Enforce the use of Lockfiles (package-lock.json, yarn.lock, poetry.lock, go.sum).
Content Addressing: Pin dependencies by cryptographic hash (SHA256), not just version number.
CI Fail: Configure the build to fail if the lockfile does not match the manifest or if npm ci (or equivalent) detects discrepancies.
B. Dependency Verification (Sigstore/Cosign)
Verify that the dependencies themselves are signed by their authors.
Implementation:
Use tools like cosign or syft to verify signatures of base images (e.g., verify python:3.9-slim is signed by the Python release team).
For application libraries, enable registry verification (e.g., npm provenance) where available.
3. Phase II: The Hermetic Build Environment
Goal: Prevent "Time-of-Check to Time-of-Use" (TOCTOU) attacks and ensure reproducibility.
A. Ephemeral & Isolated
Fresh Instance: Every build runs on a fresh, ephemeral VM or container. No caching of state between builds.
Network Egress Blocking: The build environment allows network ingress (to fetch code) but blocks egress to the internet.
Exception: Allowlisting a private artifact registry (e.g., Artifactory, Sonatype Nexus) to fetch pinned dependencies. This prevents build servers from reaching out to C2 servers or public registries directly.
B. Provenance Generation (Attestation)
This is the core of the defense. We must prove how and where the artifact was built.
The Attestation: An in-toto attestation (standardized metadata statement) is generated during the build. It binds the artifact's hash to the build metadata.
Metadata Included:
Build system ID (e.g., GitHub Actions Run ID).
Source repository URI and commit SHA.
Build instructions (entry point).
The resolved dependency graph (inputs).
Signing: This attestation is signed by the build platform's dedicated key (or a Workload Identity Federation token).
Attest that "This SBOM describes Artifact sha256:abc...".
Push artifact and attestation to the registry simultaneously.
5. Phase IV: Policy Verification (The Gatekeeper)
Goal: Refuse to deploy anything that cannot prove its own integrity.
Before the artifact is allowed to progress to Staging or Production, it passes through a Policy Controller (e.g., Kyverno, OPA Gatekeeper, or Sigstore Policy Controller).
The Verification Logic:
Verify Signature: Does the artifact have a valid signature from the authorized Build Pipeline key?
Verify Provenance: Check the Attestation.
Was it built from the allowed repository? (e.g., github.com/my-org/*)
Was the build triggered by a specific branch? (e.g., main)
Was the build environment non-interactive? (Prevents manual SSH tampering).
Verify SBOM:
Is an SBOM present?
Scan the SBOM against a CVE database. If critical vulnerabilities exist, FAIL.
Summary Diagram: The Hardened Pipeline
mermaid
graph TD
subgraph "Source Control"
A[Developer Commit] -->|Signed Commit| B(Repo)
B -->|Webhook| C[Build Orchestrator]
end
subgraph "Isolated Build Environment"
C --> D[Spawn Ephemeral Runner]
D -->|1. Fetch Code| E[Source Checkout]
E -->|2. Verify Lockfile| F[Install Dependencies]
F -->|3. Compile & Test| G[Build Artifact]
G -->|4. Generate Metadata| H[Generate SBOM]
H -->|5. Create Receipt| I[Generate Attestation]
end
subgraph "Signing & Verification"
I -->|Sign with Fulcio/KMS| J[Signed Artifact + Attestation + SBOM]
J --> K[Policy Controller]
K -->|Verify Signature & Policy| L{Pass?}
end
subgraph "Deployment"
L -- Yes --> M[Registry / Prod]
L -- No --> N[Quarantine / Alert]
end
Implementation Checklist
To implement this today, use the Sigstore toolchain, which is the industry standard for this architecture: