Skip to main content

kubepolicy

PyPI version Python 3.11+ License: MIT GitHub

A fast, CI-native Kubernetes policy engine with clean UX and GitHub Security integration.

Not "just a linter"—kubepolicy evaluates your Kubernetes YAML against security, reliability, cost, and best-practice rules, with SARIF output so findings appear in the GitHub Security tab.

Features

  • Recursive YAML scanning with multi-document support
  • Parallel scanning for speed
  • 10 built-in rules (security, reliability, cost, best practice)
  • Config file (.kubepolicy.yaml) to disable rules or override severity
  • Output formats: table (default), JSON, SARIF (GitHub Code Scanning)
  • Exit code control: fail CI when findings meet a severity threshold (--fail-on)

Install

From PyPI (recommended)

pip install kubepolicy

From source

git clone https://github.com/akintunero/kube-guard.git
cd kube-guard
pip install -e .

Development setup

git clone https://github.com/akintunero/kube-guard.git
cd kube-guard
pip install -e ".[dev]"
pytest tests -v

Quick start

# Scan current directory (default: table output)
kubepolicy scan ./

# JSON output
kubepolicy scan ./ --format json

# SARIF for GitHub Security tab (e.g. in CI)
kubepolicy scan ./ --format sarif > results.sarif

# Fail CI on MEDIUM or higher
kubepolicy scan ./ --fail-on MEDIUM

# List all rules
kubepolicy list-rules

# Explain a rule
kubepolicy explain SEC001

# Create sample config
kubepolicy init

Built-in rules (10)

ID Title Severity Category
SEC001 Privileged container CRITICAL security
SEC002 Missing resource limits MEDIUM security
SEC003 Use of latest tag MEDIUM security
SEC004 hostPath usage HIGH security
SEC005 Run as root HIGH security
SEC006 Allow privilege escalation HIGH security
REL001 Missing liveness probe MEDIUM reliability
REL002 Missing readiness probe MEDIUM reliability
COST001 No resource requests MEDIUM cost
BP001 Image pull policy misconfig LOW best_practice

Config file

Create .kubepolicy.yaml in your repo (or run kubepolicy init):

disable:
  - BP001

severity_overrides:
  COST001: HIGH

GitHub Security integration (SARIF)

In GitHub Actions, run kubepolicy and upload the SARIF file:

- name: Run kubepolicy
  run: kubepolicy scan ./ --format sarif > kubepolicy-results.sarif || true
- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: kubepolicy-results.sarif

Findings will appear under Security → Code scanning in your repository.

Pre-commit

Example hook (run kubepolicy on staged YAML):

# .pre-commit-hooks.yaml
- repo: local
  hooks:
    - id: kubepolicy
      name: kubepolicy scan
      entry: kubepolicy scan
      language: system
      types: [yaml]
      args: [.]

Comparison with kube-linter

kubepolicy kube-linter
SARIF / GitHub Security ✅ Native Via custom
Config file ✅ .kubepolicy.yaml ✅
Fail-on severity ✅ ✅
Parallel scan ✅ —
Python 3.11+ ✅ Go
Extensibility Rule registry Custom checks

kubepolicy is designed to be CI-first and GitHub-native, with a small, focused rule set and minimal dependencies.

Requirements

  • Python 3.11+
  • Typer, ruamel.yaml, Rich (see pyproject.toml)

Development

See CONTRIBUTING.md for guidelines on contributing to kubepolicy.

Quick start:

# Clone the repository
git clone https://github.com/akintunero/kube-guard.git
cd kube-guard

# Install in development mode with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests -v

# Run with coverage
pytest tests --cov=kubepolicy --cov-report=html

Project Status

kubepolicy is in active development. We welcome contributions, bug reports, and feature requests!

Roadmap

  • Additional security rules (network policies, RBAC, etc.)
  • Custom rule support via plugins
  • Integration with other CI/CD platforms (GitLab, Jenkins, etc.)
  • Performance optimizations for large codebases
  • Rule severity auto-tuning based on context

Changelog

See CHANGELOG.md for a list of changes and version history.

License

MIT License. See LICENSE for details.

Author

Olúmáyòwá Akinkuehinmi

Acknowledgments

Metadata

Release files for kubepolicy 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kubepolicy 1.0.0
File Size Uploaded Provenance Actions
kubepolicy-1.0.0.tar.gz 19.9 kB Without provenance Details for kubepolicy-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kubepolicy 1.0.0
File Interpreter ABI Platform Actions
kubepolicy-1.0.0-py3-none-any.whl Python 3 none any Details for kubepolicy-1.0.0-py3-none-any.whl

Total release size: 37.7 kB

Release files / kubepolicy-1.0.0.tar.gz

Download URL kubepolicy-1.0.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
645a1c0ecf3a46b4fc53a6f2ddff620faec2ffd3901337c068cb72fdb6431aa4
BLAKE2b-256 checksum
How to use checksums
95a06a8f9475f567f54e08e1672df3718a22c7a76b0df00771bd00a46204217d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / kubepolicy-1.0.0-py3-none-any.whl

Download URL kubepolicy-1.0.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
142438fbd9a1446f17bbbe2d5e4c67f95e90419a2acaa5191a3fee562cb88a77
BLAKE2b-256 checksum
How to use checksums
9a0d937681edd443c30a1482680a0c0a20764ab877c459a11a077d9c10d2ac14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for kubepolicy 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page