Implement Kubernetes security policies including

by wshobson · MIT license · ★ 39,857 on GitHub · updated Sep 21

Kubernetes Security Policies cover

Implement Kubernetes security policies including NetworkPolicy, PodSecurityPolicy, and RBAC for production-grade security. Use when securing Kubernetes clusters, implementing network isolation, or enforcing pod security standards.

---
name: k8s-security-policies
description: Implement Kubernetes security policies including NetworkPolicy, PodSecurityPolicy, and RBAC for production-grade security. Use when securing Kubernetes clusters, implementing network isolation, or enforcing pod security standards.
---

# Kubernetes Security Policies

Comprehensive guide for implementing NetworkPolicy, PodSecurityPolicy, RBAC, and Pod Security Standards in Kubernetes.

## Purpose

Implement defense-in-depth security for Kubernetes clusters using network policies, pod security standards, and RBAC.

## When to Use This Skill

- Implement network segmentation
- Configure pod security standards
- Set up RBAC for least-privilege access

Overview

Comprehensive guide for implementing NetworkPolicy, PodSecurityPolicy, RBAC, and Pod Security Standards in Kubernetes.

Manual install (npx, ZIP)
Claude Codenpx skills add wshobson/agents --skill k8s-security-policies -g -a claude-code
Claude Code (manual)mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \ | tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/kubernetes-operations/skills/k8s-security-policies
Windows (PowerShell)New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/20e6f1a48ba51f774edb/k8s-security-policies.zip" -OutFile "$env:TEMP\k8s-security-policies.zip"; Expand-Archive "$env:TEMP\k8s-security-policies.zip" -DestinationPath "$HOME\.claude\skills" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md7.0 KB
  • assets/1 file · 3.1 KB
  • references/1 file · 4.1 KB
Read the files here
wshobson/4236bb93 files
SKILL.md
Show the full text348 lines

Kubernetes Security Policies

Comprehensive guide for implementing NetworkPolicy, PodSecurityPolicy, RBAC, and Pod Security Standards in Kubernetes.

Purpose

Implement defense-in-depth security for Kubernetes clusters using network policies, pod security standards, and RBAC.

When to Use This Skill

  • Implement network segmentation
  • Configure pod security standards
  • Set up RBAC for least-privilege access
  • Create security policies for compliance
  • Implement admission control
  • Secure multi-tenant clusters

Pod Security Standards

1. Privileged (Unrestricted)
apiVersion: v1
kind: Namespace
metadata:
  name: privileged-ns
  labels:
    pod-security.kubernetes.io/enforce: privileged
    pod-security.kubernetes.io/audit: privileged
    pod-security.kubernetes.io/warn: privileged
2. Baseline (Minimally restrictive)
apiVersion: v1
kind: Namespace
metadata:
  name: baseline-ns
  labels:
    pod-security.kubernetes.io/enforce: baseline
    pod-security.kubernetes.io/audit: baseline
    pod-security.kubernetes.io/warn: baseline
3. Restricted (Most restrictive)
apiVersion: v1
kind: Namespace
metadata:
  name: restricted-ns
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/warn: restricted

Network Policies

Default Deny All
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
  namespace: production
spec:
  podSelector: {}
  policyTypes:
    - Ingress
    - Egress
Allow Frontend to Backend
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-frontend-to-backend
  namespace: production
spec:
  podSelector:
    matchLabels:
      app: backend
  policyTypes:
    - Ingress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: frontend
      ports:
        - protocol: TCP
          port: 8080
Allow DNS
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-dns
  namespace: production
spec:
  podSelector: {}
  policyTypes:
    - Egress
  egress:
    - to:
        - namespaceSelector:
            matchLabels:
              name: kube-system
      ports:
        - protocol: UDP
          port: 53

Reference: See assets/network-policy-template.yaml

RBAC Configuration

Role (Namespace-scoped)
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-reader
  namespace: production
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "watch", "list"]
ClusterRole (Cluster-wide)
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: secret-reader
rules:
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get", "watch", "list"]
RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: production
subjects:
  - kind: User
    name: jane
    apiGroup: rbac.authorization.k8s.io
  - kind: ServiceAccount
    name: default
    namespace: production
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

Reference: See references/rbac-patterns.md

Pod Security Context

Restricted Pod
apiVersion: v1
kind: Pod
metadata:
  name: secure-pod
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    fsGroup: 1000
    seccompProfile:
      type: RuntimeDefault
  containers:
    - name: app
      image: myapp:1.0
      securityContext:
        allowPrivilegeEscalation: false
        readOnlyRootFilesystem: true
        capabilities:
          drop:
            - ALL

Policy Enforcement with OPA Gatekeeper

ConstraintTemplate
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
  name: k8srequiredlabels
spec:
  crd:
    spec:
      names:
        kind: K8sRequiredLabels
      validation:
        openAPIV3Schema:
          type: object
          properties:
            labels:
              type: array
              items:
                type: string
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package k8srequiredlabels
        violation[{"msg": msg, "details": {"missing_labels": missing}}] {
          provided := {label | input.review.object.metadata.labels[label]}
          required := {label | label := input.parameters.labels[_]}
          missing := required - provided
          count(missing) > 0
          msg := sprintf("missing required labels: %v", [missing])
        }
Constraint
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
  name: require-app-label
spec:
  match:
    kinds:
      - apiGroups: ["apps"]
        kinds: ["Deployment"]
  parameters:
    labels: ["app", "environment"]

Service Mesh Security (Istio)

PeerAuthentication (mTLS)
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: default
  namespace: production
spec:
  mtls:
    mode: STRICT
AuthorizationPolicy
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: allow-frontend
  namespace: production
spec:
  selector:
    matchLabels:
      app: backend
  action: ALLOW
  rules:
    - from:
        - source:
            principals: ["cluster.local/ns/production/sa/frontend"]

Best Practices

  1. Implement Pod Security Standards at namespace level
  2. Use Network Policies for network segmentation
  3. Apply least-privilege RBAC for all service accounts
  4. Enable admission control (OPA Gatekeeper/Kyverno)
  5. Run containers as non-root
  6. Use read-only root filesystem
  7. Drop all capabilities unless needed
  8. Implement resource quotas and limit ranges
  9. Enable audit logging for security events
  10. Regular security scanning of images

Compliance Frameworks

CIS Kubernetes Benchmark
  • Use RBAC authorization
  • Enable audit logging
  • Use Pod Security Standards
  • Configure network policies
  • Implement secrets encryption at rest
  • Enable node authentication
NIST Cybersecurity Framework
  • Implement defense in depth
  • Use network segmentation
  • Configure security monitoring
  • Implement access controls
  • Enable logging and monitoring

Troubleshooting

NetworkPolicy not working:

# Check if CNI supports NetworkPolicy
kubectl get nodes -o wide
kubectl describe networkpolicy <name>

RBAC permission denied:

# Check effective permissions
kubectl auth can-i list pods --as system:serviceaccount:default:my-sa
kubectl auth can-i '*' '*' --as system:serviceaccount:default:my-sa
  • k8s-manifest-generator - For creating secure manifests
  • gitops-workflow - For automated policy deployment
1---
2name: k8s-security-policies
3description: Implement Kubernetes security policies including NetworkPolicy, PodSecurityPolicy, and RBAC for production-grade security. Use when securing Kubernetes clusters, implementing network isolation, or enforcing pod security standards.
4---
5 
6# Kubernetes Security Policies
7 
8Comprehensive guide for implementing NetworkPolicy, PodSecurityPolicy, RBAC, and Pod Security Standards in Kubernetes.
9 
10## Purpose
11 
12Implement defense-in-depth security for Kubernetes clusters using network policies, pod security standards, and RBAC.
13 
14## When to Use This Skill
15 
16- Implement network segmentation
17- Configure pod security standards
18- Set up RBAC for least-privilege access
19- Create security policies for compliance
20- Implement admission control
21- Secure multi-tenant clusters
22 
23## Pod Security Standards
24 
25### 1. Privileged (Unrestricted)
26 
27```yaml
28apiVersion: v1
29kind: Namespace
30metadata:
31 name: privileged-ns
32 labels:
33 pod-security.kubernetes.io/enforce: privileged
34 pod-security.kubernetes.io/audit: privileged
35 pod-security.kubernetes.io/warn: privileged
36```
37 
38### 2. Baseline (Minimally restrictive)
39 
40```yaml
41apiVersion: v1
42kind: Namespace
43metadata:
44 name: baseline-ns
45 labels:
46 pod-security.kubernetes.io/enforce: baseline
47 pod-security.kubernetes.io/audit: baseline
48 pod-security.kubernetes.io/warn: baseline
49```
50 
51### 3. Restricted (Most restrictive)
52 
53```yaml
54apiVersion: v1
55kind: Namespace
56metadata:
57 name: restricted-ns
58 labels:
59 pod-security.kubernetes.io/enforce: restricted
60 pod-security.kubernetes.io/audit: restricted
61 pod-security.kubernetes.io/warn: restricted
62```
63 
64## Network Policies
65 
66### Default Deny All
67 
68```yaml
69apiVersion: networking.k8s.io/v1
70kind: NetworkPolicy
71metadata:
72 name: default-deny-all
73 namespace: production
74spec:
75 podSelector: {}
76 policyTypes:
77 - Ingress
78 - Egress
79```
80 
81### Allow Frontend to Backend
82 
83```yaml
84apiVersion: networking.k8s.io/v1
85kind: NetworkPolicy
86metadata:
87 name: allow-frontend-to-backend
88 namespace: production
89spec:
90 podSelector:
91 matchLabels:
92 app: backend
93 policyTypes:
94 - Ingress
95 ingress:
96 - from:
97 - podSelector:
98 matchLabels:
99 app: frontend
100 ports:
101 - protocol: TCP
102 port: 8080
103```
104 
105### Allow DNS
106 
107```yaml
108apiVersion: networking.k8s.io/v1
109kind: NetworkPolicy
110metadata:
111 name: allow-dns
112 namespace: production
113spec:
114 podSelector: {}
115 policyTypes:
116 - Egress
117 egress:
118 - to:
119 - namespaceSelector:
120 matchLabels:
121 name: kube-system
122 ports:
123 - protocol: UDP
124 port: 53
125```
126 
127**Reference:** See `assets/network-policy-template.yaml`
128 
129## RBAC Configuration
130 
131### Role (Namespace-scoped)
132 
133```yaml
134apiVersion: rbac.authorization.k8s.io/v1
135kind: Role
136metadata:
137 name: pod-reader
138 namespace: production
139rules:
140 - apiGroups: [""]
141 resources: ["pods"]
142 verbs: ["get", "watch", "list"]
143```
144 
145### ClusterRole (Cluster-wide)
146 
147```yaml
148apiVersion: rbac.authorization.k8s.io/v1
149kind: ClusterRole
150metadata:
151 name: secret-reader
152rules:
153 - apiGroups: [""]
154 resources: ["secrets"]
155 verbs: ["get", "watch", "list"]
156```
157 
158### RoleBinding
159 
160```yaml
161apiVersion: rbac.authorization.k8s.io/v1
162kind: RoleBinding
163metadata:
164 name: read-pods
165 namespace: production
166subjects:
167 - kind: User
168 name: jane
169 apiGroup: rbac.authorization.k8s.io
170 - kind: ServiceAccount
171 name: default
172 namespace: production
173roleRef:
174 kind: Role
175 name: pod-reader
176 apiGroup: rbac.authorization.k8s.io
177```
178 
179**Reference:** See `references/rbac-patterns.md`
180 
181## Pod Security Context
182 
183### Restricted Pod
184 
185```yaml
186apiVersion: v1
187kind: Pod
188metadata:
189 name: secure-pod
190spec:
191 securityContext:
192 runAsNonRoot: true
193 runAsUser: 1000
194 fsGroup: 1000
195 seccompProfile:
196 type: RuntimeDefault
197 containers:
198 - name: app
199 image: myapp:1.0
200 securityContext:
201 allowPrivilegeEscalation: false
202 readOnlyRootFilesystem: true
203 capabilities:
204 drop:
205 - ALL
206```
207 
208## Policy Enforcement with OPA Gatekeeper
209 
210### ConstraintTemplate
211 
212```yaml
213apiVersion: templates.gatekeeper.sh/v1
214kind: ConstraintTemplate
215metadata:
216 name: k8srequiredlabels
217spec:
218 crd:
219 spec:
220 names:
221 kind: K8sRequiredLabels
222 validation:
223 openAPIV3Schema:
224 type: object
225 properties:
226 labels:
227 type: array
228 items:
229 type: string
230 targets:
231 - target: admission.k8s.gatekeeper.sh
232 rego: |
233 package k8srequiredlabels
234 violation[{"msg": msg, "details": {"missing_labels": missing}}] {
235 provided := {label | input.review.object.metadata.labels[label]}
236 required := {label | label := input.parameters.labels[_]}
237 missing := required - provided
238 count(missing) > 0
239 msg := sprintf("missing required labels: %v", [missing])
240 }
241```
242 
243### Constraint
244 
245```yaml
246apiVersion: constraints.gatekeeper.sh/v1beta1
247kind: K8sRequiredLabels
248metadata:
249 name: require-app-label
250spec:
251 match:
252 kinds:
253 - apiGroups: ["apps"]
254 kinds: ["Deployment"]
255 parameters:
256 labels: ["app", "environment"]
257```
258 
259## Service Mesh Security (Istio)
260 
261### PeerAuthentication (mTLS)
262 
263```yaml
264apiVersion: security.istio.io/v1beta1
265kind: PeerAuthentication
266metadata:
267 name: default
268 namespace: production
269spec:
270 mtls:
271 mode: STRICT
272```
273 
274### AuthorizationPolicy
275 
276```yaml
277apiVersion: security.istio.io/v1beta1
278kind: AuthorizationPolicy
279metadata:
280 name: allow-frontend
281 namespace: production
282spec:
283 selector:
284 matchLabels:
285 app: backend
286 action: ALLOW
287 rules:
288 - from:
289 - source:
290 principals: ["cluster.local/ns/production/sa/frontend"]
291```
292 
293## Best Practices
294 
2951. **Implement Pod Security Standards** at namespace level
2962. **Use Network Policies** for network segmentation
2973. **Apply least-privilege RBAC** for all service accounts
2984. **Enable admission control** (OPA Gatekeeper/Kyverno)
2995. **Run containers as non-root**
3006. **Use read-only root filesystem**
3017. **Drop all capabilities** unless needed
3028. **Implement resource quotas** and limit ranges
3039. **Enable audit logging** for security events
30410. **Regular security scanning** of images
305 
306## Compliance Frameworks
307 
308### CIS Kubernetes Benchmark
309 
310- Use RBAC authorization
311- Enable audit logging
312- Use Pod Security Standards
313- Configure network policies
314- Implement secrets encryption at rest
315- Enable node authentication
316 
317### NIST Cybersecurity Framework
318 
319- Implement defense in depth
320- Use network segmentation
321- Configure security monitoring
322- Implement access controls
323- Enable logging and monitoring
324 
325## Troubleshooting
326 
327**NetworkPolicy not working:**
328 
329```bash
330# Check if CNI supports NetworkPolicy
331kubectl get nodes -o wide
332kubectl describe networkpolicy <name>
333```
334 
335**RBAC permission denied:**
336 
337```bash
338# Check effective permissions
339kubectl auth can-i list pods --as system:serviceaccount:default:my-sa
340kubectl auth can-i '*' '*' --as system:serviceaccount:default:my-sa
341```
342 
343 
344## Related Skills
345 
346- `k8s-manifest-generator` - For creating secure manifests
347- `gitops-workflow` - For automated policy deployment
348 
View all files on GitHub →

Details

Updated
Sep 21, 2026
License
MIT
Stars on the repo
★ 39,857
Checked
Source
wshobson/agents ↗
Creator
wshobson · 179 listings
View creator

Similar skills

See all →
SkillSecurity guidance and vulnerability review for codebasesSecurity auditcloudflare/security-audit-skill · by cloudflareSecurity guidance and vulnerability review for codebases, APIs, services, CLI tools, libraries, and daemons. Use for security questions, focused reviews, vulnerability research, security audits, or pen tests. Run the complete workflow only for explicit codebase audit or pen-test requests, full/comprehensive/end-to-end reviews, or requested report artifacts.★ 26.1k GitHub starsMCPYou need to audit Active Directory security postureAd security reviewerVoltAgent/awesome-claude-code-subagents · by VoltAgentUse this agent when you need to audit Active Directory security posture, evaluate privilege escalation risks, review identity delegation patterns, or assess authentication protocol hardening.★ 25.2k GitHub starsSkillApply modern web development best practices for securityaddyosmani/web-quality-skills · by addyosmaniApply modern web development best practices for security, compatibility, and code quality. Use when asked to "apply best practices", "security audit", "modernize code", "code quality review", or "check for vulnerabilities".★ 2.8k GitHub starsSkillHelps Claude write secure web applicationsSecure Coding Guide for Web ApplicationsBehiSecc/VibeSec-Skill · by BehiSeccThis skill helps Claude write secure web applications. Use this when working on any web application or when a user requests a scan or audit to ensure security best practices are followed.★ 1.3k GitHub starsMCPReviews completed implementation against governing securitySecurity reviewershinpr/claude-code-workflows · by shinprReviews completed implementation against governing security requirements and the reachable trust model. Use after implementation or when security review/security check/vulnerability check is requested. Returns only must-fix findings with the smallest sufficient corrections.★ 687 GitHub starsSkillAccount-based marketing for B2B SaaSAccount-Based Marketing Operationsshalintripathi/saas-marketing-agents · by shalintripathiAccount-based marketing for B2B SaaS. Use this skill to build a target account list, tier it 1:1 / 1:few / 1:many, size it against sales capacity, turn intent and engagement signals into plays, write the multi-channel orchestration contract each tier runs on, and measure the program in account coverage, penetration and pipeline instead of MQLs. Also triggers on: ABM, account-based marketing, target account list, TAL, named accounts, account tiering, 1:1 ABM, one-to-few, programmatic ABM, account selection, ideal customer profile fit, intent data, buying signals, 6sense, Bombora, Demandbase, account penetration, account coverage, sales and marketing alignment on accounts, enterprise account program.★ 20 GitHub stars

More from wshobson

SkillMaster C/.NET backend development patterns for buildingwshobson/agents · by wshobsonMaster C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.★ 39.9k GitHub starsSkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliancewshobson/agents · by wshobsonImplement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.★ 39.9k GitHub starsSkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Designwshobson/agents · by wshobsonMaster Material Design 3 and Jetpack Compose patterns for building native Android apps. Use when designing Android interfaces, implementing Compose UI, or following Google's Material Design guidelines.★ 39.9k GitHub starsSkillMigrate from AngularJS to Angular using hybrid modeAngular migrationwshobson/agents · by wshobsonMigrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.★ 39.9k GitHub starsSkillUnderstand anti-reversing, obfuscationAnti reversing techniqueswshobson/agents · by wshobsonUnderstand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.★ 39.9k GitHub starsSkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patternswshobson/agents · by wshobsonBuild production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.★ 39.9k GitHub stars