{
    "url": "https://delaparra-services.nl/skills/k8s-security-policies",
    "locale": "en",
    "title": "Kubernetes Security Policies | DeLaParra Services",
    "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.",
    "alternates": {
        "en": "https://delaparra-services.nl/skills/k8s-security-policies",
        "nl": "https://delaparra-services.nl/nl/skills/k8s-security-policies"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/skills/k8s-security-policies.csv",
        "md": "https://delaparra-services.nl/skills/k8s-security-policies.md",
        "json": "https://delaparra-services.nl/skills/k8s-security-policies.json",
        "zip": "https://delaparra-services.nl/skills/k8s-security-policies.zip",
        "pdf": "https://delaparra-services.nl/skills/k8s-security-policies.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/skills/k8s-security-policies.csv",
            "encodingFormat": "text/csv",
            "name": "k8s-security-policies.csv"
        },
        {
            "url": "https://delaparra-services.nl/skills/k8s-security-policies.json",
            "encodingFormat": "application/json",
            "name": "k8s-security-policies.json"
        },
        {
            "url": "https://delaparra-services.nl/skills/k8s-security-policies.md",
            "encodingFormat": "text/markdown",
            "name": "k8s-security-policies.md"
        },
        {
            "url": "https://delaparra-services.nl/skills/k8s-security-policies.pdf",
            "encodingFormat": "application/pdf",
            "name": "k8s-security-policies.pdf"
        },
        {
            "url": "https://delaparra-services.nl/skills/k8s-security-policies.zip",
            "encodingFormat": "application/zip",
            "name": "k8s-security-policies.zip"
        },
        {
            "url": "https://delaparra-services.nl/skills/k8s-security-policies/download",
            "encodingFormat": "application/zip",
            "name": "k8s-security-policies-files.zip"
        }
    ],
    "markdown": "# Kubernetes Security Policies\n\n \n\nImplement 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.\n\n \n\n**Licence** MIT\n\n \n\n**Source** wshobson/agents\n\n [Download zip](<https://delaparra-services.nl/skills/k8s-security-policies/download>)   \n\n# Kubernetes Security Policies\n\n \n\nComprehensive guide for implementing NetworkPolicy, PodSecurityPolicy, RBAC, and Pod Security Standards in Kubernetes.\n\n \n\n## Purpose\n\n \n\nImplement defense-in-depth security for Kubernetes clusters using network policies, pod security standards, and RBAC.\n\n \n\n## When to Use This Skill\n\n \n\n- Implement network segmentation \n- Configure pod security standards \n- Set up RBAC for least-privilege access \n- Create security policies for compliance \n- Implement admission control \n- Secure multi-tenant clusters\n\n \n\n## Pod Security Standards\n\n \n\n### 1. Privileged (Unrestricted)\n\n \n\n```\napiVersion: v1\nkind: Namespace\nmetadata:\n  name: privileged-ns\n  labels:\n    pod-security.kubernetes.io/enforce: privileged\n    pod-security.kubernetes.io/audit: privileged\n    pod-security.kubernetes.io/warn: privileged\n```\n\n \n\n### 2. Baseline (Minimally restrictive)\n\n \n\n```\napiVersion: v1\nkind: Namespace\nmetadata:\n  name: baseline-ns\n  labels:\n    pod-security.kubernetes.io/enforce: baseline\n    pod-security.kubernetes.io/audit: baseline\n    pod-security.kubernetes.io/warn: baseline\n```\n\n \n\n### 3. Restricted (Most restrictive)\n\n \n\n```\napiVersion: v1\nkind: Namespace\nmetadata:\n  name: restricted-ns\n  labels:\n    pod-security.kubernetes.io/enforce: restricted\n    pod-security.kubernetes.io/audit: restricted\n    pod-security.kubernetes.io/warn: restricted\n```\n\n \n\n## Network Policies\n\n \n\n### Default Deny All\n\n \n\n```\napiVersion: networking.k8s.io/v1\nkind: NetworkPolicy\nmetadata:\n  name: default-deny-all\n  namespace: production\nspec:\n  podSelector: {}\n  policyTypes:\n    - Ingress\n    - Egress\n```\n\n \n\n### Allow Frontend to Backend\n\n \n\n```\napiVersion: networking.k8s.io/v1\nkind: NetworkPolicy\nmetadata:\n  name: allow-frontend-to-backend\n  namespace: production\nspec:\n  podSelector:\n    matchLabels:\n      app: backend\n  policyTypes:\n    - Ingress\n  ingress:\n    - from:\n        - podSelector:\n            matchLabels:\n              app: frontend\n      ports:\n        - protocol: TCP\n          port: 8080\n```\n\n \n\n### Allow DNS\n\n \n\n```\napiVersion: networking.k8s.io/v1\nkind: NetworkPolicy\nmetadata:\n  name: allow-dns\n  namespace: production\nspec:\n  podSelector: {}\n  policyTypes:\n    - Egress\n  egress:\n    - to:\n        - namespaceSelector:\n            matchLabels:\n              name: kube-system\n      ports:\n        - protocol: UDP\n          port: 53\n```\n\n \n\n**Reference:** See ` assets/network-policy-template.yaml `\n\n \n\n## RBAC Configuration\n\n \n\n### Role (Namespace-scoped)\n\n \n\n```\napiVersion: rbac.authorization.k8s.io/v1\nkind: Role\nmetadata:\n  name: pod-reader\n  namespace: production\nrules:\n  - apiGroups: [\"\"]\n    resources: [\"pods\"]\n    verbs: [\"get\", \"watch\", \"list\"]\n```\n\n \n\n### ClusterRole (Cluster-wide)\n\n \n\n```\napiVersion: rbac.authorization.k8s.io/v1\nkind: ClusterRole\nmetadata:\n  name: secret-reader\nrules:\n  - apiGroups: [\"\"]\n    resources: [\"secrets\"]\n    verbs: [\"get\", \"watch\", \"list\"]\n```\n\n \n\n### RoleBinding\n\n \n\n```\napiVersion: rbac.authorization.k8s.io/v1\nkind: RoleBinding\nmetadata:\n  name: read-pods\n  namespace: production\nsubjects:\n  - kind: User\n    name: jane\n    apiGroup: rbac.authorization.k8s.io\n  - kind: ServiceAccount\n    name: default\n    namespace: production\nroleRef:\n  kind: Role\n  name: pod-reader\n  apiGroup: rbac.authorization.k8s.io\n```\n\n \n\n**Reference:** See ` references/rbac-patterns.md `\n\n \n\n## Pod Security Context\n\n \n\n### Restricted Pod\n\n \n\n```\napiVersion: v1\nkind: Pod\nmetadata:\n  name: secure-pod\nspec:\n  securityContext:\n    runAsNonRoot: true\n    runAsUser: 1000\n    fsGroup: 1000\n    seccompProfile:\n      type: RuntimeDefault\n  containers:\n    - name: app\n      image: myapp:1.0\n      securityContext:\n        allowPrivilegeEscalation: false\n        readOnlyRootFilesystem: true\n        capabilities:\n          drop:\n            - ALL\n```\n\n \n\n## Policy Enforcement with OPA Gatekeeper\n\n \n\n### ConstraintTemplate\n\n \n\n```\napiVersion: templates.gatekeeper.sh/v1\nkind: ConstraintTemplate\nmetadata:\n  name: k8srequiredlabels\nspec:\n  crd:\n    spec:\n      names:\n        kind: K8sRequiredLabels\n      validation:\n        openAPIV3Schema:\n          type: object\n          properties:\n            labels:\n              type: array\n              items:\n                type: string\n  targets:\n    - target: admission.k8s.gatekeeper.sh\n      rego: |\n        package k8srequiredlabels\n        violation[{\"msg\": msg, \"details\": {\"missing_labels\": missing}}] {\n          provided := {label | input.review.object.metadata.labels[label]}\n          required := {label | label := input.parameters.labels[_]}\n          missing := required - provided\n          count(missing) > 0\n          msg := sprintf(\"missing required labels: %v\", [missing])\n        }\n```\n\n \n\n### Constraint\n\n \n\n```\napiVersion: constraints.gatekeeper.sh/v1beta1\nkind: K8sRequiredLabels\nmetadata:\n  name: require-app-label\nspec:\n  match:\n    kinds:\n      - apiGroups: [\"apps\"]\n        kinds: [\"Deployment\"]\n  parameters:\n    labels: [\"app\", \"environment\"]\n```\n\n \n\n## Service Mesh Security (Istio)\n\n \n\n### PeerAuthentication (mTLS)\n\n \n\n```\napiVersion: security.istio.io/v1beta1\nkind: PeerAuthentication\nmetadata:\n  name: default\n  namespace: production\nspec:\n  mtls:\n    mode: STRICT\n```\n\n \n\n### AuthorizationPolicy\n\n \n\n```\napiVersion: security.istio.io/v1beta1\nkind: AuthorizationPolicy\nmetadata:\n  name: allow-frontend\n  namespace: production\nspec:\n  selector:\n    matchLabels:\n      app: backend\n  action: ALLOW\n  rules:\n    - from:\n        - source:\n            principals: [\"cluster.local/ns/production/sa/frontend\"]\n```\n\n \n\n## Best Practices\n\n \n\n1. **Implement Pod Security Standards** at namespace level \n1. **Use Network Policies** for network segmentation \n1. **Apply least-privilege RBAC** for all service accounts \n1. **Enable admission control** (OPA Gatekeeper/Kyverno) \n1. **Run containers as non-root** \n1. **Use read-only root filesystem** \n1. **Drop all capabilities** unless needed \n1. **Implement resource quotas** and limit ranges \n1. **Enable audit logging** for security events \n1. **Regular security scanning** of images\n\n \n\n## Compliance Frameworks\n\n \n\n### CIS Kubernetes Benchmark\n\n \n\n- Use RBAC authorization \n- Enable audit logging \n- Use Pod Security Standards \n- Configure network policies \n- Implement secrets encryption at rest \n- Enable node authentication\n\n \n\n### NIST Cybersecurity Framework\n\n \n\n- Implement defense in depth \n- Use network segmentation \n- Configure security monitoring \n- Implement access controls \n- Enable logging and monitoring\n\n \n\n## Troubleshooting\n\n \n\n**NetworkPolicy not working:**\n\n \n\n```\n# Check if CNI supports NetworkPolicy\nkubectl get nodes -o wide\nkubectl describe networkpolicy <name>\n```\n\n \n\n**RBAC permission denied:**\n\n \n\n```\n# Check effective permissions\nkubectl auth can-i list pods --as system:serviceaccount:default:my-sa\nkubectl auth can-i '*' '*' --as system:serviceaccount:default:my-sa\n```\n\n \n\n## Related Skills\n\n \n\n- ` k8s-manifest-generator ` - For creating secure manifests \n- ` gitops-workflow ` - For automated policy deployment\n\n \n\n## Files\n\n \n\n- ` LICENSE ` \n- ` SKILL.md ` \n- ` SOURCE.md ` \n- ` assets/network-policy-template.yaml ` \n- ` references/rbac-patterns.md `\n\n \n\n## Related terms\n\n \n\n- [NetworkPolicy](<https://delaparra-services.nl/knowledge-hub/networkpolicy>) \n- [Secret](<https://delaparra-services.nl/knowledge-hub/secret>)\n\n \n\n[Installing an agent skill in Claude Code, Codex, Cursor and Copilot](<https://delaparra-services.nl/manuals/een-skill-installeren-in-je-ai-assistent>)\n\n[HTML version](https://delaparra-services.nl/skills/k8s-security-policies)\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "Organization",
                "@id": "https://delaparra-services.nl/#practice",
                "logo": "https://delaparra-services.nl/logo.png",
                "name": "DeLaParra Services",
                "legalName": "DeLaParra Services",
                "url": "https://delaparra-services.nl/",
                "description": "Bespoke software, web applications and mobile apps, developed in Laravel by a single developer in Groningen. Fixed price agreed in advance, full source code provided upon delivery.",
                "email": "info@delaparra-services.nl",
                "address": {
                    "@type": "PostalAddress",
                    "addressLocality": "Groningen",
                    "addressRegion": "Groningen",
                    "addressCountry": "NL"
                },
                "areaServed": "Groningen, the Netherlands",
                "knowsLanguage": [
                    "en",
                    "nl"
                ],
                "knowsAbout": [
                    "Web design and development",
                    "App development",
                    "Custom software and web applications",
                    "OpenSpec",
                    "AI code review",
                    "Your own coding agent"
                ],
                "founder": {
                    "@id": "https://delaparra-services.nl/#person"
                }
            },
            {
                "@type": "WebPage",
                "@id": "https://delaparra-services.nl/skills/k8s-security-policies#webpage",
                "url": "https://delaparra-services.nl/skills/k8s-security-policies",
                "name": "Kubernetes Security Policies | DeLaParra Services",
                "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.",
                "isPartOf": {
                    "@id": "https://delaparra-services.nl/#website"
                },
                "about": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "inLanguage": "en",
                "breadcrumb": {
                    "@id": "https://delaparra-services.nl/skills/k8s-security-policies#breadcrumb"
                }
            },
            {
                "@type": "BreadcrumbList",
                "@id": "https://delaparra-services.nl/skills/k8s-security-policies#breadcrumb",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "name": "Home",
                        "item": "https://delaparra-services.nl/"
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "name": "Kubernetes Security Policies"
                    }
                ]
            },
            {
                "@type": "Person",
                "@id": "https://delaparra-services.nl/#person",
                "name": "Reinier de la Parra",
                "url": "https://delaparra-services.nl/about"
            },
            {
                "@type": "SoftwareSourceCode",
                "@id": "https://delaparra-services.nl/skills/k8s-security-policies#skill",
                "url": "https://delaparra-services.nl/skills/k8s-security-policies",
                "name": "Kubernetes 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.",
                "inLanguage": "en",
                "license": "https://spdx.org/licenses/MIT.html",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/skills/k8s-security-policies#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/skills/k8s-security-policies#dataset",
                "name": "Kubernetes 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.",
                "url": "https://delaparra-services.nl/skills/k8s-security-policies",
                "identifier": "https://delaparra-services.nl/skills/k8s-security-policies#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/skills/k8s-security-policies#skill"
                },
                "creditText": "wshobson/agents",
                "publisher": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "license": "https://spdx.org/licenses/MIT.html",
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "dateModified": "2026-11-28T14:00:11+00:00",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/knowledge-hub#skills",
                    "name": "Skills for AI coding assistants",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "k8s-security-policies.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/skills/k8s-security-policies.csv",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "k8s-security-policies.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/skills/k8s-security-policies.json",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "k8s-security-policies.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/skills/k8s-security-policies.md",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "k8s-security-policies.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/skills/k8s-security-policies.pdf",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "k8s-security-policies.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/k8s-security-policies.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "k8s-security-policies-files.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/k8s-security-policies/download",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:11+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    }
                ]
            }
        ]
    }
}