← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

postStart Hook Targets an Arbitrary Host

container-poststart-httpget-host

severityLow resourceContainers productKubernetes bundles2

A postStart HTTP hook aimed at another host makes the kubelet call an arbitrary URL from the node each time a container starts, reaching internal endpoints closed to pods and triggering side effects there.

Rejects unless

object.spec.containers.all(c,
  !has(c.lifecycle) ||
  !has(c.lifecycle.postStart) ||
  !has(c.lifecycle.postStart.httpGet) ||
  !has(c.lifecycle.postStart.httpGet.host) ||
  c.lifecycle.postStart.httpGet.host == ""
)

spec.containers[*].lifecycle.postStart.httpGet.host must be undefined or empty ("").

Remediation

Remove the host field so the hook targets the pod IP, or set it to an empty string. Field: spec.containers[*].lifecycle.postStart.httpGet.host.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: container-poststart-httpget-host
  annotations:
    kubeapt.io/uuid: "8aac94da-b019-408f-909d-edc75587c2f9"
    security.kubeapt.io/displayName: "postStart Hook Targets an Arbitrary Host"
    security.kubeapt.io/description: "A postStart HTTP hook aimed at another host makes the kubelet call an arbitrary URL from the node each time a container starts, reaching internal endpoints closed to pods and triggering side effects there."
    security.kubeapt.io/resource: "Containers"
    security.kubeapt.io/severity: "Low"
    security.kubeapt.io/remediation: "Remove the host field so the hook targets the pod IP, or set it to an empty string. Field: spec.containers[*].lifecycle.postStart.httpGet.host."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - pods
  validations:
  - expression: |
      object.spec.containers.all(c,
        !has(c.lifecycle) ||
        !has(c.lifecycle.postStart) ||
        !has(c.lifecycle.postStart.httpGet) ||
        !has(c.lifecycle.postStart.httpGet.host) ||
        c.lifecycle.postStart.httpGet.host == ""
      )
    message: |
      spec.containers[*].lifecycle.postStart.httpGet.host must be undefined or empty ("").

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

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

$ kubeapt validate --policy-name container-poststart-httpget-host -A