TMA-KUBERNETES-5.2.2
Minimize the admission of privileged containers
심각레벨 1자동kubernetes
설명
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.
점검 방법
감사 방식: 셸 명령
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- 예상 출력
compliant
조치 방법
조치 방식: 가이드 또는 인프라 패치
Add policies to each namespace in the cluster which has user workloads to restrict the admission of privileged containers.
속성
- 운영 체제
- 모두
- 태그
- kubernetespoliciespod-security
- 참고 자료
- CIS Kubernetes Benchmark v2.1.0 - 5.2.2 Minimize the admission of privileged containers
이 호스트 점검하기
감사 권한이 있는 시스템에서 실행하세요. 스캔은 읽기 전용입니다.
shell
tmaegis scan --target kubernetes