ephemeralcontainer-windows-hostprocess
A Windows HostProcess ephemeral container runs directly on the node in the host namespaces under a system account, exposing the host filesystem, registry and services and making node compromise trivial.
!has(object.spec.ephemeralContainers) || object.spec.ephemeralContainers.all(c,
!has(c.securityContext) ||
!has(c.securityContext.windowsOptions) ||
!has(c.securityContext.windowsOptions.hostProcess) ||
c.securityContext.windowsOptions.hostProcess == false
)
HostProcess is not allowed for ephemeral containers. Each spec.ephemeralContainers[*].securityContext.windowsOptions.hostProcess must be undefined or set to false.
Remove windowsOptions.hostProcess from every ephemeral container security context or set it to false. Field: spec.ephemeralContainers[*].securityContext.windowsOptions.hostProcess.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: ephemeralcontainer-windows-hostprocess
annotations:
kubeapt.io/uuid: "c89b27c2-91e3-4523-9e00-6b0e498f6b94"
security.kubeapt.io/displayName: "Runs as a Windows HostProcess"
security.kubeapt.io/description: "A Windows HostProcess ephemeral container runs directly on the node in the host namespaces under a system account, exposing the host filesystem, registry and services and making node compromise trivial."
security.kubeapt.io/resource: "EphemeralContainers"
security.kubeapt.io/severity: "High"
security.kubeapt.io/remediation: "Remove windowsOptions.hostProcess from every ephemeral container security context or set it to false. Field: spec.ephemeralContainers[*].securityContext.windowsOptions.hostProcess."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods/ephemeralcontainers
validations:
- expression: |
!has(object.spec.ephemeralContainers) || object.spec.ephemeralContainers.all(c,
!has(c.securityContext) ||
!has(c.securityContext.windowsOptions) ||
!has(c.securityContext.windowsOptions.hostProcess) ||
c.securityContext.windowsOptions.hostProcess == false
)
message: |
HostProcess is not allowed for ephemeral containers. Each spec.ephemeralContainers[*].securityContext.windowsOptions.hostProcess must be undefined or set to false.Save it as ephemeralcontainer-windows-hostprocess.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./ephemeralcontainer-windows-hostprocess.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name ephemeralcontainer-windows-hostprocess -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name ephemeralcontainer-windows-hostprocess -A