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 命令
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