C-0213 - Minimize the admission of privileged containers

Framework

cis-eks-t1.2.0, cis-aks-t1.2.0

Severity

High

Description of the the issue

Privileged containers have access to all Linux Kernel capabilities and devices. A container running with full privileges can do almost everything that the host can do. This flag exists to allow special use-cases, like manipulating the network stack and accessing devices.

There should be at least one PodSecurityPolicy (PSP) defined which does not permit privileged containers.

If you need to run privileged containers, this should be defined in a separate PSP and you should carefully check RBAC controls to ensure that only limited service accounts and users are given permission to access that PSP.

Related resources

PodSecurityPolicy

What does this control test

Do not generally permit containers to be run with the securityContext.privileged flag set to true.

How to check it manually

Get the set of PSPs with the following command:

kubectl get psp

For each PSP, check whether privileged is enabled:

kubectl get psp -o json

Verify that there is at least one PSP which does not return true.

kubectl get psp <name> -o=jsonpath='{.spec.privileged}'

Remediation

Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.privileged field is set to false.

Impact Statement

Pods defined with spec.containers[].securityContext.privileged: true will not be permitted.

Default Value

By default, when you provision an EKS cluster, a pod security policy called eks.privileged is automatically created. The manifest for that policy appears below:

apiVersion: extensions/v1beta1
kind: PodSecurityPolicy
metadata:
  annotations:
    kubernetes.io/description: privileged allows full unrestricted access to pod features,
      as if the PodSecurityPolicy controller was not enabled.
    seccomp.security.alpha.kubernetes.io/allowedProfileNames: '*'
  labels:
    eks.amazonaws.com/component: pod-security-policy
    kubernetes.io/cluster-service: "true"
  name: eks.privileged
spec:
  allowPrivilegeEscalation: true
  allowedCapabilities:
  - '*'
  fsGroup:
    rule: RunAsAny
  hostIPC: true
  hostNetwork: true
  hostPID: true
  hostPorts:
  - max: 65535
    min: 0
  privileged: true
  runAsUser:
    rule: RunAsAny
  seLinux:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  volumes:
  - '*'

Example

No example