← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Runs an Image Not Pinned to a Digest

container-image-digest

severityModerate resourceContainers productKubernetes bundles1

An image reference without a digest resolves through a mutable tag, so registry content can be replaced between pulls and the container silently starts running attacker-supplied code on the next restart or reschedule.

Rejects unless

variables.isWindows || object.spec.containers.all(c,
  c.image.matches(".*@sha256:[0-9A-Fa-f]{64}")
)

spec.containers[*].image must be pinned by an immutable @sha256 digest.

Variables

isWindows

has(object.spec.os) && has(object.spec.os.name) && object.spec.os.name.lowerAscii() == "windows"

Remediation

Replace the mutable tag with an immutable digest reference of the form registry/image@sha256:<64-hex-digest>. Field: spec.containers[*].image.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: container-image-digest
  annotations:
    kubeapt.io/uuid: "97adc456-4552-4280-a0bc-91769cfce7f6"
    security.kubeapt.io/displayName: "Runs an Image Not Pinned to a Digest"
    security.kubeapt.io/description: "An image reference without a digest resolves through a mutable tag, so registry content can be replaced between pulls and the container silently starts running attacker-supplied code on the next restart or reschedule."
    security.kubeapt.io/resource: "Containers"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Replace the mutable tag with an immutable digest reference of the form registry/image@sha256:<64-hex-digest>. Field: spec.containers[*].image."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - pods
  variables:
  - name: isWindows
    expression: |
      has(object.spec.os) && has(object.spec.os.name) && object.spec.os.name.lowerAscii() == "windows"
  validations:
  - expression: |
      variables.isWindows || object.spec.containers.all(c,
        c.image.matches(".*@sha256:[0-9A-Fa-f]{64}")
      )
    message: |
      spec.containers[*].image must be pinned by an immutable @sha256 digest.

Save it as container-image-digest.yaml — the commands below assume that name.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./container-image-digest.yaml -r ./workload.yaml

Or without the file, from the published policy set — -r takes a directory too:

$ kubeapt policies download && kubeapt validate --policy-name container-image-digest -r ./manifests

Or against every namespace in the cluster your kubeconfig points at:

$ kubeapt validate --policy-name container-image-digest -A