10 Best Container Hardening Tools by Layer

10 open source container hardening tools by layer: distroless, SlimToolkit, Hadolint, Docker Bench, kube-bench, seccomp, Kyverno, gVisor and Kata.

Dec 22, 2025 - 18:09
Nov 7, 2026 - 11:16
 0  67
10 Best Container Hardening Tools by Layer

Container hardening tools shrink what an attacker can reach inside a running container. They strip unneeded packages from images, lint Dockerfiles, audit hosts and clusters against CIS Benchmarks, restrict system calls, block risky pod settings at admission, and add kernel isolation. Scanners find known CVEs; hardening tools remove the places those CVEs live.

This guide covers ten open source tools, sorted by the layer they harden: the image, the build file, the host, the cluster, the kernel interface and the runtime. It is part of our container security tools overview, which covers scanning and runtime detection products. If you want the rules first and the tools second, read the 10 golden rules of Docker container hardening.

Key takeaways

  • Hardening is about reducing attack surface and privilege. Vulnerability scanning is a separate job, covered in our image scanning tools guide.
  • Start at the image: a distroless or minimized image removes shells and package managers that most exploits rely on.
  • Hadolint catches root users and unpinned tags before an image is ever built.
  • Docker Bench for Security and kube-bench turn the CIS Docker and CIS Kubernetes Benchmarks into repeatable checks.
  • Seccomp, AppArmor and SELinux profiles limit what a compromised process can ask the kernel to do. The Security Profiles Operator manages them as Kubernetes objects.
  • Kyverno and the built-in Pod Security Admission stop privileged or root pods from being scheduled at all.
  • gVisor and Kata Containers add a second isolation boundary for untrusted or multi-tenant workloads.

Hardening vs scanning: what each tool class does

Teams often buy a scanner and call the job done. A scanner tells you that openssl in your image has a known CVE. A hardening tool asks why openssl, bash, apt and curl are in a container that only runs a Go binary. The two work together, but the questions are different, and the second one lowers your CVE count for good instead of until next week's advisory.

LayerHardening questionTools in this list
Base imageWhat is in the image that the app does not need?Distroless, SlimToolkit
Build fileDoes the Dockerfile run as root or pull floating tags?Hadolint
Docker hostIs the daemon and host configured to CIS guidance?Docker Bench for Security
Kubernetes nodes and control planeDoes the cluster meet the CIS Kubernetes Benchmark?kube-bench
Kernel interfaceWhich syscalls and files may the process touch?Security Profiles Operator
AdmissionCan someone deploy a privileged pod?Pod Security Admission, Kyverno
Runtime isolationWhat if the container escapes to the kernel?gVisor, Kata Containers

1. Distroless images

Google's distroless images contain your application and its runtime dependencies, and nothing else. There is no shell, no package manager and no coreutils. The project publishes images built on Debian 13, from static-debian13 (around 2 MiB, for statically linked binaries) up to language images such as python3-debian13, java21-debian13 and nodejs24-debian13.

Two features matter for hardening. Every image has a nonroot tag that runs as an unprivileged user by default, and every image is signed with cosign using keyless signing, so you can verify it before use. The debug tags add a busybox shell for troubleshooting; keep those out of production.

FROM golang:1.24 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app ./cmd/server

FROM gcr.io/distroless/static-debian13:nonroot
COPY --from=build /app /app
ENTRYPOINT ["/app"]

Use it when you control the build and can use a multi-stage Dockerfile. Commercial hardened image catalogs (Chainguard, Docker Hardened Images, Red Hat UBI minimal) follow the same idea and add vendor support.

2. SlimToolkit (formerly DockerSlim)

SlimToolkit minimizes an existing image without asking you to rewrite the Dockerfile. Its slim build command runs the container, watches which files the application actually opens, and produces a smaller image that contains only those files. The same run can generate seccomp and AppArmor profiles from the observed behaviour. slim xray does static analysis and reverse engineers a Dockerfile from an image, and slim lint checks Dockerfile instructions.

The project is Apache 2.0 licensed and is a CNCF Sandbox project. The catch is test coverage: if your probe run never exercises a code path, the files for that path can be removed. Run your integration tests against the slimmed image before promoting it.

slim build --target myorg/api:1.4.2 --tag myorg/api:1.4.2-slim
slim xray --target myorg/api:1.4.2

3. Hadolint

Hadolint is a Dockerfile linter. It parses the Dockerfile into a syntax tree, checks it against best practice rules, and runs ShellCheck over the shell inside RUN instructions. Two rules map straight to hardening: DL3002 warns when the last USER is root, and DL3007 warns when you use the latest tag instead of a pinned version.

docker run --rm -i hadolint/hadolint < Dockerfile

Put it in the first stage of CI so a root image fails in seconds instead of after a ten minute build. When a rule truly does not apply, ignore it inline with a reason so reviewers can see the decision:

# hadolint ignore=DL3008 # versions pinned by the base image digest
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates

Our Dockerfile mistakes guide explains the build problems behind many Hadolint rules.

4. Docker Bench for Security

Docker Bench for Security is a shell script from Docker that checks a Docker host and its running containers against the CIS Docker Benchmark (v1.6.0 at the time of writing). Checks are named after the benchmark sections, for example check_2_6, so a failed line points you to the exact recommendation.

git clone https://github.com/docker/docker-bench-security.git
cd docker-bench-security
sudo sh docker-bench-security.sh -l /var/log/docker-bench.log

The README notes that the prebuilt image on Docker Hub is outdated, so build it yourself if you want to run it as a container. Use -c to run selected checks and -e to exclude ones you have formally accepted. It suits standalone Docker hosts and build agents; for Kubernetes nodes, use kube-bench.

5. kube-bench

kube-bench, from Aqua Security, runs the CIS Kubernetes Benchmark against control plane and worker nodes. Tests are defined in YAML, and the tool picks a test set based on the Kubernetes version it finds. It ships Job manifests for generic clusters and for managed services such as EKS, GKE and AKS, where you only control the worker nodes.

kubectl apply -f job.yaml
kubectl get pods
kubectl logs <kube-bench-pod-name>

The pod needs the host PID namespace and read access to host configuration directories, so run it in a dedicated namespace and delete it afterwards. Pair the report with our Kubernetes cluster hardening steps to fix the failures in a sensible order.

6. Security Profiles Operator

Seccomp, AppArmor and SELinux are kernel features, and writing profiles by hand is slow. The Security Profiles Operator, a Kubernetes SIG project, manages all three as custom resources and distributes them to nodes. It can also record a profile from a running workload: seccomp recording works from audit logs or eBPF, SELinux from audit logs, and AppArmor from eBPF.

A sensible path is to start every workload on the runtime's default seccomp profile, then record a tighter profile for internet facing services and apply it through the pod's securityContext:

securityContext:
  seccompProfile:
    type: Localhost
    localhostProfile: operator/my-namespace/api-profile.json

The exact localhostProfile path depends on how the operator stores profiles on your nodes; check the operator's status output for the path it reports.

7. Pod Security Admission

Pod Security Admission is built into Kubernetes and enforces the three Pod Security Standards: Privileged, Baseline and Restricted. Restricted requires runAsNonRoot: true, allowPrivilegeEscalation: false, dropping all capabilities (only NET_BIND_SERVICE may be added back) and a seccomp profile of RuntimeDefault or Localhost.

kubectl label namespace payments \
  pod-security.kubernetes.io/warn=restricted \
  pod-security.kubernetes.io/audit=restricted
# after fixing warnings:
kubectl label namespace payments pod-security.kubernetes.io/enforce=restricted

It costs nothing to turn on, which is why it sits in this list next to the add-on tools. Its limit is that it only knows those three levels. For custom rules, such as allowed registries, use a policy engine.

8. Kyverno

Kyverno is a policy engine that writes policies as Kubernetes resources, so platform teams do not need to learn a new language. For hardening, it can reject pods from unapproved registries, require resource limits, add a default securityContext, and verify image signatures made with Sigstore or Notary before admission.

Check the docs for the version you install. Current Kyverno documentation lists CEL based types such as ValidatingPolicy, MutatingPolicy and ImageValidatingPolicy, and marks the older ClusterPolicy as deprecated, with a migration guide. Our post on where admission controllers enforce policy shows how Kyverno and Pod Security Admission fit together.

9. gVisor

gVisor is an application kernel written in Go that runs in user space. Its OCI runtime, runsc, sits between the container and the host kernel and handles most system calls itself, so a kernel bug in the host is much harder to reach from inside the container. It works with Docker, containerd and Kubernetes, where you select it per pod with a RuntimeClass.

apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
  name: gvisor
handler: runsc
---
apiVersion: v1
kind: Pod
metadata:
  name: untrusted-job
spec:
  runtimeClassName: gvisor
  containers:
  - name: job
    image: myorg/untrusted:2.0.1

The trade-off is overhead on syscall heavy workloads and some compatibility gaps, so use it for untrusted code, CI runners or customer supplied plugins rather than for every pod.

10. Kata Containers

Kata Containers is an open source container runtime that runs each pod inside a lightweight virtual machine, giving it its own kernel. It is stewarded by the OpenInfra Foundation. Like gVisor, it plugs into Kubernetes through a RuntimeClass. The difference is the boundary: gVisor intercepts syscalls in user space, while Kata relies on hardware virtualization, which requires nested virtualization or bare metal nodes.

Pick Kata when you need VM grade isolation between tenants and can provide the hardware. Our container runtime comparison covers how these runtimes sit beside containerd and CRI-O.

How the ten tools compare

ToolLayerWhen it runsBest fit
DistrolessImageBuildNew services with multi-stage builds
SlimToolkitImageBuildExisting images you cannot rewrite
HadolintDockerfileCommit / CIEvery repository with a Dockerfile
Docker Bench for SecurityDocker hostScheduled auditStandalone hosts and build agents
kube-benchCluster nodesScheduled auditSelf-managed and managed clusters
Security Profiles OperatorKernel interfaceRuntimeInternet facing workloads
Pod Security AdmissionAdmissionDeployEvery namespace
KyvernoAdmissionDeployCustom rules and signature checks
gVisorRuntime isolationRuntimeUntrusted code, CI runners
Kata ContainersRuntime isolationRuntimeMulti-tenant, VM grade isolation

A rollout order that works

  1. Add Hadolint to CI and fix root users and floating tags.
  2. Move new services to distroless or another minimal base, and run SlimToolkit on legacy images that you cannot rebuild yet.
  3. Label every namespace with Pod Security Admission in warn and audit mode, fix the warnings, then switch to enforce=restricted where possible.
  4. Run kube-bench (or Docker Bench for standalone hosts) monthly and after upgrades; track failures like any other ticket.
  5. Add Kyverno for registry allow lists and signature verification.
  6. Record seccomp profiles for exposed services with the Security Profiles Operator.
  7. Move untrusted workloads to gVisor or Kata through a RuntimeClass.

Steps 1 to 3 cost little and remove most of the easy wins. Keep images immutable once they are hardened; our article on immutable containers explains why patching a running container undoes this work.

Common mistakes

  • Shipping the debug distroless tag to production because it was used during troubleshooting.
  • Slimming an image with a probe run that skips error paths, then finding missing files during an incident.
  • Running kube-bench once for an audit and never again, so drift after upgrades goes unseen.
  • Enforcing the Restricted level on kube-system, where some system components legitimately need privileges.
  • Treating gVisor as a substitute for patching. It narrows the kernel attack surface; it does not fix vulnerable application code.

Learn container hardening hands-on

Our CKS training covers Pod Security Admission, seccomp and AppArmor, kube-bench, RuntimeClass and supply chain checks in lab clusters. If you are earlier in the journey, start with Docker training. Both run as classroom batches in Kharadi, Pune and as live online classes across India.

Frequently asked questions

What is container hardening?

Container hardening is reducing the attack surface and privileges of a container: removing unneeded packages, running as a non-root user, dropping Linux capabilities, restricting syscalls, enforcing safe pod settings and isolating untrusted workloads from the host kernel.

Is container hardening the same as image scanning?

No. Scanning finds known CVEs in packages that are present. Hardening removes packages and privileges so there is less to scan and less to exploit. Use both: a scanner in CI and hardening tools at build, deploy and runtime.

Which container hardening tool should I start with?

Start with Hadolint in CI and Pod Security Admission in warn mode. Both are free, take minutes to enable and show you the biggest problems, such as root users and privileged pods, before you invest in runtime tools.

What is the difference between gVisor and Kata Containers?

gVisor runs a user space kernel that intercepts system calls, so it needs no virtualization hardware. Kata Containers runs each pod in a lightweight VM with its own kernel, which gives stronger isolation but needs hardware virtualization support.

Does kube-bench work on EKS, GKE and AKS?

Yes. kube-bench ships platform specific Job files for EKS, GKE and AKS. On managed services you can only check worker nodes, because the provider runs the control plane.

Are distroless images safe to debug?

Standard distroless images have no shell. Use the debug tag in a test environment, or attach an ephemeral debug container with kubectl debug in Kubernetes, rather than adding a shell to the production image.

Is SlimToolkit safe for production images?

It can be, if your probe run exercises every code path. SlimToolkit keeps only the files it sees the application use, so run your full integration tests against the slimmed image before promoting it.

References

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.