k8s-security-policies — Claude Code skill: what it does, install
This skill helps define Kubernetes security policies for network isolation, RBAC, and pod security standards. Use it when securing a cluster.
/plugin marketplace add wshobson/agents
/plugin install kubernetes-operations@claude-code-workflowsWhat k8s-security-policies does
k8s-security-policies guides Kubernetes security work around NetworkPolicy, Pod Security Standards, RBAC, and admission control. It covers network segmentation, least-privilege access, non-root containers, read-only root filesystems, and dropped capabilities.
The skill includes YAML examples for default-deny traffic, frontend-to-backend access, DNS, Role, ClusterRole, RoleBinding, securityContext, OPA Gatekeeper, and Istio mTLS. It also points to assets/network-policy-template.yaml and references/rbac-patterns.md, with kubectl commands for checking NetworkPolicy and RBAC behavior.
Install it when you are securing a Kubernetes cluster or setting policies for multiple tenants. Kubernetes knowledge is required. OPA Gatekeeper or Istio only applies to the matching policy scenarios.
What it helps with
- segment traffic between Kubernetes workloads
- configure least-privilege RBAC access
- enforce pod security at namespace level
- run containers without root privileges
- debug NetworkPolicy or RBAC permission issues
Example prompts for the agent
- Set up NetworkPolicy for the `production` namespace: deny all ingress and egress, then allow frontend traffic to backend.
- Create a Role and RoleBinding that let a service account read pods in `production`, then check it with `kubectl auth can-i`.
- Write OPA Gatekeeper policies that require the `app` and `environment` labels on Deployments.
How to install k8s-security-policies
1Plugin marketplace
/plugin marketplace add wshobson/agents/plugin install kubernetes-operations@claude-code-workflowsThis installs the whole kubernetes-operations plugin with all its skills
2Skills CLI (Vercel)
npx skills add wshobson/agents --skill k8s-security-policies -a claude-code3Manually: put the files in place
~/.claude/skills/k8s-security-policies/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/k8s-security-policies/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill k8s-security-policies -a codex2Manually: put the files in place
.agents/skills/k8s-security-policies/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill k8s-security-policies -a cursor2Manually: put the files in place
.cursor/skills/k8s-security-policies/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install wshobson/agents k8s-security-policies2Manually: put the files in place
.github/skills/k8s-security-policies/SKILL.mdPlatform CLI
gemini skills install https://github.com/wshobson/agents --path plugins/kubernetes-operations/skills/k8s-security-policiesManually: put the files in place
.devin/skills/k8s-security-policies/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set213
The whole set →Similar
Questions about k8s-security-policies
How do I install k8s-security-policies in Claude Code?
Run npx skills add wshobson/agents --skill k8s-security-policies -a claude-code. The skill is also available through the Kubernetes operations marketplace plugin.
What does k8s-security-policies do?
It provides guidance and examples for Kubernetes NetworkPolicy, RBAC, Pod Security Standards, securityContext, and admission control. The material also covers OPA Gatekeeper and Istio policies.
Do I need Istio to use this skill?
No. The core examples cover Kubernetes NetworkPolicy, RBAC, and Pod Security Standards. Istio is relevant only for PeerAuthentication and AuthorizationPolicy configurations.
Source text
SKILL.md · MIT
---
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
- Create security policies for compliance
- Implement admission control
- Secure multi-tenant clusters
## Pod Security Standards
### 1. Privileged (Unrestricted)
```yaml
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)
```yaml
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)
```yaml
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
```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
```
### Allow Frontend to Backend
```yaml
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
```yaml
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)
```yaml
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)
```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: secret-reader
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "watch", "list"]
```
### RoleBinding
```yaml
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
```yaml
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
```yaml
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
```yaml
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)
```yaml
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: production
spec:
mtls:
mode: STRICT
```
### AuthorizationPolicy
```yaml
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:**
```bash
# Check if CNI supports NetworkPolicy
kubectl get nodes -o wide
kubectl describe networkpolicy <name>
```
**RBAC permission denied:**
```bash
# 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
```
## Related Skills
- `k8s-manifest-generator` - For creating secure manifests
- `gitops-workflow` - For automated policy deployment
© Seth Hobson · MIT · wshobson/agents