initcontainer-startupprobe-tcpsocket-host
Pointing the startup TCP probe at another host makes the kubelet open connections from the node to an arbitrary address, probing endpoints closed to pods, and a hung init container passes its startup gate.
!has(object.spec.initContainers) || object.spec.initContainers.all(ic,
!has(ic.startupProbe) ||
!has(ic.startupProbe.tcpSocket) ||
!has(ic.startupProbe.tcpSocket.host) ||
ic.startupProbe.tcpSocket.host == ""
)
spec.initContainers[*].startupProbe.tcpSocket.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.initContainers[*].startupProbe.tcpSocket.host.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: initcontainer-startupprobe-tcpsocket-host
annotations:
kubeapt.io/uuid: "b45fe463-3d31-457e-9ad3-850462f795ff"
security.kubeapt.io/displayName: "Startup TCP Probe Targets an Arbitrary Host"
security.kubeapt.io/description: "Pointing the startup TCP probe at another host makes the kubelet open connections from the node to an arbitrary address, probing 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.tcpSocket.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.tcpSocket) ||
!has(ic.startupProbe.tcpSocket.host) ||
ic.startupProbe.tcpSocket.host == ""
)
message: |
spec.initContainers[*].startupProbe.tcpSocket.host must be undefined or empty ("").Save it as initcontainer-startupprobe-tcpsocket-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 ./initcontainer-startupprobe-tcpsocket-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 initcontainer-startupprobe-tcpsocket-host -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name initcontainer-startupprobe-tcpsocket-host -A