← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Readiness Probe Targets an Arbitrary Host

initcontainer-readinessprobe-httpget-host

severityLow resourceInitContainers productKubernetes bundles2

Redirecting the readiness HTTP probe to another host makes the kubelet fetch an arbitrary URL from the node, reaching metadata and node-local endpoints closed to pods, while pod readiness rests on an unchecked init container.

Rejects unless

!has(object.spec.initContainers) || object.spec.initContainers.all(ic,
  !has(ic.readinessProbe) ||
  !has(ic.readinessProbe.httpGet) ||
  !has(ic.readinessProbe.httpGet.host) ||
  ic.readinessProbe.httpGet.host == ""
)

spec.initContainers[*].readinessProbe.httpGet.host must be undefined or empty ("").

Remediation

Remove the host field so the probe targets the pod IP, or set it to an empty string. Field: spec.initContainers[*].readinessProbe.httpGet.host.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: initcontainer-readinessprobe-httpget-host
  annotations:
    kubeapt.io/uuid: "5dd76a70-9308-4635-94d2-d68e75ba1e24"
    security.kubeapt.io/displayName: "Readiness Probe Targets an Arbitrary Host"
    security.kubeapt.io/description: "Redirecting the readiness HTTP probe to another host makes the kubelet fetch an arbitrary URL from the node, reaching metadata and node-local endpoints closed to pods, while pod readiness rests on an unchecked init container."
    security.kubeapt.io/resource: "InitContainers"
    security.kubeapt.io/severity: "Low"
    security.kubeapt.io/remediation: "Remove the host field so the probe targets the pod IP, or set it to an empty string. Field: spec.initContainers[*].readinessProbe.httpGet.host."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - pods
  validations:
  - expression: |
      !has(object.spec.initContainers) || object.spec.initContainers.all(ic,
        !has(ic.readinessProbe) ||
        !has(ic.readinessProbe.httpGet) ||
        !has(ic.readinessProbe.httpGet.host) ||
        ic.readinessProbe.httpGet.host == ""
      )
    message: |
      spec.initContainers[*].readinessProbe.httpGet.host must be undefined or empty ("").

Save it as initcontainer-readinessprobe-httpget-host.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 ./initcontainer-readinessprobe-httpget-host.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 initcontainer-readinessprobe-httpget-host -r ./manifests

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

$ kubeapt validate --policy-name initcontainer-readinessprobe-httpget-host -A