
K8s Security Policies
Drop ready-made Kubernetes NetworkPolicy YAML into your cluster so traffic is deny-by-default with explicit DNS, ingress, and monitoring paths.
Install
npx skills add https://github.com/wshobson/agents --skill k8s-security-policiesWhat is this skill?
- 5 NetworkPolicy templates: default deny, allow DNS, frontend→backend, ingress controller, monitoring (partial set in cat
- Default-deny-all baseline with empty podSelector for namespace-wide lockdown
- Explicit UDP port 53 egress to kube-system for DNS resolution
- Label-driven frontend/backend tier rules on TCP 8080 and 9090
- Ingress-nginx namespaceSelector pattern for HTTP/HTTPS exposure
Adoption & trust: 10.6k installs on skills.sh; 36.5k GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Azure Deploymicrosoft/azure-skills
Azure Preparemicrosoft/azure-skills
Azure Storagemicrosoft/azure-skills
Azure Validatemicrosoft/azure-skills
Appinsights Instrumentationmicrosoft/azure-skills
Azure Resource Lookupmicrosoft/azure-skills
Journey fit
Common Questions / FAQ
Is K8s Security Policies safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - K8s Security Policies
# Network Policy Templates --- # Template 1: Default Deny All (Start Here) apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: default-deny-all namespace: <namespace> spec: podSelector: {} policyTypes: - Ingress - Egress --- # Template 2: Allow DNS (Essential) apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-dns namespace: <namespace> spec: podSelector: {} policyTypes: - Egress egress: - to: - namespaceSelector: matchLabels: name: kube-system ports: - protocol: UDP port: 53 --- # Template 3: Frontend to Backend apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-frontend-to-backend namespace: <namespace> spec: podSelector: matchLabels: app: backend tier: backend policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: app: frontend tier: frontend ports: - protocol: TCP port: 8080 - protocol: TCP port: 9090 --- # Template 4: Allow Ingress Controller apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-ingress-controller namespace: <namespace> spec: podSelector: matchLabels: app: web policyTypes: - Ingress ingress: - from: - namespaceSelector: matchLabels: name: ingress-nginx ports: - protocol: TCP port: 80 - protocol: TCP port: 443 --- # Template 5: Allow Monitoring (Prometheus) apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-prometheus-scraping namespace: <namespace> spec: podSelector: matchLabels: prometheus.io/scrape: "true" policyTypes: - Ingress ingress: - from: - namespaceSelector: matchLabels: name: monitoring ports: - protocol: TCP port: 9090 --- # Template 6: Allow External HTTPS apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-external-https namespace: <namespace> spec: podSelector: matchLabels: app: api-client policyTypes: - Egress egress: - to: - ipBlock: cidr: 0.0.0.0/0 except: - 169.254.169.254/32 # Block metadata service ports: - protocol: TCP port: 443 --- # Template 7: Database Access apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-app-to-database namespace: <namespace> spec: podSelector: matchLabels: app: postgres tier: database policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: tier: backend ports: - protocol: TCP port: 5432 --- # Template 8: Cross-Namespace Communication apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-from-prod-namespace namespace: <namespace> spec: podSelector: matchLabels: app: api policyTypes: - Ingress ingress: - from: - namespaceSelector: matchLabels: environment: production podSelector: matchLabels: app: frontend ports: - protocol: TCP port: 8080 # RBAC Patterns and Best Practices ## Common RBAC Patterns ### Pattern 1: Read-Only Access ```yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: read-only rules: - apiGroups: ["", "apps", "batch"] resources: ["*"] verbs: ["get", "list", "watch"] ``` ### Pattern 2: Namespace Admin ```yaml apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: namespace-admin namespace: production rules: - apiGroups: ["", "apps", "batch", "extensions"] resources: ["*"] verbs: ["*"] ``` ### Pattern 3: Deployment Manager ```yaml apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: deployment-manager namespace: production rules: - apiGroups: ["apps"] resources: ["deployments"] verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]