Amazon EKS
TMA-EKS-4.2.1
Minimize the admission of privileged containers
Description
Minimize the admission of privileged containers in EKS by enforcing Pod Security Standards through Pod Security Admission or an equivalent policy engine, and restrict privileged workloads to only the limited system or platform namespaces that truly require them. Requires kubectl with cluster-wide read access (KUBECONFIG); system namespaces are excluded and listed resources must be remediated or documented as exceptions.
Méthode de vérification
Méthode d'audit: Commande shell
out=$(kubectl get pods -A -o go-template='{{range .items}}{{$ns:=.metadata.namespace}}{{$p:=.metadata.name}}{{range .spec.containers}}{{$ns}} {{$p}} {{.name}} {{with .securityContext}}{{.privileged}}{{end}}{{"\n"}}{{end}}{{range .spec.initContainers}}{{$ns}} {{$p}} {{.name}} {{with .securityContext}}{{.privileged}}{{end}}{{"\n"}}{{end}}{{range .spec.ephemeralContainers}}{{$ns}} {{$p}} {{.name}} {{with .securityContext}}{{.privileged}}{{end}}{{"\n"}}{{end}}{{end}}') || exit 1
bad=$(printf '%s\n' "$out" | awk -v ex='^(kube-system|kube-public|kube-node-lease)$' 'NF && $1 !~ ex && ($4=="true")')
if [ -z "$bad" ]; then echo compliant; else printf '%s\n' "$bad" | head -n 25; fi- Sortie attendue
compliant
Méthode de correction
Méthode de correction: Recommandation ou correctif d'infrastructure
Configure Pod Security Admission on workload namespaces so privileged containers are denied when new pods are created. In EKS, Pod Security Standards are applied through namespace labels, and current AWS guidance is to enforce at least baseline cluster-wide and restricted for workload namespaces. For this control, both baseline and restricted disallow privileged containers, but restricted is typically the stronger choice for user workloads. Only enforce blocks noncompliant pods. warn and audit are useful during rollout, but they do not remediate the issue by themselves. • Label each workload namespace to enforce restricted. kubectl label ns NAMESPACE pod-security.kubernetes.io/enforce=restricted --overwrite • Add warn and audit labels during transition so violations are surfaced before or alongside enforcement.
Propriétés
- Systèmes d'exploitation
- Tous
- Étiquettes
- ekspoliciespod-security
- Référence
- CIS Amazon Elastic Kubernetes Service (EKS) Benchmark v2.0.0 - 4.2.1 Minimize the admission of privileged containers
Vérifier cet hôte
Exécutez cette commande sur une machine que vous êtes autorisé à auditer. L'analyse est en lecture seule.
tmaegis scan --target eks