Skip to main content

Validate & lint K8s manifests, Helm charts, Docker Compose, CI configs โ€” 60+ rules with beautiful reports

Project description

๐Ÿฉบ yaml-doctor

YAML Linter & Security Scanner for DevOps Engineers

Validate and lint Kubernetes manifests, Docker Compose files, GitHub Actions workflows, GitLab CI pipelines, and generic YAML with 60+ built-in rules covering security, reliability, and best practices.

PyPI version Python License: MIT Tests


โœจ Features

  • ๐Ÿ” 60+ Lint Rules โ€” Security, reliability, and best practice checks
  • ๐ŸŽฏ Auto-Detection โ€” Automatically identifies Kubernetes, Docker Compose, GitHub Actions, GitLab CI, and Helm files
  • ๐Ÿ“Š Grading System โ€” A+ to F grades with detailed scoring
  • ๐ŸŒ HTML Dashboard โ€” Beautiful dark-theme HTML reports with severity charts
  • ๐Ÿ“‹ JSON Export โ€” Machine-readable reports for CI/CD integration
  • ๐Ÿ”ง Fix Suggestions โ€” Actionable remediation for every finding
  • ๐ŸŽฎ Demo Mode โ€” Try it instantly with built-in sample files
  • ๐Ÿš€ Zero Config โ€” Works out of the box, no configuration needed

๐Ÿ“ฆ Installation

pip install yaml-doctor

๐Ÿš€ Quick Start

# Lint a single file
yaml-doctor lint deployment.yaml

# Scan a directory recursively
yaml-doctor scan ./k8s/

# Run demo with sample files
yaml-doctor demo

# Show all 60 rules
yaml-doctor rules

# Get fix suggestions
yaml-doctor fix deployment.yaml

# Export HTML dashboard
yaml-doctor scan . --html report.html

# Export JSON report
yaml-doctor lint config.yaml -j report.json

๐ŸŽฏ Supported File Types

Type Detection Rules
Kubernetes apiVersion + kind 20 rules (K8S001-K8S020)
Docker Compose services + image/build 12 rules (DC001-DC012)
GitHub Actions .github/workflows/ + on/jobs 10 rules (GHA001-GHA010)
GitLab CI .gitlab-ci.yml + stages/script 10 rules (GL001-GL010)
Helm Chart.yaml / values.yaml K8s rules applied
Generic YAML Any .yml/.yaml file 8 rules (YML001-YML008)

๐Ÿ”’ Security Rules

Kubernetes (20 rules)

Rule Severity Description
K8S001 ๐Ÿ”ด CRITICAL Container running as root
K8S004 ๐Ÿ”ด CRITICAL Privileged container
K8S002 ๐ŸŸ  HIGH Missing resource limits
K8S003 ๐ŸŸ  HIGH Missing resource requests
K8S005 ๐ŸŸ  HIGH Using :latest image tag
K8S006 ๐ŸŸ  HIGH Missing liveness probe
K8S011 ๐ŸŸ  HIGH Host network enabled
K8S012 ๐ŸŸ  HIGH Host PID enabled
K8S016 ๐ŸŸ  HIGH Secrets in environment variables
K8S007 ๐ŸŸก MEDIUM Missing readiness probe
K8S008 ๐ŸŸก MEDIUM Read-only filesystem not set
K8S013 ๐ŸŸก MEDIUM Single replica deployment
K8S014 ๐ŸŸก MEDIUM Privilege escalation allowed
K8S017 ๐ŸŸก MEDIUM Missing update strategy
K8S018 ๐ŸŸก MEDIUM Capabilities not dropped
K8S020 ๐ŸŸก MEDIUM Missing restart policy
K8S009 ๐Ÿ”ต LOW Missing recommended labels
K8S015 ๐Ÿ”ต LOW Missing PodDisruptionBudget
K8S019 ๐Ÿ”ต LOW No anti-affinity rules
K8S010 โšช INFO Missing namespace

Docker Compose (12 rules)

Rule Severity Description
DC002 ๐Ÿ”ด CRITICAL Privileged container
DC001 ๐ŸŸ  HIGH Using :latest tag
DC005 ๐ŸŸ  HIGH Secrets in environment
DC009 ๐ŸŸ  HIGH Host volume with write access
DC012 ๐ŸŸก MEDIUM Host network mode
DC003 ๐ŸŸก MEDIUM No restart policy
DC004 ๐ŸŸก MEDIUM No healthcheck defined
DC007 ๐ŸŸก MEDIUM Exposed to all interfaces
DC011 ๐ŸŸก MEDIUM No depends_on
DC006 ๐Ÿ”ต LOW No resource limits
DC010 ๐Ÿ”ต LOW No logging configuration
DC008 โšช INFO Deprecated version key

GitHub Actions (10 rules)

Rule Severity Description
GHA001 ๐Ÿ”ด CRITICAL Mutable action reference (using @main)
GHA002 ๐ŸŸ  HIGH Persist credentials enabled
GHA003 ๐ŸŸ  HIGH Secrets in run commands
GHA009 ๐ŸŸ  HIGH Script injection risk
GHA004 ๐ŸŸก MEDIUM Overly broad permissions
GHA005 ๐ŸŸก MEDIUM No job timeout
GHA006 ๐ŸŸก MEDIUM pull_request_target trigger
GHA007 ๐Ÿ”ต LOW No concurrency control
GHA008 ๐Ÿ”ต LOW Unversioned runner image
GHA010 โšช INFO Missing workflow name

GitLab CI (10 rules)

Rule Severity Description
GL001 ๐ŸŸ  HIGH Secrets in script blocks
GL007 ๐ŸŸ  HIGH allow_failure on security jobs
GL002 ๐ŸŸก MEDIUM No retry configuration
GL004 ๐ŸŸก MEDIUM Using :latest image
GL005 ๐ŸŸก MEDIUM No timeout set
GL009 ๐ŸŸก MEDIUM No rules/conditions
GL003 ๐Ÿ”ต LOW No cache defined
GL008 ๐Ÿ”ต LOW No artifacts defined
GL010 ๐Ÿ”ต LOW Missing job description
GL006 โšช INFO No stages defined

Generic YAML (8 rules)

Rule Severity Description
YML005 ๐ŸŸ  HIGH Hardcoded credentials
YML001 ๐ŸŸก MEDIUM Inconsistent indentation
YML006 ๐ŸŸก MEDIUM Duplicate keys
YML002 ๐Ÿ”ต LOW Trailing whitespace
YML003 ๐Ÿ”ต LOW Line too long (>200 chars)
YML007 ๐Ÿ”ต LOW Empty values
YML004 โšช INFO Missing document start marker
YML008 โšช INFO File too long (>1000 lines)

๐Ÿ“Š Grading System

Grade Score Description
A+ 95-100 Excellent โ€” production ready
A 85-94 Great โ€” minor improvements possible
B 75-84 Good โ€” some issues to address
C 65-74 Fair โ€” significant improvements needed
D 50-64 Poor โ€” many issues found
F 0-49 Failing โ€” critical issues present

Score deductions per finding:

  • ๐Ÿ”ด Critical: -15 points
  • ๐ŸŸ  High: -8 points
  • ๐ŸŸก Medium: -3 points
  • ๐Ÿ”ต Low: -1 point
  • โšช Info: 0 points

๐Ÿ–ฅ๏ธ CLI Commands

yaml-doctor lint <file>

Lint a single YAML file with auto-detection.

yaml-doctor lint deployment.yaml
yaml-doctor lint docker-compose.yml --html report.html
yaml-doctor lint .github/workflows/ci.yml -j report.json

yaml-doctor scan <directory>

Scan all YAML files in a directory.

yaml-doctor scan ./k8s/
yaml-doctor scan . --html dashboard.html
yaml-doctor scan ./configs --no-recursive

yaml-doctor demo

Run a demo with built-in sample files.

yaml-doctor demo
yaml-doctor demo --type kubernetes
yaml-doctor demo --type compose
yaml-doctor demo --html demo-report.html

yaml-doctor rules

Display all 60 available lint rules.

yaml-doctor rules

yaml-doctor fix <file>

Show fix suggestions for all findings.

yaml-doctor fix deployment.yaml

๐Ÿ”Œ CI/CD Integration

GitHub Actions

- name: YAML Lint
  run: |
    pip install yaml-doctor
    yaml-doctor scan . --html report.html -j report.json
    
- name: Upload Report
  uses: actions/upload-artifact@v4
  with:
    name: yaml-doctor-report
    path: report.html

GitLab CI

yaml-lint:
  stage: test
  script:
    - pip install yaml-doctor
    - yaml-doctor scan . --html report.html -j report.json
  artifacts:
    paths:
      - report.html
      - report.json

Pre-commit Hook

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: yaml-doctor
        name: yaml-doctor
        entry: yaml-doctor lint
        language: python
        types: [yaml]
        additional_dependencies: [yaml-doctor]

๐Ÿ“ Project Structure

yaml-doctor/
โ”œโ”€โ”€ yaml_doctor/
โ”‚   โ”œโ”€โ”€ __init__.py          # Package version
โ”‚   โ”œโ”€โ”€ __main__.py          # python -m support
โ”‚   โ”œโ”€โ”€ cli.py               # Click CLI commands
โ”‚   โ”œโ”€โ”€ scanner.py           # Core scanning engine
โ”‚   โ”œโ”€โ”€ models.py            # Data models & enums
โ”‚   โ”œโ”€โ”€ rules.py             # Rule registry (60 rules)
โ”‚   โ”œโ”€โ”€ utils.py             # Helper utilities
โ”‚   โ”œโ”€โ”€ demo.py              # Demo sample data
โ”‚   โ”œโ”€โ”€ analyzers/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py      # File type detection
โ”‚   โ”‚   โ”œโ”€โ”€ kubernetes.py    # 20 K8s rules
โ”‚   โ”‚   โ”œโ”€โ”€ compose.py       # 12 Docker Compose rules
โ”‚   โ”‚   โ”œโ”€โ”€ github_actions.py # 10 GitHub Actions rules
โ”‚   โ”‚   โ”œโ”€โ”€ gitlab_ci.py     # 10 GitLab CI rules
โ”‚   โ”‚   โ””โ”€โ”€ yaml_lint.py     # 8 generic YAML rules
โ”‚   โ””โ”€โ”€ output/
โ”‚       โ”œโ”€โ”€ console.py       # Rich terminal output
โ”‚       โ””โ”€โ”€ html_report.py   # HTML dashboard reports
โ”œโ”€โ”€ tests/                   # 188 tests
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md

๐Ÿงช Development

git clone https://github.com/SanjaySundarMurthy/yaml-doctor.git
cd yaml-doctor
pip install -e ".[dev]"
pytest
ruff check .

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Sanjay S โ€” GitHub ยท Email

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

yaml_doctor_cli-1.0.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

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

yaml_doctor_cli-1.0.0-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file yaml_doctor_cli-1.0.0.tar.gz.

File metadata

  • Download URL: yaml_doctor_cli-1.0.0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for yaml_doctor_cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6810d9692893c89d5ce19c136907539510ac59e0ca13842ebb21036e4b18c3bf
MD5 8b966682200cc6c9d71bc21d6de019c9
BLAKE2b-256 2bbfb9b981f41cb4e32c99e07d6db15e0b100dbaf346086497da8b385000b506

See more details on using hashes here.

File details

Details for the file yaml_doctor_cli-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for yaml_doctor_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d22c4d915e409a1b2bef7593f7bc8bf01858542b717d9546e6d4c0c7408b976
MD5 23ddacdf0e76228585708b38a975031d
BLAKE2b-256 cf46039cad81487025c49b8d6427df689dafebb70fcfba41c3cf0e108f386948

See more details on using hashes here.

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