pod-volume-types
Volume sources outside the allowed set, such as hostPath, gitRepo or flexVolume, mount node filesystem paths or run driver code on the node, opening a route to kubelet credentials and the container runtime socket.
!has(object.spec.volumes) || object.spec.volumes.all(v,
has(v.configMap) ||
has(v.csi) ||
has(v.downwardAPI) ||
has(v.emptyDir) ||
has(v.ephemeral) ||
has(v.persistentVolumeClaim) ||
has(v.projected) ||
has(v.secret)
)
Each item in spec.volumes[*] must set one of: configMap, csi, downwardAPI, emptyDir, ephemeral, persistentVolumeClaim, projected, or secret.
Replace the volume with an allowed source (configMap, csi, downwardAPI, emptyDir, ephemeral, persistentVolumeClaim, projected or secret) and expose node-local data through a PersistentVolumeClaim instead. Field: spec.volumes[*].
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: pod-volume-types
annotations:
kubeapt.io/uuid: "d727820a-72b4-4c75-bf4c-17da0e3e4c81"
security.kubeapt.io/displayName: "Uses a Volume Type Outside the Allowed Set"
security.kubeapt.io/description: "Volume sources outside the allowed set, such as hostPath, gitRepo or flexVolume, mount node filesystem paths or run driver code on the node, opening a route to kubelet credentials and the container runtime socket."
security.kubeapt.io/resource: "Pods"
security.kubeapt.io/severity: "High"
security.kubeapt.io/remediation: "Replace the volume with an allowed source (configMap, csi, downwardAPI, emptyDir, ephemeral, persistentVolumeClaim, projected or secret) and expose node-local data through a PersistentVolumeClaim instead. Field: spec.volumes[*]."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods
validations:
- expression: |
!has(object.spec.volumes) || object.spec.volumes.all(v,
has(v.configMap) ||
has(v.csi) ||
has(v.downwardAPI) ||
has(v.emptyDir) ||
has(v.ephemeral) ||
has(v.persistentVolumeClaim) ||
has(v.projected) ||
has(v.secret)
)
message: |
Each item in spec.volumes[*] must set one of: configMap, csi, downwardAPI, emptyDir, ephemeral, persistentVolumeClaim, projected, or secret.Save it as pod-volume-types.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./pod-volume-types.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name pod-volume-types -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-volume-types -A