Design a network proxy policy linter: egress rules, identities, and risk checks.
- User
Design a network proxy policy linter: egress rules, identities, and risk checks.
- Assistant
Design a network proxy policy linter: egress rules, identities, and risk checks.
The Network Proxy Policy Linter (NPPL) is a static analysis tool for validating and auditing network proxy policies, with a focus on egress rules, identities, and risk checks. It targets proxies like Envoy (used in Istio, Consul, etc.), NGINX, or custom service mesh proxies enforcing zero-trust policies.
NPPL CLI/API
├── Parser (YAML/JSON → AST)
├── Checker Registry
│ ├── EgressChecker
│ ├── IdentityChecker
│ └── RiskChecker (with external feeds)
├── Reporter (JSON/YAML/SARIF/HTML)
└── Output: Violations Report + Diffs
NetworkPolicy, Istio AuthorizationPolicy, or raw Envoy JSON).nppl.yaml): Custom rules, ignore lists, risk thresholds.{
"summary": { "total_policies": 10, "violations": 5, "critical": 2 },
"violations": [
{
"id": "EGRESS-001",
"severity": "CRITICAL",
"message": "Allow-all to internet",
"policy": "egress-policy.yaml",
"line": 15,
"remediation": "Restrict to specific CIDRs"
}
]
}
Analyzes outbound traffic allowances.
| Check ID | Severity | Description | Example Violation |
|---|---|---|---|
| EGRESS-001 | CRITICAL | Allow-all (0.0.0.0/0 or internet) without justification. | destinations: [{cidr: "0.0.0.0/0"}] |
| EGRESS-002 | HIGH | HTTP/80 egress to untrusted hosts (prefer HTTPS). | ports: [80] to external domains. |
| EGRESS-003 | MED | Shadowing: Duplicate/overlapping rules (first match wins). | Rule A allows port 443; Rule B denies it later. |
| EGRESS-004 | LOW | Unused rules (no matching selectors). | Cross-reference with workload manifests. |
| EGRESS-005 | HIGH | DNS egress without DoT (DNS over TLS). | ports: [53/udp] without encryption. |
| EGRESS-006 | MED | Non-standard ports for common protocols (e.g., SSH on 22 to internet). | Flag risky port combos. |
Implementation: Parse to AST, simulate rule evaluation with test workloads.
Validates workload/user identities (e.g., SPIFFE/SPIRE, JWT, mTLS certs).
| Check ID | Severity | Description | Example Violation |
|---|---|---|---|
| ID-001 | CRITICAL | Missing or default identities (e.g., identity: "*"). | principals: ["*"] |
| ID-002 | HIGH | Weak authn: No mTLS or JWT validation required. | Egress without require_peer_identity. |
| ID-003 | MED | Identity mismatch: Rule selectors don't align with declared identities. | Selector app: db but identity service: web. |
| ID-004 | LOW | Expired/revoked certs in identity refs (integrate with cert store). | spiffe://trust-domain/ns/default/sa/web revoked. |
| ID-005 | HIGH | Over-permissive delegation (e.g., any identity can egress to prod). | from: [{any: true}]. |
Implementation: Map identities to workloads via Kubernetes API or manifests; validate against SPIFFE spec.
Holistic security scans with external context.
| Check ID | Severity | Description | Example Violation |
|---|---|---|---|
| RISK-001 | CRITICAL | Egress to known malicious IPs/domains (e.g., via AbuseIPDB feed). | Destination in blocklist. |
| RISK-002 | HIGH | Exposed sensitive protocols (e.g., RDP/3389 to internet). | High-risk ports open externally. |
| RISK-003 | MED | No rate limiting or timeouts on egress. | Missing http_filters: rate_limit. |
| RISK-004 | HIGH | Compliance violations (e.g., PCI-DSS: no egress to cardholder data). | Custom rule sets. |
| RISK-005 | LOW | Drift: Policy differs from baseline (git diff mode). | Changed from deny-by-default. |
| RISK-006 | CRITICAL | Egress to shadow IT (e.g., unapproved SaaS like torrent domains). | Domain categorization via APIs (e.g., Google Safe Browsing). |
Implementation:
score = base_sev + (ports_risk * 0.5) + (cidr_broadness * 0.3).gopkg.in/yaml.v3 or ruamel.yaml.kyaml (for K8s).goquery for HTML reports, otx-api-go for threats.cobra or click.type Violation struct {
ID string
Severity string
Message string
File string
Line int
Remediation string
}
func LintPolicies(files []string) []Violation {
var violations []Violation
for _, file := range files {
ast := ParsePolicy(file)
violations = append(violations, EgressChecker(ast)...)
// ...
}
return violations
}
# Lint single file
nppl lint policy.yaml --output json --risk-feed otx
# CI mode
nppl lint ./policies/ --baseline baseline.yaml --fail-on high
# Sample Input (egress-policy.yaml)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
spec:
podSelector: {}
policyTypes: [Egress]
egress:
- to:
- ipBlock: {cidr: 0.0.0.0/0} # <-- Violation: EGRESS-001
ports: [{protocol: TCP, port: 80}] # <-- Violation: EGRESS-002
# Output Snippet
Violations: 2
- CRITICAL EGRESS-001: Allow-all to internet (line 7). Remediate: Use specific CIDRs.
- HIGH EGRESS-002: HTTP egress (line 8). Remediate: Enforce HTTPS/443.
This design ensures secure, scalable policy management. Deploy as a Git pre-commit hook for instant feedback! Questions or refinements?