Skip to content

CKS: Supply Chain Security

20% of the CKS exam, 4 competencies. Back to the CKS overview.

Each competency lists what to know and the official documentation to read, then a demo you can run. Demos run on the demo lab, a throwaway kind cluster on your own machine; set it up once before you start.

Know

  • Use distroless or minimal base images and multi-stage builds; fewer packages means fewer vulnerabilities.

Read

Demo: Fewer packages, fewer findings

  1. Compare the size and content of two images from the same project.

    Terminal window
    docker pull registry.k8s.io/e2e-test-images/agnhost:2.66.1 && docker pull registry.k8s.io/pause:3.10.2
    docker images --format '{{.Repository}}:{{.Tag}} {{.Size}}' | grep -E 'agnhost|pause'
  2. Scan both with Trivy v0.76.2.

    Terminal window
    trivy image --severity HIGH,CRITICAL --quiet registry.k8s.io/e2e-test-images/agnhost:2.66.1 | tail -5
    trivy image --severity HIGH,CRITICAL --quiet registry.k8s.io/pause:3.10.2 | tail -5
  3. Build a minimal image yourself: compile in one stage, ship only the binary.

    Terminal window
    mkdir -p mini && cat > mini/main.go <<'EOF'
    package main
    import ("fmt"; "net/http")
    func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "hi") }); http.ListenAndServe(":8080", nil) }
    EOF
    cat > mini/Dockerfile <<'EOF'
    FROM golang:1.26 AS build
    WORKDIR /src
    COPY main.go .
    RUN go mod init mini && CGO_ENABLED=0 go build -o /app .
    FROM scratch
    COPY --from=build /app /app
    USER 65534
    ENTRYPOINT ["/app"]
    EOF
    docker build -t demo/mini:1.0 mini/ && docker images demo/mini:1.0

What you should see: agnhost is an Alpine-based test image with a shell and tools; pause is a single static binary of under a megabyte, and its scan has nothing to report. The scratch image contains only your binary: no shell for an attacker, and no OS packages to patch.

Note: The build stage pulls golang:1.26 from Docker Hub. Pin it by digest in real pipelines.

Clean up:

Terminal window
rm -rf mini

Understand your supply chain (e.g. SBOM, CI/CD, artifact repositories)

Section titled “Understand your supply chain (e.g. SBOM, CI/CD, artifact repositories)”

Know

  • Know every step from source to running pod, and generate an SBOM for each image.

Read

Demo: Generate an SBOM and scan it later

  1. Generate a CycloneDX SBOM for an image.

    Terminal window
    trivy image --format cyclonedx --output agnhost.cdx.json registry.k8s.io/e2e-test-images/agnhost:2.66.1
    jq '.components | length' agnhost.cdx.json
    jq -r '.components[] | select(.type=="library" or .type=="operating-system") | "\(.name) \(.version)"' agnhost.cdx.json | head
  2. Scan the SBOM instead of the image: the same check, without pulling anything.

    Terminal window
    trivy sbom --severity HIGH,CRITICAL --quiet agnhost.cdx.json | tail -5
  3. Do the same for Kubernetes itself: the project publishes SBOMs for every release.

    Terminal window
    curl -Ls https://sbom.k8s.io/v1.37.2/release | grep -c '^PackageName:'

What you should see: The SBOM lists the OS packages and libraries inside the image. Keep it next to the image in your registry: when a new CVE is announced you can search SBOMs for the affected component across every image you ship, without rescanning them all.

Note: Trivy itself was hit by a supply chain attack in March 2026 (malicious v0.69.4 binaries and v0.69.5 and v0.69.6 images were published briefly). Install it from the official release, verify the checksum, and pin the version.

Clean up:

Terminal window
rm -f agnhost.cdx.json

Secure your supply chain (permitted registries, sign and validate artifacts, etc.)

Section titled “Secure your supply chain (permitted registries, sign and validate artifacts, etc.)”

Know

  • Allow only approved registries with admission policy, and verify image signatures before admission.

Read

Demo: Allow only one registry, and verify signatures

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace cks-supply
    kubectl config set-context --current --namespace=cks-supply
  2. A ValidatingAdmissionPolicy that only admits images from registry.k8s.io in labelled namespaces.

    Terminal window
    kubectl label namespace cks-supply supply-chain=strict
    kubectl apply -f - <<'EOF'
    apiVersion: admissionregistration.k8s.io/v1
    kind: ValidatingAdmissionPolicy
    metadata:
    name: allowed-registries
    spec:
    failurePolicy: Fail
    matchConstraints:
    resourceRules:
    - apiGroups: [""]
    apiVersions: ["v1"]
    operations: ["CREATE", "UPDATE"]
    resources: ["pods"]
    validations:
    - expression: "object.spec.containers.all(c, c.image.startsWith('registry.k8s.io/')) && (!has(object.spec.initContainers) || object.spec.initContainers.all(c, c.image.startsWith('registry.k8s.io/')))"
    message: "images must come from registry.k8s.io"
    ---
    apiVersion: admissionregistration.k8s.io/v1
    kind: ValidatingAdmissionPolicyBinding
    metadata:
    name: allowed-registries
    spec:
    policyName: allowed-registries
    validationActions: ["Deny"]
    matchResources:
    namespaceSelector:
    matchLabels:
    supply-chain: strict
    EOF
    sleep 3
    kubectl run ok --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
    kubectl run nope --image=docker.io/library/busybox:1.37 -- sleep 3600
  3. Verify the signature on an official Kubernetes image with cosign v3.1.4.

    Terminal window
    cosign verify registry.k8s.io/kube-apiserver-amd64:v1.37.2 \
    --certificate-identity krel-trust@k8s-releng-prod.iam.gserviceaccount.com \
    --certificate-oidc-issuer https://accounts.google.com | jq '.[0].critical.image'

What you should see: ok is admitted and nope is rejected with your message. Note startsWith on a string prefix: registry.k8s.io.evil.example/ would also pass, which is why the check includes the trailing slash. cosign prints the verified image digest; to enforce signatures at admission time use a policy controller such as Kyverno or the Sigstore policy-controller.

Clean up:

Terminal window
kubectl delete validatingadmissionpolicybinding allowed-registries
kubectl delete validatingadmissionpolicy allowed-registries
kubectl config set-context --current --namespace=default
kubectl delete namespace cks-supply

Practise

  • Write a ValidatingAdmissionPolicy that rejects images not from your registry.

Perform static analysis of user workloads and container images (e.g. Kubesec, KubeLinter)

Section titled “Perform static analysis of user workloads and container images (e.g. Kubesec, KubeLinter)”

Know

  • Scan manifests for risky settings and images for known CVEs before they reach the cluster.

Read

Demo: Lint manifests before they reach the cluster

  1. A manifest with typical problems.

    Terminal window
    mkdir -p manifests && cat > manifests/risky.yaml <<'EOF'
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: risky
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: risky
    template:
    metadata:
    labels:
    app: risky
    spec:
    hostNetwork: true
    containers:
    - name: app
    image: docker.io/library/nginx:latest
    securityContext:
    privileged: true
    EOF
  2. Scan it with Trivy’s misconfiguration checks and with KubeLinter v0.8.3.

    Terminal window
    trivy config --severity HIGH,CRITICAL manifests/
    kube-linter lint manifests/risky.yaml

What you should see: Both tools flag the privileged container, host networking, the latest tag, and the missing resource limits and read-only root filesystem. Run them in CI and fail the merge request; kubesec and Checkov do the same job with different rule sets.

Note: Install kube-linter (and kubesec, if you want to compare) from their GitHub release pages at a pinned version.

Clean up:

Terminal window
rm -rf manifests

Domain and competency names are from the CNCF CKS curriculum (v1.37), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.