TMA-KUBERNETES-5.2.2
Minimize the admission of privileged containers
Nghiêm trọngCấp 1Tự độngkubernetes
Mô tả
Do not generally permit containers to be run with the securityContext.privileged flag set to true. Requires kubectl with cluster-wide read access (KUBECONFIG); system namespaces are excluded and listed resources must be remediated or documented as exceptions. The benchmark marks this Manual; this audit automates its kubectl inventory step.
Cách kiểm tra
Phương pháp kiểm tra: Lệnh shell
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- Đầu ra mong đợi
compliant
Cách khắc phục
Phương pháp khắc phục: Hướng dẫn hoặc bản vá hạ tầng
Add policies to each namespace in the cluster which has user workloads to restrict the admission of privileged containers.
Thuộc tính
- Hệ điều hành
- Bất kỳ
- Thẻ
- kubernetespoliciespod-security
- Tham chiếu
- CIS Kubernetes Benchmark v2.1.0 - 5.2.2 Minimize the admission of privileged containers
Kiểm tra máy này
Chạy lệnh này trên máy bạn được phép kiểm tra. Lần quét chỉ ở chế độ đọc.
shell
tmaegis scan --target kubernetes