Cosign: Container Image Signing & Verification
Author: Fabrice JAMMES (LinkedIn).
Objective
- Sign a container image with Cosign and a key pair
- Verify the signature, and see why an image is signed by digest, not by tag
A signature proves who published an image and that it was not changed since: only the images signed by your CI should run in production.
The CKS curriculum lists “Secure your supply chain: permitted registries, sign and validate artifacts” in the Supply chain security domain.
Prerequisites
cosign and docker are installed on the training server. The registry localhost:5000 is shared by all the accounts of the server: each trainee pushes in a repository of their own.
Exercise 1: push an image and find its digest
Push the image nginx:1.27-alpine to the registry as $IMAGE. Find its digest: the sha256 of its manifest.
Exercise 2: sign the image
Generate a key pair with the password test123, then sign the image by digest with the private key.
Note
By default, Cosign also writes the signature in Rekor, the public transparency log of Sigstore. The lab disables it (--tlog-upload=false) not to publish training signatures; the verification then needs --insecure-ignore-tlog=true.
Exercise 3: verify the signature
- Verify the signature of
$IMAGEwith the public key. - Verify it with the public key of another key pair.
- Push
nginx:1.29-alpinewith the same tag$IMAGE, and verify$IMAGEagain. Then verify$DIGEST.
Questions
- How do you prevent the cluster from running an image which is not signed?
- What is “keyless” signing?
Clean up
The 2-cosign.sh script of the k8s-advanced repository runs a similar scenario, and keyless signing.