← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Startup Probe Targets an Arbitrary Host

initcontainer-startupprobe-httpget-host

severityLow resourceInitContainers productKubernetes bundles2

Redirecting the startup HTTP probe to another host makes the kubelet fetch an arbitrary URL from the node, reaching metadata and node-local endpoints closed to pods, and a hung init container passes its startup gate.

Rejects unless

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

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

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: initcontainer-startupprobe-httpget-host
  annotations:
    kubeapt.io/uuid: "f49ff543-8ed7-441b-9fb2-69dc4ed5338e"
    security.kubeapt.io/displayName: "Startup Probe Targets an Arbitrary Host"
    security.kubeapt.io/description: "Redirecting the startup HTTP probe to another host makes the kubelet fetch an arbitrary URL from the node, reaching metadata and node-local endpoints closed to pods, and a hung init container passes its startup gate."
    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[*].startupProbe.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.startupProbe) ||
        !has(ic.startupProbe.httpGet) ||
        !has(ic.startupProbe.httpGet.host) ||
        ic.startupProbe.httpGet.host == ""
      )
    message: |
      spec.initContainers[*].startupProbe.httpGet.host must be undefined or empty ("").

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

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

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