Distroless Container Basics¶
This document explains what distroless containers are, their benefits, and the challenges they present for security scanning.
What are Distroless Containers?¶
Distroless containers are minimalist container images that contain only the application and its runtime dependencies. They do not include:
- Shell
- Package managers
- Standard Linux utilities
- Debugging tools
These containers are designed for improved security by reducing the attack surface, but they present challenges for traditional container debugging and scanning approaches.
Key Characteristics of Distroless Containers¶
What's Included in Distroless Containers¶
- Application binaries and libraries: Just the executables and shared libraries needed for the application to run
- Runtime dependencies: Minimal set of files and libraries required by the runtime (e.g., Java JRE, Python interpreter)
- CA certificates: For secure network connections
- Timezone data: For correct time representation
- Non-root user: Typically configured to run as a non-privileged user
What's Explicitly Excluded¶
- Shell: No
/bin/sh
,/bin/bash
, or other shells - Package manager: No apt, dpkg, yum, etc.
- Common utilities: No ls, cat, grep, etc.
- Development tools: No compilers, debuggers, etc.
- Configuration tools: No init system or service managers
Benefits of Distroless Containers¶
- Reduced Attack Surface: Fewer components mean fewer potential vulnerabilities
- Smaller Image Size: Significantly smaller images, often 10-20% the size of standard images
- Improved Security Posture: Limited capabilities for attackers if compromised
- Immutable Infrastructure: Encourages proper CI/CD practices as containers can't be modified at runtime
- Simplified Dependency Management: Clear definition of actual runtime dependencies
- Improved Performance: Less overhead, faster startup times
Examples of Distroless Container Images¶
Google's distroless containers project provides several base images:
- distroless/static: Ultra-minimal image for statically-linked binaries
- distroless/base: Minimal base image with glibc
- distroless/java: For Java applications
- distroless/python: For Python applications
- distroless/nodejs: For Node.js applications
- distroless/cc: For C/C++ applications
The Challenge with Scanning Distroless Containers¶
The train-k8s-container transport plugin that CINC Auditor uses relies on the ability to execute commands within the target container. It typically does this by:
- Using
kubectl exec
to run commands inside the container - Assuming the presence of a shell (like
/bin/sh
) in the container - Executing tests that often rely on standard Linux utilities
In distroless containers, these requirements are not met, making traditional scanning impossible.
Common Errors When Attempting to Scan Distroless¶
When trying to scan a distroless container with the standard approach, you'll see errors like:
Or when using InSpec directly:
Distroless Container Detection¶
Detecting distroless containers can be done by:
- Attempting to execute a simple command and checking for failure
- Testing for the presence of common shells
- Looking at image metadata if available
Example detection code:
Common Distroless Scanning Approaches¶
There are several approaches to scanning distroless containers:
- Debug Container Approach: Using Kubernetes ephemeral containers to inspect the distroless container (our recommended interim approach)
- Sidecar Approach: Deploying sidecar containers with shared process namespace
- Static Analysis: Scanning the container image rather than the running container
- Custom Tooling: Building specialized tools for distroless containers
Base Image Influence on Scanning Approach¶
The choice of distroless base image affects the scanning approach:
Distroless Base | Key Characteristics | Scanning Considerations |
---|---|---|
Static | No libc, for statically-linked binaries | Most restricted, needs complete external access |
Base | Includes glibc but no shell | Cannot execute commands, needs external tools |
Java | JRE without shell or tools | Can analyze JVM but not execute shell commands |
Python | Python runtime without shell | Can potentially use Python for some inspections |
Node.js | Node runtime without shell | Can potentially use Node for some inspections |
Container Security Considerations¶
Distroless containers provide security benefits:
- Attack Surface Reduction: No shell means no easy execution for attackers
- Limited Privilege Escalation: Fewer tools available if compromised
- Vulnerability Reduction: No excess packages means fewer CVEs
However, they also introduce security challenges:
- Limited Inspectability: Harder to debug and scan
- Specialized Knowledge Required: Teams need more advanced container expertise
- Special Handling in Security Tooling: Many security tools assume shell access
Recommended InSpec Resources for Distroless¶
When creating InSpec profiles for distroless containers, focus on:
- file resource: For checking file existence, permissions, content
- directory resource: For checking directory attributes
- parse_config* resources: For analyzing configuration files without commands
- packages resource: Only for language-specific package analysis (npm, pip, etc.)
- simple matchers: Resources that don't depend on command execution
Avoid resources that rely on command execution:
- command resource: Will fail without a shell
- process resource: Often depends on ps command
- service resource: Requires service management tools
- user/group resources: Often depend on commands like id, getent