← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Liveness Probe Targets an Arbitrary Host

initcontainer-livenessprobe-httpget-host

severityLow resourceInitContainers productKubernetes bundles2

Redirecting the liveness 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 a hung init container is never restarted.

Rejects unless

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

spec.initContainers[*].livenessProbe.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[*].livenessProbe.httpGet.host.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: initcontainer-livenessprobe-httpget-host
  annotations:
    kubeapt.io/uuid: "2fedfec0-bde4-4c12-ab33-7d9ff294b3fe"
    security.kubeapt.io/displayName: "Liveness Probe Targets an Arbitrary Host"
    security.kubeapt.io/description: "Redirecting the liveness 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 a hung init container is never restarted."
    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[*].livenessProbe.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.livenessProbe) ||
        !has(ic.livenessProbe.httpGet) ||
        !has(ic.livenessProbe.httpGet.host) ||
        ic.livenessProbe.httpGet.host == ""
      )
    message: |
      spec.initContainers[*].livenessProbe.httpGet.host must be undefined or empty ("").

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

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

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