container-livenessprobe-httpget-host
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 container is never restarted.
object.spec.containers.all(c,
!has(c.livenessProbe) ||
!has(c.livenessProbe.httpGet) ||
!has(c.livenessProbe.httpGet.host) ||
c.livenessProbe.httpGet.host == ""
)
spec.containers[*].livenessProbe.httpGet.host must be undefined or empty ("").
Remove the host field so the probe targets the pod IP, or set it to an empty string. Field: spec.containers[*].livenessProbe.httpGet.host.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: container-livenessprobe-httpget-host
annotations:
kubeapt.io/uuid: "f871b54a-afc3-47b9-b25f-0dfac4e2924a"
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 container is never restarted."
security.kubeapt.io/resource: "Containers"
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.containers[*].livenessProbe.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.livenessProbe) ||
!has(c.livenessProbe.httpGet) ||
!has(c.livenessProbe.httpGet.host) ||
c.livenessProbe.httpGet.host == ""
)
message: |
spec.containers[*].livenessProbe.httpGet.host must be undefined or empty ("").Save it as container-livenessprobe-httpget-host.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./container-livenessprobe-httpget-host.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name container-livenessprobe-httpget-host -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name container-livenessprobe-httpget-host -A