kube-netpol
Kubernetes NetworkPolicy Generator, Validator & Visualizer
A comprehensive CLI tool that validates existing Kubernetes NetworkPolicies, generates secure policy templates, simulates traffic flows, and visualizes network connectivity — all from your terminal.
Why kube-netpol?
Kubernetes NetworkPolicies are the firewall of your cluster — but they're notoriously easy to get wrong. One missing policyTypes field and your "deny all" policy does nothing. One empty namespaceSelector: {} and you've opened traffic from every namespace.
kube-netpol catches these mistakes before they hit production:
- 34+ validation rules covering security, correctness, and best practices
- 10 policy templates from default-deny to full microservices zero-trust
- Traffic simulation engine that evaluates flows against your policies
- Mermaid + ASCII visualization of network connectivity
- CI/CD ready with --fail-on threshold and JSON/HTML export
Installation
pip install -e .
Or directly from the repository:
git clone https://github.com/SanjaySundarMurthy/kube-netpol.git
cd kube-netpol
pip install -e .
Quick Start
Demo Mode (No Cluster Needed)
kube-netpol demo
This creates a realistic e-commerce cluster with intentional security issues and runs a full analysis — perfect for seeing what kube-netpol can do.
Scan Existing Policies
# Scan a single file
kube-netpol scan my-network-policy.yaml
# Scan a directory of manifests
kube-netpol scan ./k8s/
# Verbose mode with suggestions
kube-netpol scan ./k8s/ --verbose
# With traffic simulation
kube-netpol scan ./k8s/ --simulate
Generate Policies from Templates
# List all templates
kube-netpol templates
# Generate a default-deny-all policy
kube-netpol generate default-deny-all --namespace production
# Generate a complete microservices suite
kube-netpol generate microservices-suite --namespace ecommerce --app myshop
# Save to file
kube-netpol generate database --namespace production -o db-policy.yaml
Simulate Traffic Flows
kube-netpol simulate ./k8s/ \
--from-pod frontend --from-ns ecommerce --from-labels "app=frontend" \
--to-pod backend --to-ns ecommerce --to-labels "app=backend-api" \
--port 8080
Visualize Connections
# ASCII traffic map
kube-netpol visualize ./k8s/
# Mermaid diagram (paste into GitHub, Notion, etc.)
kube-netpol visualize ./k8s/ --format mermaid
# Save to file
kube-netpol visualize ./k8s/ --format mermaid -o diagram.md
CI/CD Integration
Use --fail-on to fail your pipeline when issues exceed a threshold:
# Fail on critical or high severity
kube-netpol scan ./k8s/ --fail-on high
# Export JSON for further processing
kube-netpol scan ./k8s/ --format json -o report.json
# Export interactive HTML dashboard
kube-netpol scan ./k8s/ --format html -o report.html
GitHub Actions Example
- name: Validate NetworkPolicies
run: |
pip install kube-netpol
kube-netpol scan ./k8s/network-policies/ --fail-on high
Validation Rules
34+ rules organized into 6 categories:
| Category | Rules | What It Catches |
|---|---|---|
| Structure | KNP-001 to KNP-003 | Missing policies, naming, labels |
| Pod Selectors | KNP-004 to KNP-007 | Overly broad selectors, missing policyTypes |
| Ingress | KNP-008 to KNP-012 | Open ingress, dangerous ports, missing restrictions |
| Egress | KNP-013 to KNP-018 | Unrestricted egress, cloud metadata SSRF, wide CIDRs |
| IP Blocks | KNP-019 to KNP-022 | Invalid CIDRs, internet exposure, /32 overuse |
| Cross-Policy | KNP-023 to KNP-034 | Duplicates, coverage gaps, missing default-deny, DNS |
View all rules:
kube-netpol rules
Policy Templates
| Template | Description |
|---|---|
default-deny-ingress |
Block all inbound traffic |
default-deny-egress |
Block all outbound traffic |
default-deny-all |
Zero-trust baseline (both directions) |
allow-dns |
Allow DNS resolution via kube-dns |
allow-internet-egress |
Allow outbound HTTPS (blocking cloud metadata) |
web-app |
HTTP/HTTPS ingress + DNS egress |
backend-api |
Frontend → API ingress + DB egress |
database |
API-only ingress + DNS egress |
monitoring |
Prometheus scraping from monitoring namespace |
microservices-suite |
Complete 3-tier zero-trust (5 policies) |
Output Formats
Terminal (Default)
Rich terminal output with colored severity, score gauge, traffic map, and recommendations.
JSON
Machine-readable report for CI/CD pipelines and custom dashboards.
HTML
Interactive dashboard with Mermaid connectivity diagrams, sortable tables, and severity filtering.
Architecture
kube_netpol/
├── cli.py # Click CLI entry point
├── models.py # Core data models (Issue, NetworkPolicy, TrafficFlow)
├── parser.py # YAML manifest parser
├── demo.py # Demo scenario generator
├── analyzers/
│ ├── validator.py # 34+ validation rules
│ └── simulator.py # Traffic flow simulation engine
├── generators/
│ └── policy_generator.py # 10 policy templates
└── reporters/
├── terminal_reporter.py # Rich terminal output
├── export_reporter.py # JSON + HTML export
└── visualizer.py # Mermaid + ASCII diagrams
License
MIT License — see LICENSE for details.
Author
Sai Sandeep — Built with ❤️ for Kubernetes network security.
Metadata
Release files for kube-netpol 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| kube_netpol-1.0.0.tar.gz | 36.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kube_netpol-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 72.1 kB
Release files / kube_netpol-1.0.0.tar.gz
| Download URL | kube_netpol-1.0.0.tar.gz |
|---|---|
| Size | 36.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15970c380d32f1f690d81eb8315cde4dd9cee29921fb50bb40b7cb55e1506cb2
|
|
BLAKE2b-256 checksum How to use checksums |
30e18ece9164df1f00d4a8549bf2acc2d65ef3ad358ee62fae048aab91a3bc86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.7
|
Release files / kube_netpol-1.0.0-py3-none-any.whl
| Download URL | kube_netpol-1.0.0-py3-none-any.whl |
|---|---|
| Size | 35.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27d1640826957361c77d18f3c61012594d9d31331b748dce35db00de6440353e
|
|
BLAKE2b-256 checksum How to use checksums |
dc871752d1bd2c1acc230b479fe3b9df079b33193a23317d92cfa3ec864c0b11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.7
|
Security for kube-netpol 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.