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