CINC Auditor Sidecar Container Approach¶
This document outlines an alternative approach for container scanning using a CINC Auditor sidecar container. This approach is particularly useful for scanning distroless containers and can be an alternative to the ephemeral container approach.
Overview¶
The sidecar container approach involves deploying a CINC Auditor container alongside the target container within the same pod. This allows the CINC Auditor container to access the target container's filesystem through the shared process namespace.
flowchart TD
A[Start] --> B[Deploy Pod with Sidecar]
subgraph "Target Pod"
C1[Target Container]
C2[CINC Auditor Sidecar]
end
B --> D[Mount Shared Volume]
D --> E[Share Process Namespace]
E --> F[Run CINC Auditor in Sidecar]
F --> G[Access Target Filesystem via /proc]
G --> H[Execute Compliance Controls]
H --> I[Write Results to Shared Volume]
I --> J[Container or Scheduler Retrieves Results]
J --> K[Generate Reports]
K --> L[Validate Against Thresholds]
L --> M[End]
C1 --- C2
style A fill:#f9f,stroke:#333,stroke-width:2px
style C1 fill:#fbb,stroke:#333,stroke-width:2px
style C2 fill:#bbf,stroke:#333,stroke-width:2px
style F fill:#bbf,stroke:#333,stroke-width:2px
style L fill:#bfb,stroke:#333,stroke-width:2px
style M fill:#f9f,stroke:#333,stroke-width:2px
Key Components¶
- Target Container: The container to be scanned, which could be a regular container or a distroless container.
- CINC Auditor Sidecar: A container with CINC Auditor pre-installed, deployed in the same pod.
- Shared Process Namespace: Enables the sidecar to access the target container's filesystem through /proc.
- Shared Volume: Optional component to make it easier to retrieve scan results.
Implementation¶
Prerequisites¶
- Kubernetes cluster with support for shared process namespaces (v1.17+)
- RBAC permissions to create pods with shared process namespaces
- A CINC Auditor container image
Pod Definition¶
Retrieving Results¶
Results can be retrieved in several ways:
- Kubernetes API: Retrieve the results from the shared volume using the API
- kubectl cp: Copy results from the pod to the local filesystem
- Result Collection Container: Add a third container to the pod that processes and uploads the results
Example:
Advantages Over Other Approaches¶
- No Modifications to Train-k8s-container Plugin: Works with standard CINC Auditor installations.
- Deployed Alongside Application: Can be included in application deployment pipelines.
- Works with Any Container Type: Effective for both standard and distroless containers.
- No Need for Ephemeral Containers: Works with older Kubernetes clusters.
- Simpler Implementation: Requires less custom code than the transport plugin modification approach.
Limitations¶
- Pod Modification Required: The target pod must be defined with the sidecar and shared process namespace.
- Security Implications: Sharing process namespaces has security implications that should be considered.
- Not Suitable for Existing Pods: The approach requires creating a new pod with the sidecar, not modifying existing pods.
- More Resource Intensive: Running an additional container consumes more resources than other approaches.
Example Implementation¶
Step 1: Create a ConfigMap with InSpec Profiles¶
Step 2: Deploy the Pod with Sidecar¶
Step 3: Wait for the Scan to Complete¶
Step 4: Retrieve and Process Results¶
CI/CD Integration¶
For CI/CD environments, the sidecar approach can be integrated as follows:
- Build Stage: Build and push the application container.
- Test Stage: Deploy the application with the CINC Auditor sidecar.
- Scan Stage: Wait for the scan to complete and retrieve results.
- Validation Stage: Process results against thresholds.
- Cleanup Stage: Remove the test pod.
Example GitLab CI configuration:
Security Considerations¶
When implementing the sidecar container approach, consider the following security implications:
- Shared Process Namespace: All containers in the pod can see each other's processes, which could be a security concern.
- Temporary Deployments: For production environments, consider using this approach only for temporary test deployments.
- RBAC Restrictions: Implement strict RBAC to limit which users/systems can deploy pods with shared process namespaces.
- Resource Isolation: Ensure the sidecar container has appropriate resource limits.
Future Enhancements¶
Potential improvements to this approach:
- Automated Sidecar Injection: Use a mutating webhook to automatically inject the scanner sidecar.
- Results Aggregation: Implement a results collector that aggregates results from multiple scanned pods.
- Optimized CINC Image: Create a minimal CINC Auditor image specifically designed for sidecars.
- Integration with Helm: Add support for this approach in our Helm charts.