kubesec: score a Kubernetes manifest's security settings (controlplane.io kubesec 2.15)
kubesec scan [flags] FILE|-
What it does
Each rule that matches adds its points: risky settings (privileged, hostNetwork, SYS_ADMIN, docker.sock, secrets in env vars) are critical with negative points, hardening (runAsNonRoot, readOnlyRootFilesystem, capabilities drop ALL, seccomp, AppArmor, resource limits, a service account) passes with positive points; a hardening rule that does not match is listed under advise. Score 0 or below exits 2.
Options you will use
-f, --format json|table|template- Output format (default json: an array, one report per document).
-r, --rules LIST- Scan only these rule IDs, e.g. RunAsNonRoot,SeccompAny.
--exit-code INT- Exit code when an object scores 0 or less (default 2).
-o, --output FILE- Also write the report to FILE.
--absolute-path- Report the file name as an absolute path.
Examples
$ kubesec scan pod.yamlthe JSON report: score, critical, passed, advise
$ kubesec scan deploy.yaml | jq '.[0].scoring.critical[].id'only the critical findings
$ helm template ./chart | kubesec scan -a rendered chart from stdin
Gotchas
- A score above 0 is not "secure": it is the sum of points. A privileged container (-30) outweighs every hardening point, but hostPID (-9) can still end at "Passed with a score of 7 points".
- A score of exactly 0 prints "Passed with a score of 0 points" and still exits 2: the message tests >= 0, the exit code <= 0 (pkg/ruler/ruleset.go, cmd/scan.go).
- The object is named Kind/name.namespace; no namespace in the manifest reads as default.
Taught in
On the blog
Try kubesec in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.