Distroless Container Workflow¶
This document details the workflow for scanning distroless containers, which are minimal containers without a shell or common utilities.
Workflow Overview¶
The distroless container workflow uses a debug container approach to access containers that lack a shell or common utilities. It employs ephemeral debug containers with chroot to scan the target container's filesystem.
Detailed Workflow Steps¶
1. Setup Phase¶
flowchart TD
A[Start Setup] --> B[Identify Distroless Target Container]
B --> C[Create Service Account]
C --> D[Apply Extended RBAC]
D --> E[Generate Short-lived Token]
E --> F[Create Restricted Kubeconfig]
F --> G[Setup Complete]
style A fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style G fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
Setup Tasks¶
- Identify Target Container:
- Namespace, pod name, and container name are identified
- Container status verified to ensure it's running
-
Container verified as distroless or minimal
-
Create Service Account:
- Temporary service account created in target namespace
-
Account is marked for cleanup after scan completion
-
Apply Extended RBAC:
- Role created with permissions for:
pods/exec
permission for target podpods/ephemeralcontainers
permission for debug containerpods
GET permission for target pod
-
RoleBinding created to link service account to role
-
Generate Token:
- Short-lived token generated for service account
-
Token expiration set to minimal required time
-
Create Kubeconfig:
- Restricted kubeconfig file created with token
- File permissions set to restrict access
2. Debug Container Deployment Phase¶
flowchart TD
A[Start Debug Deployment] --> B[Create Debug Container Spec]
B --> C[Apply Debug Container to Target Pod]
C --> D[Wait for Debug Container Ready]
D --> E[Verify Debug Container Access]
E --> F[Debug Container Ready]
style A fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style F fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
Debug Container Tasks¶
- Create Debug Container:
-
Debug container specification created with:
- CINC Auditor image
- Target process namespace sharing
- Required security context
-
Apply Debug Container:
- Debug container added to target pod
-
Container configured to access target filesystem
-
Wait for Readiness:
- Debug container availability checked
- Connection tested
3. Scanning Phase¶
flowchart TD
A[Start Scanning] --> B[Initialize CINC Auditor in Debug Container]
B --> C[Chroot to Target Container Filesystem]
C --> D[Execute Compliance Profile]
D --> E[Collect Scan Results]
E --> F[Export Results from Debug Container]
F --> G[Scanning Complete]
style A fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style D fill:#217645,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style G fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
Scanning Tasks¶
- Initialize CINC Auditor:
- CINC Auditor (InSpec) initialized in debug container
-
Scanner configured with appropriate profile
-
Chroot to Target:
-
Target container filesystem accessed via:
- Process filesystem (
/proc/<pid>/root
) - Or bind-mounted directory
- Process filesystem (
-
Execute Profile:
- Compliance profile run against target filesystem
-
Profile execution constrained to target context
-
Collect Results:
- Scan results collected in structured JSON format
-
Results stored in debug container
-
Export Results:
- Results exported from debug container
- Results saved for processing
4. Results Processing Phase¶
flowchart TD
A[Start Processing] --> B[Format Raw Results]
B --> C[Generate JSON Report]
C --> D[Process with SAF CLI]
D --> E[Apply Threshold Validation]
E --> F{Thresholds Met?}
F -->|Yes| G[Mark as Passed]
F -->|No| H[Mark as Failed]
G --> I[Processing Complete]
H --> I
style A fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style D fill:#217645,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style E fill:#217645,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style F fill:#DD6100,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style G fill:#217645,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style H fill:#DD6100,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style I fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
Processing Tasks¶
- Format Results:
- Raw scan results formatted for readability
-
Results organized by control
-
Generate Reports:
- JSON report generated with full scan details
-
Additional report formats created as needed
-
Process with SAF CLI:
- MITRE SAF CLI processes scan results
-
Results evaluated against compliance standards
-
Threshold Validation:
- Results compared to configured thresholds
- Pass/fail status determined
5. Cleanup Phase¶
flowchart TD
A[Start Cleanup] --> B[Remove Debug Container]
B --> C[Delete Kubeconfig]
C --> D[Delete Service Account]
D --> E[Delete Role and RoleBinding]
E --> F[Verify Resource Removal]
F --> G[Cleanup Complete]
style A fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
style G fill:#505050,stroke:#FFFFFF,stroke-width:2px,color:#FFFFFF
Cleanup Tasks¶
- Remove Debug Container:
- Debug container removed from target pod
-
Removal verified
-
Delete Kubeconfig:
- Temporary kubeconfig file securely deleted
-
File permissions verified during deletion
-
Delete Kubernetes Resources:
- Service account removed
- Role and RoleBinding removed
-
Any other temporary resources removed
-
Verify Cleanup:
- Resource deletion confirmed
- No leftover resources remain
Implementation Details¶
The distroless container workflow is implemented in the scan-distroless-container.sh
script with the following parameters:
Required Parameters¶
namespace
: Kubernetes namespace containing the target containerpod-name
: Name of the pod containing the target containercontainer-name
: Name of the target containerprofile-path
: Path to the InSpec profile to run
Optional Parameters¶
threshold_file
: Path to threshold configuration file for validation
Kubernetes Version Requirements¶
This workflow requires:
- Kubernetes v1.16+ for ephemeral container support
- Feature gate
EphemeralContainers=true
enabled in the cluster
Error Handling¶
The workflow includes specialized error handling for distroless containers:
- Feature Detection: Checks for ephemeral container support
- Alternative Fallbacks: Can use other methods if ephemeral containers unavailable
- Filesystem Access: Validates access to target filesystem
- Resource Cleanup: Ensures debug containers are removed even after failures
Integration with CI/CD¶
For CI/CD integration, the workflow can be adapted to run as part of:
- GitHub Actions workflows with special ephemeral container permissions
- GitLab CI pipelines with extended RBAC
- Other CI/CD systems with appropriate configuration
See CI/CD Integration for Distroless Containers for specific integration examples.