How do you scan Kubernetes manifests and Dockerfiles with Checkov?
BeginnerHands-onCheckov
Answer
Short answer
Point Checkov at the folder (or use --framework kubernetes / dockerfile). It checks Kubernetes manifests for things like privileged containers, root users, missing limits and probes, and Dockerfiles for things like no USER, latest tags, ADD instead of COPY and missing HEALTHCHECK. Helm charts and Kustomize are rendered and scanned too.
Commands
checkov -d ./k8s --framework kubernetes
checkov -f Dockerfile --framework dockerfile
checkov -d ./charts/shop --framework helm
checkov -d ./overlays/prod --framework kustomize
Typical Kubernetes findings
| Check | Meaning |
|---|---|
| CKV_K8S_8 / 9 | Liveness / readiness probe missing |
| CKV_K8S_11 / 13 | CPU / memory limits missing |
| CKV_K8S_20 | allowPrivilegeEscalation not false |
| CKV_K8S_23 | Container may run as root (runAsNonRoot missing) |
| CKV_K8S_14 | Image tag is latest or missing |
| CKV_K8S_16 | Privileged container |
A hardened container spec that passes most checks
securityContext:
runAsNonRoot: true
runAsUser: 10001
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: ["ALL"] }
resources:
requests: { cpu: 100m, memory: 128Mi }
limits: { memory: 256Mi }
Dockerfile findings
CKV_DOCKER_2 (no HEALTHCHECK), CKV_DOCKER_3 (no non-root USER), CKV_DOCKER_7 (latest tag in FROM).
What to say in the interview
"Checkov's kubernetes, helm, kustomize and dockerfile frameworks catch root or privileged containers, missing limits and probes, latest tags and missing USER instructions. Fixing them means a hardened securityContext, resources, probes and pinned images."
More on Checkov
What is Checkov and how do you scan Terraform with it?BeginnerWhat is IaC security scanning and why is it needed?BeginnerWhat is Checkov?BeginnerHow do you scan Terraform code with Checkov?BeginnerWhy scan the Terraform plan with Checkov instead of only the .tf files?IntermediateHow do you skip a Checkov check with a documented reason?Intermediate