Build System Provenance Verification
In the SLSA provenance, there is a builder.id field, which is used to indicate the build environment of the image.
In this document, we will use this builder.id field to verify the image.
Since Tekton Chains has already handled both image signing and SLSA provenance generation in the preparation stage, we can directly reuse the process and images from Quick Start: Signed Provenance.
We will focus on verifying the SLSA provenance in this document.
TOC
Feature Overview
This method uses Chains to automatically generate SLSA Provenance for the built image and then use Kyverno to verify the provenance:
- Configure Tekton Chains to automatically generate SLSA Provenance for the built image.
- Use
buildahTekton Task to build the image. - (Optional) Use
cosigncli to verify the attestation. - Configure Kyverno rules to verify the attestation.
- Use the image to create a Pod to verify the attestation.
Use Cases
The following scenarios require referring to the guidance in this document:
- Verifying the build environment of container images using SLSA provenance
- Implementing build system provenance verification using CUE or Rego policies
- Enforcing security policies to only allow images built in specific build environments
- Setting up automated build system provenance verification in CI/CD pipelines
- Ensuring build system provenance integrity and authenticity in production environments
Prerequisites
- A Kubernetes cluster with Tekton Pipelines, Tekton Chains and Kyverno installed
- A registry with image pushing enabled
kubectlCLI installed and configured to access your clustercosignCLI tool installedjqCLI tool installed
Process Overview
Step-by-Step Instructions
Steps 1-7: (Optional) Basic Setup
If you change the builder.id field, you need to re-run the pipeline to generate the image.
Because the old image is not signed with the new builder.id, so it will be blocked by the policy.
Otherwise, you can skip this step, use the old image to verify the policy.
These steps are identical to the Quick Start: Signed Provenance guide. Please follow the instructions in that guide for:
-
Step 3: Configure Tekton Chains
If you want to change the default
builder.id, you can adjust thebuilder.idfield in theconfigofTektonConfig.TIPThis process requires platform administrator privileges to configure.
Step 8: (Optional) Verify the builder info with cosign
This step is optional and should be performed when you need to verify the authenticity of the image builder by cosign.
If you interested how to use CUE or Rego to verify the builder info, you can continue to read the following content.
Get the signing public key according to the Get the signing public key section.
Cosign provides two ways to validate the attestation:
The following will show the verification methods of these two ways.
Way 1: Use CUE to verify
Generate the CUE file to verify the builder info.
Save the CUE file to builder.cue
Verify the builder info with cosign.
Receive the output like this, means the builder info verification is successful.
Change the builder id in the builder.cue file to an other value https://alauda.io/builders/tekton/v2, and verify again.
Receive the output like this, means the builder info verification is failed.
Way 2: Use Rego to verify
Generate the Rego file to verify the builder info.
Save the Rego file to builder.rego
Verify the builder info with cosign.
Receive the output like this, means the builder info verification is successful.
Change the builder id in the builder.rego file to an other value https://alauda.io/builders/tekton/v2, and verify again.
Receive the output like this, means the builder info verification is failed.
Step 9: Verify the signature with Kyverno
This step requires cluster administrator privileges.
The content of the provenance is roughly as follows, we will use the builder.id field to verify the build environment.
Step 9.1: Create a Kyverno policy to allow only images built in specific build environments to be deployed
More details about Kyverno ClusterPolicy, please refer to Kyverno ClusterPolicy
The policy is as follows:
Explanation of YAML fields
- The policy is largely consistent with the one in Image Signature Verification. Below only introduces the differences.
spec.rules[0].verifyImages[].attestations[0].conditionstype: The slsa provenance type ishttps://slsa.dev/provenance/v0.2orhttps://slsa.dev/provenance/v1.attestors: the same as above.conditions: The conditions to be verified.all: All conditions must be met.key: "{{ builder.id }}": This check thebuilder.idfield in the attestation is equal tohttps://alauda.io/builders/tekton/v1
Need to adjust the configuration
spec.rules[].attestors[].entries[].keys.publicKeys: The public key of the signer.- This public key is the same as the public key
cosign.pubin thesigning-secretssecret. - The public key can be obtained from the Get the Signing Public Key section.
- This public key is the same as the public key
Save the policy to a yaml file named kyverno.verify-tekton-built-images.yaml and apply it with:
Step 9.2: Verify the policy
In the policy namespace where the policy is defined, create a Pod to verify the policy.
Use the built image to create a Pod.
The Pod will be created successfully.
Change the builder id in the ClusterPolicy to an other value https://alauda.io/builders/tekton/v2, and verify again.
Receive the output like this, means the Pod is blocked by the policy.
Step 10: Clean up the resources
Delete the Pods created in the previous steps.
Delete the policy.
Expected Results
After completing this guide:
- You have a working setup with Tekton Chains for generating SLSA provenance
- Your container images are automatically signed with build system provenance during the build process
- You can verify the build environment of images using either CUE or Rego policies
- Only images built in the specified build environment can be deployed in the specified namespace
- Images built in unauthorized build environments are automatically blocked by Kyverno policies
- You have implemented a basic build system provenance verification control for your container images
This guide provides a foundation for implementing build system provenance verification in your CI/CD pipelines. In a production environment, you should:
- Configure proper namespace isolation and access controls
- Implement secure key management for signing keys
- Set up monitoring and alerting for policy violations
- Regularly rotate signing keys and update security policies
- Consider implementing additional security controls like vulnerability scanning