Skip to content

Docker Security Audit

CarterPerez-dev edited this page Feb 11, 2026 · 1 revision

Docker Security Audit

Go-based Docker environment security scanner validating against CIS Docker Benchmark.

Overview

docksec is a CLI tool that scans Docker environments for security misconfigurations. It analyzes running containers, daemon settings, images, Dockerfiles, and docker-compose files against the CIS Docker Benchmark v1.6.0, detecting issues like privileged containers, dangerous capabilities, Docker socket mounts, and hardcoded secrets.

Status: Complete | Difficulty: Intermediate

Tech Stack

Technology Version Purpose
Go 1.23+ Core language
Docker SDK - Container/image/daemon introspection
Cobra - CLI framework
moby/buildkit - Dockerfile AST parsing
errgroup - Concurrent scanning

Output Formats

Format Purpose
Terminal Human-readable colored output
JSON Structured data for automation
SARIF 2.1.0 GitHub Security tab integration
JUnit XML CI/CD pipeline integration

Features

Security Scanners

Scanner Target Checks
Container Running containers Privileged mode, capabilities, mounts, namespaces, security profiles, resource limits
Daemon Docker daemon Insecure registries, ICC, user namespaces, experimental features
Image Local images USER instruction, secrets in history, base image tags
Dockerfile Build files USER instruction, ADD vs COPY, secrets in ENV/ARG, HEALTHCHECK
Compose docker-compose.yml Same as container checks for service definitions

Advanced Features

  • 41 Linux capabilities mapped with risk levels
  • 200+ sensitive host path detection
  • 80+ secret patterns with Shannon entropy analysis
  • CIS Benchmark control mapping with scored/unscored distinction
  • Severity filtering (INFO through CRITICAL)
  • CI/CD fail-on threshold (--fail-on medium)
  • Concurrent scanning with rate limiting

Architecture

cmd/docksec/main.go (Cobra CLI)
    ↓
internal/scanner/scanner.go (Orchestration)
    ↓ errgroup + rate limiter
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Container β”‚  Daemon  β”‚  Image   β”‚ Dockerfile β”‚  Compose  β”‚
β”‚Analyzer  β”‚ Analyzer β”‚ Analyzer β”‚  Analyzer  β”‚ Analyzer  β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
     β”‚          β”‚          β”‚           β”‚            β”‚
     β–Ό          β–Ό          β–Ό           β–Ό            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Rules Engine                          β”‚
β”‚  capabilities.go | paths.go | secrets.go                β”‚
β”‚  (41 caps)       | (200+ paths) | (80+ patterns)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              CIS Benchmark Registry                      β”‚
β”‚  benchmark/controls.go (100+ controls)                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Terminal β”‚   JSON   β”‚  SARIF   β”‚  JUnit   β”‚
β”‚ Reporter β”‚ Reporter β”‚ Reporter β”‚ Reporter β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

cd PROJECTS/intermediate/docker-security-audit

# Build
go build -o docksec ./cmd/docksec

# Scan all running containers
./docksec scan

# Scan specific targets
./docksec scan --target containers
./docksec scan --target daemon
./docksec scan --target images

# Scan a Dockerfile
./docksec scan --file Dockerfile

# Scan docker-compose
./docksec scan --file docker-compose.yml

# JSON output for automation
./docksec scan --output json --output-file results.json

# SARIF for GitHub Security
./docksec scan --output sarif --output-file results.sarif

# Fail CI on findings
./docksec scan --fail-on medium

Project Structure

docker-security-audit/
β”œβ”€β”€ cmd/docksec/
β”‚   └── main.go              # CLI entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ analyzer/            # Security check implementations
β”‚   β”‚   β”œβ”€β”€ container.go     # Running container checks
β”‚   β”‚   β”œβ”€β”€ daemon.go        # Daemon config checks
β”‚   β”‚   β”œβ”€β”€ image.go         # Image metadata checks
β”‚   β”‚   β”œβ”€β”€ dockerfile.go    # Dockerfile static analysis
β”‚   β”‚   └── compose.go       # docker-compose checks
β”‚   β”œβ”€β”€ benchmark/
β”‚   β”‚   └── controls.go      # CIS Docker Benchmark v1.6.0
β”‚   β”œβ”€β”€ config/              # Runtime configuration
β”‚   β”œβ”€β”€ docker/              # Docker SDK client wrapper
β”‚   β”œβ”€β”€ finding/             # Finding data model
β”‚   β”œβ”€β”€ proc/                # Linux /proc inspection
β”‚   β”œβ”€β”€ report/              # Output formatters
β”‚   β”œβ”€β”€ rules/               # Security rule data
β”‚   └── scanner/             # Scan orchestration
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ go.mod
└── go.sum

Development

# Run tests
go test ./...

# Build
go build -o docksec ./cmd/docksec

# Build with version info
go build -ldflags "-X main.version=1.0.0" -o docksec ./cmd/docksec

Source Code

View on GitHub

Clone this wiki locally