Skip to main content

Lightweight container security auditor for Docker and Kubernetes

Project description

Container Audit

Container Audit

Lightweight container security auditor for Docker and Kubernetes

CI License: MIT PyPI Python


โœจ Features

Container Audit is a fast, lightweight security scanner that helps developers and DevSecOps teams identify misconfigurations in Docker and Kubernetes environments before they become vulnerabilities.

  • ๐Ÿณ Docker Security โ€” 14 checks covering privileged mode, capabilities, secrets, network exposure, and more
  • โ˜ธ๏ธ Kubernetes Compliance โ€” Pod Security, RBAC, NetworkPolicy, and manifest best practices
  • ๐Ÿ” Secret Detection โ€” Scan files for leaked API keys, private keys, passwords, and connection strings
  • ๐Ÿ“Š Multiple Reports โ€” Terminal (Rich), JSON, and HTML output with dark theme
  • โšก Security Score โ€” 0-100 score based on severity-weighted findings
  • ๐Ÿ”Œ CI/CD Ready โ€” Exit codes and JSON output for pipeline integration

๐Ÿš€ Quick Start

Installation

pip install container-audit

Or from source:

git clone https://github.com/HYMichellexdd/container-audit.git
cd container-audit
pip install -e ".[dev]"

Basic Usage

# Scan a running Docker container
container-audit docker my-container

# Scan a docker-compose file
container-audit compose docker-compose.yml

# Scan Kubernetes manifests
container-audit k8s ./k8s-manifests/

# Scan for secrets in source code
container-audit secrets ./src/

Output Formats

# JSON output (for CI/CD pipelines)
container-audit docker my-container -f json -o report.json

# HTML report (dark theme, great for sharing)
container-audit docker my-container -f html -o report.html

# Verbose terminal output with evidence
container-audit docker my-container -v

๐Ÿ“‹ Security Checks

Docker (14 checks)

Check Severity Description
DOCKER-001 ๐Ÿ”ด CRITICAL Privileged container detection
DOCKER-002 ๐Ÿ”ด CRITICAL Docker socket mount detection
DOCKER-003 ๐ŸŸก MEDIUM Running as root user
DOCKER-004 ๐Ÿ”ด HIGH Dangerous capabilities (SYS_ADMIN, NET_ADMIN, etc.)
DOCKER-005 ๐ŸŸก MEDIUM Ports exposed on 0.0.0.0
DOCKER-006 ๐Ÿ”ด HIGH Secrets in environment variables
DOCKER-007 ๐Ÿ”ต LOW Writable root filesystem
DOCKER-008 ๐ŸŸก MEDIUM Missing resource limits (memory/CPU/PIDs)
DOCKER-009 ๐Ÿ”ต LOW No healthcheck configured
DOCKER-010 ๐Ÿ”ต LOW AppArmor profile status
DOCKER-011 ๐Ÿ”ต LOW Seccomp profile status
DOCKER-012 ๐Ÿ”ด HIGH Host PID namespace sharing
DOCKER-013 ๐ŸŸก MEDIUM Host IPC namespace sharing
DOCKER-014 ๐Ÿ”ด HIGH Host network mode

Kubernetes

Check Severity Description
K8S-PRIV-* ๐Ÿ”ด CRITICAL Privileged containers in workloads
K8S-ROOT-* ๐ŸŸก MEDIUM Containers running as root
K8S-CAPS-* ๐Ÿ”ด HIGH Dangerous capabilities added
K8S-SA-TOKEN ๐ŸŸก MEDIUM ServiceAccount token auto-mounting
K8S-HNET ๐Ÿ”ด HIGH Host network enabled
K8S-HPID ๐Ÿ”ด HIGH Host PID namespace
K8S-HOSTPATH ๐Ÿ”ด HIGH HostPath volumes mounted
K8S-RBAC-* ๐Ÿ”ด HIGH Overprivileged RBAC rules
K8S-NS-* ๐ŸŸก MEDIUM Namespace configuration checks
K8S-ING-TLS-* ๐Ÿ”ด HIGH Ingress without TLS
K8S-NP-* ๐ŸŸก MEDIUM NetworkPolicy validation

Secrets Detection

Pattern Severity Description
API Keys ๐Ÿ”ด CRITICAL Generic API key patterns
AWS Keys ๐Ÿ”ด CRITICAL AWS access/secret keys
GitHub Tokens ๐Ÿ”ด CRITICAL GitHub PATs and tokens
Private Keys ๐Ÿ”ด CRITICAL RSA/EC/DSA private keys
Passwords ๐Ÿ”ด CRITICAL Hardcoded passwords
Connection Strings ๐Ÿ”ด CRITICAL Database/message broker URIs
JWT Tokens ๐Ÿ”ด CRITICAL JSON Web Tokens
GCP/Azure ๐Ÿ”ด CRITICAL Cloud provider credentials

๐Ÿ“Š Report Example

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Security Report โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  Container Audit Report                 โ”‚
โ”‚  Target: my-container                   โ”‚
โ”‚  Scan Type: docker                      โ”‚
โ”‚  Score: 35/100                          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           Summary                            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Severity โ”‚ Failed โ”‚ Passed โ”‚ Warnings        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ CRITICAL โ”‚      2 โ”‚      0 โ”‚               0 โ”‚
โ”‚ HIGH     โ”‚      3 โ”‚      1 โ”‚               0 โ”‚
โ”‚ MEDIUM   โ”‚      2 โ”‚      1 โ”‚               1 โ”‚
โ”‚ LOW      โ”‚      1 โ”‚      2 โ”‚               2 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Findings:
  โœ—  CRITICAL  Privileged container
       โ†’ Remove --privileged flag. Use specific capabilities instead.
  โœ—  CRITICAL  Docker socket mounted
       โ†’ Avoid mounting Docker socket.
  โœ—     HIGH  Dangerous capabilities added
       โ†’ Remove unnecessary capabilities.
  โœ“     HIGH  Host PID namespace
  โœ—   MEDIUM  Running as root
       โ†’ Set USER directive in Dockerfile.

๐Ÿ”ง CI/CD Integration

GitHub Actions

- name: Container Security Scan
  run: |
    pip install container-audit
    container-audit docker ${{ env.IMAGE }} -f json -o scan-results.json
    # Fail CI on critical findings
    container-audit docker ${{ env.IMAGE }}

GitLab CI

security_scan:
  image: python:3.12-slim
  script:
    - pip install container-audit
    - container-audit k8s ./k8s/ -f json -o report.json
  artifacts:
    reports:
      container_scanning: report.json

Exit Codes

Code Meaning
0 No critical or high findings
1 High severity findings present
2 Critical severity findings present

๐Ÿ›ก๏ธ Why Container Audit?

Feature Container Audit Trivy Grype Snyk
Docker config audit โœ… โŒ โŒ โŒ
Compose file scan โœ… โŒ โŒ โŒ
K8s manifest check โœ… โš ๏ธ Limited โŒ โš ๏ธ Limited
Secret detection โœ… โœ… โŒ โœ…
CI/CD friendly โœ… โœ… โœ… โœ…
Zero dependencies โœ… โŒ โŒ โŒ
Lightweight (<1s) โœ… โš ๏ธ โœ… โŒ

๐Ÿ“ Project Structure

container-audit/
โ”œโ”€โ”€ container_audit/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ cli.py              # CLI entry point
โ”‚   โ”œโ”€โ”€ scanner.py           # Core scanning engine
โ”‚   โ”œโ”€โ”€ utils.py             # Shared utilities
โ”‚   โ”œโ”€โ”€ checks/
โ”‚   โ”‚   โ”œโ”€โ”€ docker.py        # Docker security checks
โ”‚   โ”‚   โ”œโ”€โ”€ kubernetes.py    # K8s manifest checks
โ”‚   โ”‚   โ”œโ”€โ”€ network.py       # Network exposure checks
โ”‚   โ”‚   โ””โ”€โ”€ secrets.py       # Secret detection
โ”‚   โ””โ”€โ”€ reporters/
โ”‚       โ”œโ”€โ”€ console.py       # Rich terminal output
โ”‚       โ”œโ”€โ”€ json_out.py      # JSON report
โ”‚       โ””โ”€โ”€ html_out.py      # HTML report
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ .github/workflows/ci.yml
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-check)
  3. Commit your changes (git commit -m 'Add amazing security check')
  4. Push to the branch (git push origin feature/amazing-check)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Links


Made with โค๏ธ by HYMichellexdd

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

container_audit-0.1.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

container_audit-0.1.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file container_audit-0.1.0.tar.gz.

File metadata

  • Download URL: container_audit-0.1.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for container_audit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bdccfbfd7736d9460aaeb336846f6207ab0682329427f6d5e11447211461ea93
MD5 55cd9ba4b14a27b6feb4f4bfc2ea052a
BLAKE2b-256 38ab28c98602dfa885790a8a30c18f8f3c7f3a786c84fb58b25bd6d360dedb3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for container_audit-0.1.0.tar.gz:

Publisher: publish.yml on HYMichellelxdd/container-audit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file container_audit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: container_audit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for container_audit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dae16e302d81544c96a3af1d83ff92fd249193c744c014f1a3ccbf2c2884388a
MD5 d81538e75faf476f3e67008afc8778d8
BLAKE2b-256 4c039e7adff63d46d71f50bb29538d9f144951564c01716ec8063319f975e892

See more details on using hashes here.

Provenance

The following attestation bundles were made for container_audit-0.1.0-py3-none-any.whl:

Publisher: publish.yml on HYMichellelxdd/container-audit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page