Build Provenance Fundamentals
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 10 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Build Provenance Fundamentals: Securing the Software Supply Chain
Introduction: Why Provenance Matters
In the modern landscape of software development, the integrity of the code we run is just as important as the code itself. Every application relies on a complex web of dependencies, build tools, and deployment pipelines. If any part of this chain is compromised, the final artifact—be it a container image, a binary, or a library—can become a vehicle for malicious code injection. Build provenance is the technical answer to the fundamental question: "How do I know where this artifact came from and how it was made?"
Build provenance is a verifiable record that describes the origin of a software artifact. It includes metadata such as the source code repository, the commit hash, the build environment, and the specific commands used to transform source code into a deployable package. Without this information, you are essentially trusting the artifact blindly. By establishing a chain of custody from the initial commit to the final production deployment, you can ensure that your software has not been tampered with during the build process. This lesson explores the fundamentals of build provenance, how to generate it, and why it is a non-negotiable component of modern security practices.
Not read yet
Defining Build Provenance
At its core, build provenance is a document—typically in a machine-readable format like JSON—that provides a snapshot of the build process. Think of it as a "birth certificate" for your software. It connects the final artifact to the exact conditions under which it was created. This link is vital because attackers often attempt to inject malicious code during the build phase, where developers might assume the environment is secure.
When we talk about provenance, we are usually referring to a standard known as SLSA (Supply-chain Levels for Software Artifacts). SLSA provides a framework for evaluating the security of the software supply chain. A key goal of SLSA is to move from "untrusted" builds to "authenticated" ones. Authenticated builds are those where the provenance is cryptographically signed, ensuring that the metadata has not been altered since it was generated by the build system.
Key Components of a Provenance Record
A standard provenance record typically contains the following fields:
- Builder Identity: Who or what performed the build? This could be a specific CI/CD pipeline, a build server, or a hardware security module.
- Build Source: The exact repository and commit hash that served as the input for the build.
- Build Parameters: The specific configuration options, environment variables, and build commands executed.
- Dependencies: A list of all external libraries or base images used during the build process to ensure reproducibility.
- Artifact Digest: The cryptographic hash (e.g., SHA-256) of the final output, ensuring that the provenance is tied to the specific binary or image.
Callout: Provenance vs. SBOM It is common to confuse a Software Bill of Materials (SBOM) with build provenance. An SBOM is a list of ingredients—it tells you what is inside the software. Build provenance is a record of the process—it tells you how the software was made. You need both to have a complete picture of your supply chain security.
Not read yet
The Mechanics of Generating Provenance
To generate meaningful provenance, you must integrate tools into your CI/CD pipeline that capture metadata as the build happens. Manual documentation is prone to human error and is easily bypassed by attackers. Therefore, the process must be automated and enforced by the build platform itself.
Tools like Sigstore, specifically the cosign and slsa-github-generator projects, have become the industry standard for this task. These tools allow you to sign your artifacts and attach the provenance metadata directly to them.
Step-by-Step: Generating Provenance in GitHub Actions
GitHub Actions provides a native way to generate provenance using the slsa-github-generator workflow. This process involves creating a reusable workflow that acts as a witness to the build process.
- Configure the Workflow: You define a workflow file in your repository that calls the SLSA generator.
- Execute the Build: The generator runs your build scripts in a controlled environment.
- Capture Metadata: The generator automatically captures the environment, inputs, and build commands.
- Sign the Attestation: The generator uses OIDC (OpenID Connect) to request a short-lived signing key from Sigstore.
- Attach to Artifact: The final provenance record is signed and uploaded to the container registry alongside the artifact.
Note: The use of OIDC is critical here. By using OIDC, you avoid the need to manage long-lived secrets or private keys in your CI/CD environment. The build system proves its identity to the signing service, which then issues a temporary certificate.
Not read yet
Practical Example: Signing an Artifact with Cosign
Cosign is a powerful tool for signing artifacts and attaching provenance records. Below is a practical example of how you might use it in a terminal or within a CI script.
Signing an Image
To sign a container image, you first need to have the image pushed to a registry. Once pushed, you can sign it using your identity (e.g., your GitHub account or a hardware key).
# Sign the container image using your OIDC identity
cosign sign --yes my-registry.com/my-app:v1.0.0
Attaching Provenance
Attaching a provenance record is slightly more complex as it requires a JSON file describing the build. If you are using an automated builder, this is often handled for you, but it is helpful to understand the underlying command:
# Attach a provenance file to the image
cosign attest --type slsa --predicate provenance.json my-registry.com/my-app:v1.0.0
In this command:
--type slsatellscosignthat this is a SLSA-compliant provenance record.--predicate provenance.jsonpoints to the file containing the build metadata.- The final argument is the reference to the image in the registry.
Not read yet
Best Practices for Implementing Provenance
Implementing provenance is not a "set it and forget it" task. To be effective, it requires adherence to specific security principles.
1. Use Ephemeral Build Environments
Never build your artifacts on a developer's local machine for production release. Local machines are inherently insecure and lack the audit trails required for provenance. Use hardened, ephemeral CI/CD runners that are destroyed after every build.
2. Verify Everything
Generating provenance is only half the battle. You must also verify it before deployment. If your deployment pipeline does not check the provenance record, you are essentially ignoring the security measures you put in place.
# Verify the provenance of an image before pulling it to a cluster
cosign verify-attestation --type slsa --certificate-identity-regexp ".*@github.com" my-registry.com/my-app:v1.0.0
3. Minimize Build Dependencies
The more dependencies your build process has, the larger your attack surface. Audit your build environment regularly and remove unnecessary tools, scripts, or libraries that could be used to facilitate an attack.
4. Enforce Policy as Code
Use tools like OPA (Open Policy Agent) or Kyverno to enforce policies in your Kubernetes cluster. For example, you can create a policy that rejects any container image that does not have a verified SLSA provenance record.
Warning: The "Trust-on-First-Use" Trap Be careful not to assume that just because a record exists, it is valid. Always verify the signature against a trusted root certificate (like the Sigstore transparency log). A provenance record without a valid signature is just as dangerous as no record at all because it provides a false sense of security.
Not read yet
Comparison: Manual vs. Automated Provenance
| Feature | Manual Provenance | Automated Provenance |
|---|---|---|
| Consistency | Low (prone to human error) | High (consistent across every build) |
| Scalability | Poor (impossible for large teams) | Excellent (integrated into CI/CD) |
| Integrity | Weak (easily forged) | Strong (cryptographically signed) |
| Visibility | Limited (often siloed) | High (accessible via registry/API) |
Common Pitfalls and How to Avoid Them
Pitfall 1: Relying on Static Secrets
Many teams store private keys in environment variables to sign their artifacts. This is a significant security risk. If the CI/CD platform is compromised, the attacker gains access to your signing key and can sign malicious artifacts as if they were legitimate.
- Solution: Use Keyless signing (Sigstore). Keyless signing uses short-lived certificates derived from OIDC identities, meaning there is no long-lived secret for an attacker to steal.
Pitfall 2: Ignoring the Build Environment
You might have a secure source code repository, but if the build server itself is misconfigured, the provenance will reflect a "secure" source while ignoring the fact that the build environment was compromised.
- Solution: Treat your build infrastructure as part of your production environment. Apply the same level of monitoring, logging, and access control to your CI runners as you would to your production servers.
Pitfall 3: Incomplete Provenance Records
A common mistake is generating a provenance record that only contains the build command but omits the dependencies or the environment variables. This makes the provenance useless for reproducing the build or auditing the security of the final artifact.
- Solution: Use standard formats like SLSA v1.0. These standards ensure that you are capturing all necessary fields. Avoid "home-grown" metadata formats that lack the necessary depth and industry support.
Not read yet
Advanced Concepts: Reproducible Builds
Reproducible builds are the ultimate goal of build provenance. A build is "reproducible" if, given the same source code and the same build environment, it produces the exact same binary (bit-for-bit) every single time.
If your build is reproducible, you can have two independent build systems build the same source code. If the resulting hashes match, you can be absolutely certain that the build process itself was not tampered with. Even if one build environment was compromised, the attacker would have to compromise both environments in the exact same way to produce the same malicious binary—an extremely difficult task.
Steps to Achieve Reproducibility:
- Pin Versions: Use exact versions for all build tools, compilers, and dependencies. Do not use "latest" tags.
- Strip Non-Determinism: Compilers often include timestamps or local paths in binaries. Use flags to disable these or normalize them (e.g.,
SOURCE_DATE_EPOCHin Linux). - Isolate the Environment: Ensure the build runs in a container with a fixed filesystem state.
Callout: Why Reproducibility is Hard Reproducible builds are difficult because modern software stacks are complex. Network calls during builds, non-deterministic compiler output, and hidden environment variables can all break reproducibility. Start small by focusing on pinning your compiler and dependency versions before attempting full binary reproducibility.
Not read yet
Integrating Provenance into the Software Development Lifecycle (SDLC)
Provenance should not be an afterthought added at the end of the project. It should be baked into the way you develop software.
Phase 1: Development
Developers should sign their commits using GPG or SSH keys. While this is not "build" provenance, it establishes the first link in the chain of trust: the identity of the person who wrote the code.
Phase 2: Build
As discussed, the CI/CD pipeline acts as the "witness." It must be configured to generate signed provenance records automatically. This is where the bulk of the "provenance" work occurs.
Phase 3: Distribution
When you push your artifacts to a registry, the provenance records should be pushed alongside them. Most modern registries (like OCI-compliant registries) support storing "artifacts" that are not images, which is perfect for storing provenance documents.
Phase 4: Deployment
The deployment engine (e.g., Kubernetes) must perform "Admission Control." This means it intercepts the request to run a container and checks the registry to see if a valid, signed provenance record exists for that specific image hash. If it doesn't, the deployment is blocked.
Not read yet
Common Questions (FAQ)
Q: Does provenance stop all supply chain attacks?
A: No. Provenance tells you how an artifact was made, but it does not tell you if the code itself is bug-free or if a dependency has a zero-day vulnerability. It is one layer of a "defense-in-depth" strategy, not a silver bullet.
Q: What if my build system doesn't support SLSA?
A: You can still generate provenance. While SLSA-native builders make it easier, you can use the cosign CLI to manually sign and attest artifacts in any CI/CD environment. It requires more setup, but it is achievable.
Q: How much overhead does this add to my build time?
A: Minimal. Generating a provenance record takes seconds, and signing it via Sigstore is very fast. The primary cost is the initial configuration and the effort required to maintain the security of your build environment.
Q: Can I use provenance for non-container artifacts?
A: Yes. Provenance is useful for any artifact, including zip files, tarballs, binaries, and even scripts. As long as you can calculate a hash of the file, you can sign it and attach provenance.
Not read yet
Best Practices Checklist for Teams
To ensure your team is successfully implementing build provenance, use this checklist as a guide:
- Standardize on a format: Use SLSA v1.0 or higher for all projects.
- Automate signing: Use OIDC-based signing (like Sigstore) to eliminate long-lived secrets.
- Audit your dependencies: Use automated tools to scan dependencies for known vulnerabilities before building.
- Enforce via policy: Use admission controllers in Kubernetes to block unsigned or unverified artifacts.
- Document the build: Ensure that the provenance metadata includes the exact build commands and environment variables.
- Regularly test verification: Perform "fire drills" where you attempt to deploy an intentionally invalid artifact to ensure your blocking policies are working.
Key Takeaways
- Provenance is a Birth Certificate: Build provenance provides a verifiable, cryptographically signed record of how a software artifact was created, linking it to the source code and the environment.
- Automation is Essential: Never rely on manual processes for provenance. It must be generated and signed by the CI/CD pipeline itself to prevent tampering.
- Verification is the Goal: Generating provenance is useless if it is not verified. Implement admission control in your deployment pipelines to reject any artifact that lacks a valid provenance record.
- Keyless Signing is the Standard: Move away from long-lived GPG/SSH keys for signing. Use OIDC-based identity systems to issue short-lived certificates, which significantly reduces the risk of credential theft.
- Defense-in-Depth: Build provenance is one critical component of a secure supply chain. Combine it with SBOMs, vulnerability scanning, and signed commits to create a comprehensive security posture.
- Reproducibility as a North Star: Strive for reproducible builds to add an extra layer of assurance that your build process is deterministic and free from hidden tampering.
- Policy as Code: Use tools like OPA or Kyverno to translate your security requirements into machine-readable policies that automatically enforce provenance verification at the cluster level.
By mastering the fundamentals of build provenance, you transition from a reactive security posture to a proactive one. You are no longer just hoping your software is safe; you are building the technical evidence required to prove it. This shift is essential for any organization that takes the integrity of its software seriously and wants to protect its users from the growing threat of supply chain compromises. Start by identifying your most critical build pipelines, implement automated signing, and slowly expand these practices across your entire engineering organization.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
Spend your points to unlock exam-style practice questions
Spend points to unlock GH-500 exam-style practice questions.
Practice for GH-500