Container Audit — Docker & Kubernetes Security Review
Audit container images, Dockerfiles, Helm charts, Kustomize overlays, and Kubernetes manifests for misconfiguration, excessive privilege, exposed secrets, and runtime security gaps. Distinct from cloud-audit (cloud-provider IAM and managed services) and dependency-audit (package CVEs in the application). This skill is the container/orchestration layer between them.
Scope the Audit
- Inventory the surface — Dockerfiles, base images, registries, Helm charts, K8s manifests, Kustomize overlays, CI build pipelines that produce images
- Identify the runtime — vanilla K8s, EKS, GKE, AKS, OpenShift, ECS Fargate, Cloud Run, Fly.io
- Identify the network model — service mesh, ingress controller, default-deny vs default-allow
- Identify the secret model — K8s Secrets (base64-only), External Secrets Operator, sealed-secrets, Vault, Doppler
Audit Checklist — Dockerfile
Base image & supply chain
- Pinned by digest, not tag —
FROM node:20@sha256:abc... not FROM node:20 (which can move)
- Distroless / minimal where possible —
gcr.io/distroless/nodejs20, alpine (be aware of musl quirks), chainguard/*
- Not using
:latest — non-reproducible builds
- Multi-stage builds discard build-time tooling —
FROM build AS builder → FROM runtime final stage
- Grep for:
FROM .*:latest, FROM .*:[0-9]+$ (tag without digest)
Build-time exposure
- Secrets passed via
--build-arg end up in image layers visible to anyone who pulls the image — use BuildKit secrets (--mount=type=secret) or runtime env vars instead
COPY . . ships everything in the build context — .dockerignore should exclude .git, .env, node_modules, *.pem, .aws/, .ssh/
ADD <url> follows redirects and disables checksum verification — prefer RUN curl ... && sha256sum -c
- Grep for:
ARG .*KEY, ARG .*TOKEN, ARG .*SECRET, ENV .*=.*[A-Za-z0-9]{32,}, ADD http
Runtime posture
- Non-root user —
USER 1001 (or any non-zero UID) before CMD
- No
chmod 4755 SUID binaries in the final image
- No unnecessary shells / package managers in the final stage — distroless / FROM scratch is the strong default
HEALTHCHECK defined so orchestrator can detect unhealthy containers
- Read-only root filesystem at runtime (set via K8s; verify nothing in the image writes outside
/tmp or a declared volume)
- Grep for:
USER root (or absence of any USER directive), chmod 4755, apt-get install.*sudo
Audit Checklist — Kubernetes manifests
Pod security
securityContext.runAsNonRoot: true and runAsUser set to a non-zero UID
securityContext.allowPrivilegeEscalation: false
securityContext.readOnlyRootFilesystem: true with explicit emptyDir mounts where the app needs to write
securityContext.capabilities.drop: ["ALL"] then add only what's needed
securityContext.privileged is never true in app workloads (Falco, kube-proxy, some CSI drivers are the rare legit exceptions)
hostNetwork, hostPID, hostIPC all false — yes on these is "container can see / talk to the node"
hostPath volumes — every one is a node-escape risk; review case by case
- Grep for:
privileged: true, runAsUser: 0, hostNetwork: true, hostPath:
Pod Security Standards (PSS) / admission
- Cluster enforces
restricted profile via PSS admission, or equivalent via OPA Gatekeeper / Kyverno
- Pod Security Policies (deprecated since 1.21, removed in 1.25) are NOT what's enforcing this — confirm a current admission controller
- No workloads in the
kube-system namespace running app code
Network
NetworkPolicy exists for every namespace running app workloads — default-deny ingress AND egress, then allow specific pods
- Missing NetworkPolicy = every pod can talk to every other pod on every port, including kube-apiserver and metadata service
- Service mesh (Istio, Linkerd) mTLS in STRICT mode for sensitive namespaces, not PERMISSIVE
- Ingress controllers terminate TLS properly; backend
tls.crt / tls.key in K8s Secrets rotate
Secrets
- K8s Secrets are base64-encoded, NOT encrypted — by default they're plain bytes in etcd
- etcd encryption at rest enabled —
--encryption-provider-config on kube-apiserver
- Workloads consume secrets via projected volumes, not environment variables (env vars leak via
/proc/<pid>/environ, error reports, crash dumps)
- External Secrets Operator / Vault / sealed-secrets bridge so the Git repo never contains plaintext
- Grep for:
kind: Secret in Git with data: fields (base64-encoded values committed)
RBAC
- No
ClusterRole with * verbs on * resources except cluster-admin (audit who's bound to it)
ServiceAccount per workload, not shared "default" SA
automountServiceAccountToken: false on workloads that don't need API access
- Bindings of
system:authenticated group are visible to every legitimate workload — almost always wrong
- Grep for:
verbs: ["*"], resources: ["*"], apiGroups: ["*"], system:authenticated
Resource limits
- Every container has
resources.requests and resources.limits set — missing limits = noisy neighbor + DoS surface (one pod can starve the node)
LimitRange per namespace as a backstop
ResourceQuota per namespace prevents tenant-vs-tenant resource exhaustion
Image policy
imagePullPolicy: Always for :latest (you shouldn't use :latest, but if you do) — otherwise the node caches stale images
- Cluster-level policy that all images come from approved registries (your own + a small allow-list); enforced via Gatekeeper / Kyverno / image-policy-webhook
- Image signature verification — cosign + sigstore policy controller, or Notary v2
Audit Checklist — runtime
- Image scanning in CI —
trivy image, grype, docker scout cves. Must run on every build; advisories should not block but should surface
- Runtime detection — Falco / Tracee / Tetragon catches "shell spawned in a pod that has never opened a shell" patterns
- Audit logs enabled — kube-apiserver audit log captures
exec, attach, port-forward events for incident response
kubectl exec access tracked — not free for any cluster-admin to silently shell into prod
Useful one-liners
# All Dockerfiles in the repo + their first FROM line
git ls-files | grep -E '(^|/)Dockerfile(\.|$)' | xargs -I{} sh -c 'echo "==> {}"; grep ^FROM "{}"'
# Manifests missing securityContext
grep -rL "securityContext" --include="*.yaml" --include="*.yml" .
# Manifests with privileged containers
grep -rln "privileged: *true" --include="*.yaml" --include="*.yml" .
# Manifests with hostPath volumes
grep -rln "hostPath:" --include="*.yaml" --include="*.yml" .
# Secrets in Git (base64-encoded but readable)
grep -rln "kind: *Secret" --include="*.yaml" --include="*.yml" . | xargs grep -l "^data:"
# Image scan (Trivy)
trivy image --severity HIGH,CRITICAL --exit-code 0 <image>
# Manifest scan (Trivy)
trivy config --severity HIGH,CRITICAL .
# Cluster posture (kube-bench, run inside the cluster)
kube-bench run --targets master,node,policies
Verify Fixes at Runtime
runAsNonRoot: true — verify the pod restarts cleanly and stays Running; if the image's ENTRYPOINT calls chown it'll crashloop
- NetworkPolicy default-deny — verify legitimate traffic still works (run an in-cluster
kubectl run -it --rm debug ... curl); silent partial outages are common after default-deny rollout
readOnlyRootFilesystem: true — verify the app doesn't write outside declared emptyDir mounts; log writes, PID files, and tmp files are common breakers
- Image-policy enforcement — try to deploy an unsigned / off-list image; verify admission rejects it
Report Format
# Container Security Audit
## Target: [cluster name / image registry / repo path]
## Date: [date]
### Summary
- Dockerfiles audited: N
- Manifests audited: N
- Cluster posture checks: pass / fail counts
### Findings
| ID | Severity | Category | Location | Issue |
|----|----------|----------|----------|-------|
### Per-finding detail
#### [SEVERITY] [Title]
**File:** `path/to/manifest.yaml:42`
**Category:** Dockerfile | Pod security | RBAC | NetworkPolicy | Secrets | Resource limits | Image policy | Runtime
**Description:** [what the issue is]
**Vulnerable config:**
```yaml
[snippet]
Remediation:
[fixed snippet]
Verification: [observed behavior proving the fix holds]
Disposition rule (Fixed / Deferred / Accepted Risk) matches `owasp-audit`.
## Boundaries
- Only audit clusters and registries the user provides or has authorization for
- Never `kubectl delete` or modify cluster state during an audit — read-only operations only (`get`, `describe`, `auth can-i`)
- For runtime evidence, prefer non-disruptive checks (a `kubectl run -it --rm` ephemeral debug pod) over modifying running workloads
- Refuse cluster-takeover scenarios — escalating from a found weakness to a full pivot is exploitation, not audit
- Flag low-confidence findings as "Potential" rather than confirmed
## References
- CIS Docker Benchmark
- CIS Kubernetes Benchmark
- NSA/CISA Kubernetes Hardening Guide
- Pod Security Standards (PSS) — restricted, baseline, privileged
- OWASP Docker Security Cheat Sheet
- OWASP Kubernetes Security Cheat Sheet
- MITRE ATT&CK for Containers
1---2name: container-audit3description: Audit container images, Dockerfiles, and Kubernetes manifests for misconfigurations, excessive privileges, exposed secrets, and runtime risks. Use when the user mentions 'container security,' 'Docker security,' 'Dockerfile audit,' 'Kubernetes security,' 'K8s security,' 'pod security,' 'container hardening,' 'kubectl audit,' 'image scanning,' 'distroless,' 'rootless containers,' 'pod security policy,' 'pod security standards,' 'PSS,' 'network policy,' 'OPA Gatekeeper,' 'Kyverno,' 'runtime security,' or needs to review container or orchestration security.4---5
6# Container Audit — Docker & Kubernetes Security Review
7
8Audit container images, Dockerfiles, Helm charts, Kustomize overlays, and Kubernetes manifests for misconfiguration, excessive privilege, exposed secrets, and runtime security gaps. Distinct from `cloud-audit` (cloud-provider IAM and managed services) and `dependency-audit` (package CVEs in the application). This skill is the container/orchestration layer between them.
9
10## Scope the Audit
11
121. Inventory the surface — Dockerfiles, base images, registries, Helm charts, K8s manifests, Kustomize overlays, CI build pipelines that produce images
132. Identify the runtime — vanilla K8s, EKS, GKE, AKS, OpenShift, ECS Fargate, Cloud Run, Fly.io
143. Identify the network model — service mesh, ingress controller, default-deny vs default-allow
154. Identify the secret model — K8s Secrets (base64-only), External Secrets Operator, sealed-secrets, Vault, Doppler
16
17## Audit Checklist — Dockerfile
18
19### Base image & supply chain
20
21- Pinned by digest, not tag — `FROM node:20@sha256:abc...` not `FROM node:20` (which can move)
22- Distroless / minimal where possible — `gcr.io/distroless/nodejs20`, `alpine` (be aware of musl quirks), `chainguard/*`
23- Not using `:latest` — non-reproducible builds
24- Multi-stage builds discard build-time tooling — `FROM build AS builder` → `FROM runtime` final stage
25- Grep for: `FROM .*:latest`, `FROM .*:[0-9]+$` (tag without digest)
26
27### Build-time exposure
28
29- Secrets passed via `--build-arg` end up in image layers visible to anyone who pulls the image — use BuildKit secrets (`--mount=type=secret`) or runtime env vars instead
30- `COPY . .` ships everything in the build context — `.dockerignore` should exclude `.git`, `.env`, `node_modules`, `*.pem`, `.aws/`, `.ssh/`
31- `ADD <url>` follows redirects and disables checksum verification — prefer `RUN curl ... && sha256sum -c`
32- Grep for: `ARG .*KEY`, `ARG .*TOKEN`, `ARG .*SECRET`, `ENV .*=.*[A-Za-z0-9]{32,}`, `ADD http`
33
34### Runtime posture
35
36- Non-root user — `USER 1001` (or any non-zero UID) before `CMD`
37- No `chmod 4755` SUID binaries in the final image
38- No unnecessary shells / package managers in the final stage — distroless / FROM scratch is the strong default
39- `HEALTHCHECK` defined so orchestrator can detect unhealthy containers
40- Read-only root filesystem at runtime (set via K8s; verify nothing in the image writes outside `/tmp` or a declared volume)
41- Grep for: `USER root` (or absence of any `USER` directive), `chmod 4755`, `apt-get install.*sudo`
42
43## Audit Checklist — Kubernetes manifests
44
45### Pod security
46
47- `securityContext.runAsNonRoot: true` and `runAsUser` set to a non-zero UID
48- `securityContext.allowPrivilegeEscalation: false`
49- `securityContext.readOnlyRootFilesystem: true` with explicit `emptyDir` mounts where the app needs to write
50- `securityContext.capabilities.drop: ["ALL"]` then add only what's needed
51- `securityContext.privileged` is never `true` in app workloads (Falco, kube-proxy, some CSI drivers are the rare legit exceptions)
52- `hostNetwork`, `hostPID`, `hostIPC` all `false` — yes on these is "container can see / talk to the node"
53- `hostPath` volumes — every one is a node-escape risk; review case by case
54- Grep for: `privileged: true`, `runAsUser: 0`, `hostNetwork: true`, `hostPath:`
55
56### Pod Security Standards (PSS) / admission
57
58- Cluster enforces `restricted` profile via PSS admission, or equivalent via OPA Gatekeeper / Kyverno
59- Pod Security Policies (deprecated since 1.21, removed in 1.25) are NOT what's enforcing this — confirm a current admission controller
60- No workloads in the `kube-system` namespace running app code
61
62### Network
63
64- `NetworkPolicy` exists for every namespace running app workloads — default-deny ingress AND egress, then allow specific pods
65- Missing NetworkPolicy = every pod can talk to every other pod on every port, including kube-apiserver and metadata service
66- Service mesh (Istio, Linkerd) mTLS in STRICT mode for sensitive namespaces, not PERMISSIVE
67- Ingress controllers terminate TLS properly; backend `tls.crt` / `tls.key` in K8s Secrets rotate
68
69### Secrets
70
71- K8s Secrets are base64-encoded, NOT encrypted — by default they're plain bytes in etcd
72- etcd encryption at rest enabled — `--encryption-provider-config` on kube-apiserver
73- Workloads consume secrets via projected volumes, not environment variables (env vars leak via `/proc/<pid>/environ`, error reports, crash dumps)
74- External Secrets Operator / Vault / sealed-secrets bridge so the Git repo never contains plaintext
75- Grep for: `kind: Secret` in Git with `data:` fields (base64-encoded values committed)
76
77### RBAC
78
79- No `ClusterRole` with `*` verbs on `*` resources except `cluster-admin` (audit who's bound to it)
80- `ServiceAccount` per workload, not shared "default" SA
81- `automountServiceAccountToken: false` on workloads that don't need API access
82- Bindings of `system:authenticated` group are visible to every legitimate workload — almost always wrong
83- Grep for: `verbs: ["*"]`, `resources: ["*"]`, `apiGroups: ["*"]`, `system:authenticated`
84
85### Resource limits
86
87- Every container has `resources.requests` and `resources.limits` set — missing limits = noisy neighbor + DoS surface (one pod can starve the node)
88- `LimitRange` per namespace as a backstop
89- `ResourceQuota` per namespace prevents tenant-vs-tenant resource exhaustion
90
91### Image policy
92
93- `imagePullPolicy: Always` for `:latest` (you shouldn't use :latest, but if you do) — otherwise the node caches stale images
94- Cluster-level policy that all images come from approved registries (your own + a small allow-list); enforced via Gatekeeper / Kyverno / image-policy-webhook
95- Image signature verification — cosign + sigstore policy controller, or Notary v2
96
97## Audit Checklist — runtime
98
99- Image scanning in CI — `trivy image`, `grype`, `docker scout cves`. Must run on every build; advisories should not block but should surface
100- Runtime detection — Falco / Tracee / Tetragon catches "shell spawned in a pod that has never opened a shell" patterns
101- Audit logs enabled — kube-apiserver audit log captures `exec`, `attach`, `port-forward` events for incident response
102- `kubectl exec` access tracked — not free for any cluster-admin to silently shell into prod
103
104## Useful one-liners
105
106```bash
107# All Dockerfiles in the repo + their first FROM line
108git ls-files | grep -E '(^|/)Dockerfile(\.|$)' | xargs -I{} sh -c 'echo "==> {}"; grep ^FROM "{}"'
109
110# Manifests missing securityContext
111grep -rL "securityContext" --include="*.yaml" --include="*.yml" .
112
113# Manifests with privileged containers
114grep -rln "privileged: *true" --include="*.yaml" --include="*.yml" .
115
116# Manifests with hostPath volumes
117grep -rln "hostPath:" --include="*.yaml" --include="*.yml" .
118
119# Secrets in Git (base64-encoded but readable)
120grep -rln "kind: *Secret" --include="*.yaml" --include="*.yml" . | xargs grep -l "^data:"
121
122# Image scan (Trivy)
123trivy image --severity HIGH,CRITICAL --exit-code 0 <image>
124
125# Manifest scan (Trivy)
126trivy config --severity HIGH,CRITICAL .
127
128# Cluster posture (kube-bench, run inside the cluster)
129kube-bench run --targets master,node,policies
130```
131
132## Verify Fixes at Runtime
133
134- `runAsNonRoot: true` — verify the pod restarts cleanly and stays Running; if the image's `ENTRYPOINT` calls `chown` it'll crashloop
135- NetworkPolicy default-deny — verify legitimate traffic still works (run an in-cluster `kubectl run -it --rm debug ... curl`); silent partial outages are common after default-deny rollout
136- `readOnlyRootFilesystem: true` — verify the app doesn't write outside declared `emptyDir` mounts; log writes, PID files, and tmp files are common breakers
137- Image-policy enforcement — try to deploy an unsigned / off-list image; verify admission rejects it
138
139## Report Format
140
141```markdown
142# Container Security Audit
143## Target: [cluster name / image registry / repo path]
144## Date: [date]
145
146### Summary
147- Dockerfiles audited: N
148- Manifests audited: N
149- Cluster posture checks: pass / fail counts
150
151### Findings
152| ID | Severity | Category | Location | Issue |
153|----|----------|----------|----------|-------|
154
155### Per-finding detail
156#### [SEVERITY] [Title]
157**File:** `path/to/manifest.yaml:42`
158**Category:** Dockerfile | Pod security | RBAC | NetworkPolicy | Secrets | Resource limits | Image policy | Runtime
159
160**Description:** [what the issue is]
161
162**Vulnerable config:**
163```yaml
164[snippet]
165```
166
167**Remediation:**
168```yaml
169[fixed snippet]
170```
171
172**Verification:** [observed behavior proving the fix holds]
173```
174
175Disposition rule (Fixed / Deferred / Accepted Risk) matches `owasp-audit`.
176
177## Boundaries
178
179- Only audit clusters and registries the user provides or has authorization for
180- Never `kubectl delete` or modify cluster state during an audit — read-only operations only (`get`, `describe`, `auth can-i`)
181- For runtime evidence, prefer non-disruptive checks (a `kubectl run -it --rm` ephemeral debug pod) over modifying running workloads
182- Refuse cluster-takeover scenarios — escalating from a found weakness to a full pivot is exploitation, not audit
183- Flag low-confidence findings as "Potential" rather than confirmed
184
185## References
186
187- CIS Docker Benchmark
188- CIS Kubernetes Benchmark
189- NSA/CISA Kubernetes Hardening Guide
190- Pod Security Standards (PSS) — restricted, baseline, privileged
191- OWASP Docker Security Cheat Sheet
192- OWASP Kubernetes Security Cheat Sheet
193- MITRE ATT&CK for Containers