Image Signature Verification
In Tekton Chains, it can automatically sign the built image and record the signature in the SLSA Provenance.
TOC
Feature Overview
This method uses Tekton Chains to automatically sign the built image and then use cosign or Kyverno to verify the signature:
- Configure Tekton Chains to automatically sign the built image.
- Use
buildahTekton Task to build the image. - (Optional) Use
cosigncli to verify the signature. - Configure Kyverno rules to allow only signed images.
- Use the image to create a Pod to verify the signature.
Compared to Quick Start: Signed Provenance, this method only adds more verification steps.
Use Cases
The following scenarios require referring to the guidance in this document:
- Implementing image signature verification in Kubernetes clusters using Kyverno
- Enforcing security policies to only allow signed images to be deployed
- Setting up automated image signature verification in CI/CD pipelines
- Ensuring image integrity and authenticity in production environments
- Implementing supply chain security controls for container images
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: 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
- Step 4: Create a Sample Pipeline
- Step 5: Run a Sample Pipeline
- Step 6: Wait for the PipelineRun to be signed
- Step 7: Get the image from the PipelineRun
Step 8: Verify the signature with Kyverno
At Step 8: Verifying the Image and Attestation, we use cosign CLI to verify the signature.
Here we use Kyverno to verify the signature.
Step 8.1: Create a Kyverno policy to allow only signed images to be deployed
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"}
spec.rules[].match.any[].resources: The resources to be matched and validated.kinds: The kinds of the resources to be matched and validated.Pod: The Pod resources.
namespaces: The namespaces of the resources to be matched and validated.policy: The resources in thepolicynamespace will be matched and validated.
spec.rules[].verifyImages: The verify imagesimageReferences: The image references to be verified.*: all image references will be verified.<registry>/test/*: only image references in the<registry>/testregistry will be verified.
skipImageReferences: The image references to be skipped.ghcr.io/trusted/*: only image references in theghcr.io/trustedregistry will be skipped.
imageRegistryCredentials:allowInsecureRegistry: Whether to allow insecure registry.secrets: The secrets to be used for the image registry credentials.registry-credentials: The name of the secret. The secret needs to exist in the namespace where kyverno is deployed.
attestors: The attestors to be used for the image verification.count: The count of the attestors need to be matched.entries: The entries of the attestors.keys: The keys of the attestors.publicKeys: The public keys of the attestors.- This public key is the same as the public key
cosign.pubin thesigning-secretssecret.
- This public key is the same as the public key
ctlog: The ctlog of the attestors.ignoreSCT: Whether to ignore the SCT.- In isolated network environments, ignore the SCT first.
rekor: The rekor of the attestors.ignoreTlog: Whether to ignore the Tlog.- In isolated network environments, ignore the Tlog first. :::
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 into a yaml file named kyverno.only-cosign-image-deploy.yaml and apply it with:
Step 8.2: Verify the policy
In the policy namespace where the policy is defined, create a Pod to verify the policy.
Use the signed image created by the pipeline to create a Pod.
The Pod will be created successfully.
Use the unsigned image to create a Pod.
Receive the output like this, means the Pod is blocked by the policy.
Step 9: 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 image signing and Kyverno for signature verification
- Your container images are automatically signed during the build process
- Only signed images can be deployed in the specified namespace
- Unsigned images are automatically blocked by Kyverno policies
- You have implemented a basic supply chain security control for 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
- Consider implementing additional security controls like vulnerability scanning