Zero-Trust NetworkPolicy Design Prompt
Design a default-deny NetworkPolicy set for a namespace, then add precise ingress/egress allow rules per workload so only intended traffic flows, including DNS and cross-namespace dependencies.
- Target user
- Platform and security engineers
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform security engineer designing NetworkPolicies to bring a namespace from open to default-deny zero-trust, without breaking legitimate traffic. I will provide: - The workloads in the namespace and their pod labels - The actual traffic map: who calls whom, on which ports, including cross-namespace and external (DB, cache, third-party API) dependencies - Whether the CNI enforces NetworkPolicy (Calico/Cilium) and whether egress policy is supported - Any namespace labels available for namespaceSelector Your job: 1. **Lay the default-deny base** — write the policies that deny all ingress and all egress in the namespace, and explain that an empty podSelector with no rules is the deny-all primitive. 2. **Allow DNS first** — add the egress rule to kube-dns/CoreDNS (UDP/TCP 53) before anything else, since default-deny egress breaks name resolution and is the #1 footgun. 3. **Write per-workload ingress** — for each service, allow only the specific source pods (podSelector) and ports it must receive on; use namespaceSelector for cross-namespace callers. 4. **Write per-workload egress** — allow only required destinations (in-cluster pods by label, and external CIDRs for DBs/APIs), naming why each is needed. 5. **Handle the gaps** — call out that ipBlock is needed for non-pod external endpoints, and that NetworkPolicy is namespaced and additive (policies combine as OR). 6. **Verify** — give the test plan: confirm allowed paths work and a deliberately disallowed path is blocked. Output: the ordered set of NetworkPolicy manifests (default-deny, DNS, then per-workload), a one-line rationale per policy, and a verification checklist.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Kubernetes NetworkPolicy Authoring & Review Prompt
Move a Kubernetes cluster from flat, open pod networking to default-deny, least-privilege NetworkPolicies — author, review, and validate ingress/egress rules per workload without breaking traffic.
-
Kubernetes NetworkPolicy Debug Prompt
Diagnose why pod-to-pod, pod-to-service, or pod-to-external traffic is being dropped by NetworkPolicy — Calico, Cilium, Weave, or upstream defaults.
-
NetworkPolicy Default-Deny Baseline Design Prompt
Author a zero-trust NetworkPolicy baseline for a cluster — default-deny ingress and egress per namespace, explicit allow rules for DNS and platform traffic, and a safe rollout that won't black-hole production.
-
Kubernetes RBAC Least-Privilege Role Scaffolding Prompt
Build a minimal Role/ClusterRole from an application's actual API access needs, starting from observed audit/verb usage instead of copying an over-broad cluster-admin binding.
More Kubernetes & Helm prompts & error guides
Browse every Kubernetes & Helm prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.