Skip to content

Image signing

How Playtelly images are signed in CI and checked in the cluster before they run. For versioning, releases and deployment, see Version Control and Release Guide.


1. Overview

Two layers protect production:

  1. CI signs every image it publishes to the playtelly namespace in Nexus.
  2. The cluster checks the signature when a Pod is created, so an unsigned image cannot start by accident (an old overlay, a manual kubectl, a hand-pushed image).

Only images signed by the pipeline, with the group signing key, should run.


2. Layer 1: signing in CI

  • Every image published to the playtelly namespace in Nexus is signed with cosign.
  • The sign job fails early, with a clear message, if the cosign variables are missing.
  • The public key (cosign.pub) is the same file in every service repo. The private key is COSIGN_PRIVATE_KEY in GitLab group variables.
  • Source and image scans (including the SBOM) run in the pipeline. The scan database is cached and scans run in parallel to keep pipelines fast.
  • Signatures are stored in Nexus as sha256-<digest>.sig tags. Do not delete them by hand. The nightly cleanup removes them together with their image.

3. Layer 2: policy in the cluster (Kyverno)

A policy checks the cosign signature when a Pod is created, so an unsigned image cannot start by accident (an old overlay, a manual kubectl, a hand-pushed image).

Engine Kyverno v1.19.1, ImageValidatingPolicy
Scope Only registry.nexus.castis.io/playtelly/*. Other images are never checked.
Current mode Deny: Pods with an unsigned playtelly/* image are refused (fail open if Kyverno is down)
Managed by ArgoCD (policies). Kyverno itself is installed by hand with Helm.
Failure behaviour Fails open: if Kyverno is down, Pods still start

Policy tuning done so far:

  • Digest mutation and digest verification are off, because they made ArgoCD show Deployments as OutOfSync.
  • One service that is not signed yet is temporarily exempt (see section 9).

4. Install runbook

  1. Namespace and pull secret. Push the change. The registry-secrets ApplicationSet creates the kyverno namespace and its pull secret.
kubectl -n kyverno get secret nexus-registry-secret
  1. Mirror images and chart into Nexus. The cluster mixes amd64 and arm64, so use docker buildx imagetools create, never docker pull/tag/push.
docker login registry.nexus.castis.io
for img in kyverno kyvernopre reports-controller kyverno-cli; do
  docker buildx imagetools create \
    --tag registry.nexus.castis.io/kyverno/$img:v1.19.1 reg.kyverno.io/kyverno/$img:v1.19.1
done
docker buildx imagetools create \
  --tag registry.nexus.castis.io/kyverno/readiness-checker:v1.19.1 \
  ghcr.io/kyverno/readiness-checker:v1.19.1

Then the chart. Nexus helm-hosted is a classic HTTP Helm repo, not OCI, so helm push fails. Upload with curl and never commit the password:

helm pull kyverno --repo https://kyverno.github.io/kyverno/ --version 3.9.1
curl -u "helm:<password>" https://nexus.castis.io/repository/helm-hosted/ --upload-file kyverno-3.9.1.tgz
helm repo update my-nexus
  1. Install Kyverno.
helm upgrade --install kyverno my-nexus/kyverno --version 3.9.1 \
  -n kyverno --create-namespace -f services/infrastructure/kyverno/kyverno-values.yaml
  1. Check it is up.
kubectl -n kyverno get pods
kubectl get crd imagevalidatingpolicies.policies.kyverno.io
  1. Apply the policy in Audit mode. Let ArgoCD own it (the kyverno-policies application) so the later switch to Deny is a Git change. Push it only after Kyverno is installed, otherwise the sync fails on the missing CRD.
kubectl get imagevalidatingpolicy verify-playtelly-image-signature
  1. Read the audit report. New Pods are checked at admission, and existing Pods are scanned about hourly.
kubectl get policyreport -A
kubectl -n kyverno logs deploy/kyverno-admission-controller | grep verify-playtelly-image-signature
  1. Fix what is unsigned. The real fix is to get the image signed. For a short exemption, add a matchConditions entry to the policy and remove it once the image is signed. Do not use label-based exemptions: anyone who can create a Pod can set a label. Repeat step 6 until the report is empty.

  2. Switch to Deny.

  3. Optionally raise admission replicas above 2 in kyverno-values.yaml and rerun the Helm upgrade.
  4. In a throwaway namespace, check that a Pod with a signed image starts and a Pod with an old unsigned tag is reported.
  5. Change validationActions: [Audit] to [Deny] in policies/verify-playtelly-image-signature.yaml and push.

5. Roll back

Goal Action
Back to report-only Set validationActions: [Audit] again (Git, or kubectl edit imagevalidatingpolicy ...)
Remove the rule kubectl delete imagevalidatingpolicy verify-playtelly-image-signature
Remove Kyverno helm uninstall kyverno -n kyverno (CRDs stay; the cleanup hook needs the mirrored readiness-checker image)

6. Notes and limits

  • Fail open. Even in Deny mode the rule is only as strong as Kyverno's availability.
  • Tags resolve at admission. prod-latest is resolved to its digest when the Pod is checked. The signature is on the digest.
  • No transparency log. The pipeline signs with --tlog-upload=false, hence insecureIgnoreTlog: true.
  • Key rotation. Add the new key as a second attestor, sign new images with it, then remove the old key.
  • Not yet applied to a live cluster. The policy was validated against the CRD schema only. Check behaviour in Audit mode first.

7. Required settings

Variable Purpose
COSIGN_PRIVATE_KEY, COSIGN_PASSWORD Sign images (GitLab group level)
  • cosign.pub in every service repo root is the public half of the group signing key, and must be the same file everywhere.
  • Never print or commit secrets. Share only key names, not values.
  • Protect the tag pattern v* so tag pipelines can read protected variables such as the signing key.

8. Troubleshooting

Symptom Likely cause Fix
sign job fails immediately cosign variables missing Set COSIGN_PRIVATE_KEY and COSIGN_PASSWORD
ArgoCD shows Deployments OutOfSync after Kyverno Digest mutation enabled Keep mutateDigest and verifyDigest off
Kyverno policy sync fails on a missing CRD Policy pushed before Kyverno installed Install Kyverno first (step 3), then sync
helm push fails with 405 Nexus helm-hosted is not OCI Upload the chart with curl
Policy report shows a failure for a workload Image is unsigned Sign it, or add a temporary matchConditions exemption

9. Open tasks

  • Sign the service that is currently exempt from the policy and remove its exemption.
  • Move the signature policy from Audit to Deny (section 4, step 8).
  • Commit the pending change to the signing step in the shared templates.