performing-container-image-hardening

Harden container images with multi-stage builds and CIS Docker Benchmark checks.

Updated Jan 29, 2024
One-click install
npx skills add https://github.com/riandeoliveira/aspnet-template --skill performing-container-image-hardening
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: performing-container-image-hardening
Source: https://github.com/riandeoliveira/aspnet-template/tree/main/.claude/skills/performing-container-image-hardening
Command: npx skills add https://github.com/riandeoliveira/aspnet-template --skill performing-container-image-hardening

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires argparse, json, os, subprocess, sys, datetime, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

It reduces security risk in production container images by minimizing attack surface, removing unnecessary components, and enforcing least-privilege and baseline CIS configuration controls.

Core Features & Use Cases

  • Multi-stage builds for smaller, safer images: Builds dependencies in a dedicated builder stage and copies only runtime artifacts into a minimal production stage.
  • Hardened runtime posture (non-root, least privilege, safer filesystem): Creates non-root users, drops Linux capabilities, and supports read-only root filesystem patterns (including Kubernetes securityContext examples).
  • CIS Docker Benchmark-aligned validation: Verifies vulnerabilities and misconfiguration issues using tools like Trivy and Dockle, and checks Dockerfile anti-patterns (e.g., pinned digests, avoiding secrets, and discouraging risky commands).
  • Use Case: When migrating from “fat” base images (e.g., full Python/Ubuntu) to slim/distroless variants, this helps cut image size and reduce CVE exposure while improving hardening consistency across services.

Quick Start

Run the provided agent to audit a hardened image by executing: python scripts/agent.py --image your-image:tag --dockerfile path/to/Dockerfile --output report.json

Frequently Asked Questions about performing-container-image-hardening

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I harden a Docker image to align with the CIS Docker Benchmark?

To harden a Docker image for CIS Docker Benchmark alignment, use multi-stage builds with minimal base images, enforce non-root execution, apply read-only filesystem patterns, and run validation checks using tools like Trivy and Dockle to catch misconfigurations.

Can I use Trivy and Dockle to validate non-root container hardening during CI/CD?

Yes, you can validate non-root container hardening during CI/CD by running vulnerability scanning with Trivy and misconfiguration checks with Dockle to verify dropped Linux capabilities, pinned base images, and the absence of risky Dockerfile commands.

What is the best way to reduce CVE exposure when migrating from fat base images to distroless variants?

The best way to reduce CVE exposure when migrating to distroless variants is using multi-stage builds to copy only runtime artifacts into a minimal production stage, removing unnecessary components and enforcing least-privilege configurations.

Does this container hardening approach support read-only filesystem patterns for Kubernetes securityContext?

Yes, container hardening supports read-only filesystem patterns by creating non-root users and dropping Linux capabilities, including examples for configuring Kubernetes securityContext to enforce least-privilege runtime posture in production.

Why should I pin Docker image digests instead of using mutable tags in production builds?

Pinning Docker image digests instead of mutable tags ensures reproducible builds and prevents supply chain attacks by locking dependencies to specific cryptographic hashes, satisfying CIS Docker Benchmark static checks for common security anti-patterns.

How do I audit a hardened container image for security anti-patterns in a Dockerfile?

Audit a hardened container image for security anti-patterns by executing the provided Python agent script with your image tag and Dockerfile path, which generates a JSON report detailing vulnerability scans and baseline CIS configuration checks.