Base Image and SBOM Verification
If we want to allow only specific types of base images to be deployed, we can save that information into the image attestation after obtaining it.
In Vulnerability Scanning and Verification, the cosign-vuln format attestations already include the base image information.
But here we will use a different approach, using syft to generate the SBOM for the image.
The SBOM information also includes the base image information.
In ACP (Alauda Container Platform), you can use trivy or syft task in Tekton Pipeline to generate the SBOM for image.
Here we use the syft task to generate SBOM.
TOC
Feature OverviewUse CasesPrerequisitesProcess OverviewStep-by-Step InstructionsSteps 1-3: Basic SetupStep 4: Create a Sample PipelineStep 5: Run a Sample PipelineStep 6: Wait for the PipelineRun to be signedStep 7: Get the image from the PipelineRunStep 8: (Optional) Get the SBOM attestationStep 9: Verify the base image informationStep 9.1: Create a Kyverno policy to verify the base image informationStep 9.2: Verify the policyStep 10: Clean up the resourcesExpected ResultsReferencesFeature Overview
This method uses tools similar to syft to generate SBOM for the image and then use Kyverno to verify the SBOM:
- Use
syftTekton Task to generate SBOM for the image and attach to the image. - Configure Kyverno rules to verify the SBOM.
- Use the image to create a Pod to verify the SBOM.
Use Cases
The following scenarios require referring to the guidance in this document:
- Implementing base image verification in Kubernetes clusters using Kyverno
- Enforcing security policies to only allow specific base images to be deployed
- Setting up automated SBOM generation and verification in CI/CD pipelines
- Ensuring base image compliance in production environments
- Implementing supply chain security controls for container images by verifying their base image information
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-3: Basic Setup
These steps are identical to the Quick Start: Signed Provenance guide. Please follow the instructions in that guide for:
- Step 1: Generate Signing Keys
- Step 2: Set up Authentication
- Step 3: Configure Tekton Chains
- Get the signing secret
- Important: This is only for convenience, so the global signing certificate of Chains is used here. In actual use, you can use a separate certificate to sign the image vulnerability information.
- Import the secret into the namespace where the pipeline is executed.
Step 4: Create a Sample Pipeline
This is a Pipeline resource, which is used to build the image and generate the SBOM.
This tutorial demonstrates a simplified workflow by generating the Containerfile and git-clone task output inline within the pipeline.
In production environments, you would typically:
- Use the
git-clonetask to fetch source code from your repository - Build the image using the Containerfile that exists in your source code
- This approach ensures proper version control and maintains the separation between code and pipeline configuration
Explanation of YAML fields
- The same as in Step 4: Create a Sample Pipeline, but adds the following content:
workspaces:signkey: The workspace for private keys and passwords used for image signatures.
tasks:syft-sbom: The task to generate the SBOM for the image and upload the attestation. :::
Save into a yaml file named chains-demo-5.yaml and apply it with:
Step 5: Run a Sample Pipeline
This is a PipelineRun resource, which is used to run the pipeline.
:::details {title="Explanation of YAML fields"}
- The same as in Step 5: Run a Sample Pipeline. Below only introduces the differences.
workspacessignkey: the secret name of the signing key.secret.secretName: The signing secret prepared in the previous step Get the signing secret. But you need to create a new secret with the same namespace as the pipeline run. :::
Save into a yaml file named chains-demo-5.pipelinerun.yaml and apply it with:
Wait for the PipelineRun to be completed.
Step 6: Wait for the PipelineRun to be signed
Wait for the PipelineRun has chains.tekton.dev/signed: "true" annotation.
Once the PipelineRun has chains.tekton.dev/signed: "true" annotation, means the image is signed.
Step 7: Get the image from the PipelineRun
This image will be used to verify the SBOM.
Step 8: (Optional) Get the SBOM attestation
If you interested about the SBOM attestation content, you can continue to read the following content.
More details about the cyclonedx SBOM attestation, please refer to cyclonedx SBOM attestation
Get the signing public key according to the Get the signing public key section.
The output will be similar to the following, which contains the components information of the image.
:::details {title="cyclonedx SBOM attestation"}
:::details {title="Description of the fields"}
predicateType: The type of the predicate.predicate:components: The components of the image.bom-ref: The BOM reference of the component.licenses: The licenses of the component.license: The license of the component.name: The name of the license.id: The id of the license.
name: The name of the component.type: The type of the component.version: The version of the component.
metadata: The metadata of the image.timestamp: The timestamp of the image.tools:components: The components of the tool.author: The author of the tool.name: The name of the tool.type: The type of the tool.version: The version of the tool. :::
Step 9: Verify the base image information
Step 9.1: Create a Kyverno policy to verify the base image information
This step requires cluster administrator privileges.
More details about Kyverno ClusterPolicy, please refer to Kyverno ClusterPolicy
The policy is as follows:
:::details {title="Explanation of YAML fields"}
- The policy is largely consistent with the one in Image Signature Verification
spec.rules[0].verifyImages[].attestations[0].conditionstype: The cyclonedx SBOM attestation type ishttps://cyclonedx.org/bomattestors: the same as above.conditions: The conditions to be verified.any: Any of the conditions must be met.key: "{{ components[?type=='operating-system'] | [?name=='ubuntu' && (version=='22.04' || version=='24.04')] | length(@) }}": The operating system must be Ubuntu 22.04 or 24.04.key: "{{ components[?type=='operating-system'] | [?name=='alpine' && (version=='3.18' || version=='3.20')] | length(@) }}": The operating system must be Alpine 3.18 or 3.20. :::
Save the policy to a yaml file named kyverno.verify-base-image.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.
If your base image is Ubuntu 22.04 or 24.04, the Pod will be created successfully.
Change the conditions in the ClusterPolicy to only allow Alpine 3.18 or 3.20.
Then create a Pod to verify the policy.
Receive the output like this:
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 SBOM generation and Kyverno for base image verification
- Your container images automatically include SBOM information in their attestations
- Only images with acceptable base images can be deployed in the specified namespace
- Images with non-compliant base images are automatically blocked by Kyverno policies
- You have implemented a basic supply chain security control by verifying the base image information of your container images
This guide provides a foundation for implementing supply chain security 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