跳到正文
cccskills
免费在 GitHub 公开

k8s-security-policies

Plan Kubernetes security controls for network access, pod settings, and user permissions. The skill provides examples for NetworkPolicy, Pod Security Standards, and RBAC, helping define network boundaries and grant only the access workloads and users need.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

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

实测评分 未实测

查看安装方法

适用场景

  • Restricting traffic between Kubernetes workloads
  • Applying pod security settings by namespace
  • Granting least-privilege cluster access
  • Creating admission policies for required labels

包含的文件(3)

  • SKILL.md7.3 KB
  • assets/network-policy-template.yaml3.1 KB
  • references/rbac-patterns.md4.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Kubernetes Security Policies

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

Do not use this skill when

  • The task is unrelated to kubernetes security policies
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.

Purpose

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

Use this skill when

  • 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

Reference Files

  • assets/network-policy-template.yaml - Network policy examples
  • references/rbac-patterns.md - RBAC configuration patterns

Related Skills

  • k8s-manifest-generator - For creating secure manifests
  • gitops-workflow - For automated policy deployment

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Audit web or mobile experiences against WCAG accessibility criteria. The skill combines automated scans with manual checks such as keyboard use, screen readers, focus order, and contrast, then maps barriers to user impact and gives remediation steps and retesting guidance.

中文简介正在准备中。当前显示英语简介。

  • Auditing a website against a chosen WCAG level
  • Finding keyboard and screen reader barriers
  • Prioritizing accessibility fixes by user impact
rmyndharis/antigravity-skills18462026年10月15日 更新

Helps improve an existing AI agent by reviewing performance metrics, user feedback, and failure patterns, then refining prompts and workflows. It outlines structured evaluation, A/B comparisons, version tracking, staged rollout, and rollback when quality or safety declines.

中文简介正在准备中。当前显示英语简介。

  • Analyzing recurring agent failures
  • Refining prompts based on user feedback
  • Comparing original and improved agent versions
rmyndharis/antigravity-skills18462026年10月15日 更新

Improve multi-agent workflows by measuring performance, finding coordination bottlenecks, and adjusting workload distribution, parallel execution, context use, and cost controls. It guides incremental changes and repeatable checks against defined goals.

中文简介正在准备中。当前显示英语简介。

  • Finding bottlenecks across agent workflows
  • Improving multi-agent throughput or latency
  • Reducing token and tool costs
rmyndharis/antigravity-skills18462026年10月15日 更新

Design and implement applications built with large language models, including retrieval-augmented generation (RAG), vector search, multimodal features, and AI agents. Plan integrations, monitoring, safety measures, and cost controls for production use.

中文简介正在准备中。当前显示英语简介。

  • Build a RAG knowledge assistant
  • Create a customer support agent
  • Add semantic search with reranking
rmyndharis/antigravity-skills18462026年10月15日 更新

Build and maintain Apache Airflow workflows for data pipelines and scheduled batch jobs. Get guidance on DAG structure, task dependencies, operators, sensors, local testing, production setup, and debugging failed runs, with operational checklists and examples.

中文简介正在准备中。当前显示英语简介。

  • Designing DAGs and task dependencies
  • Creating custom operators or sensors
  • Testing Airflow workflows locally
rmyndharis/antigravity-skills18462026年10月15日 更新

Plan and carry out AngularJS-to-Angular migrations, from choosing a rewrite or gradual hybrid approach to updating components, services, routing, and forms. Use it to assess risks, organize milestones, and validate an incremental transition.

中文简介正在准备中。当前显示英语简介。

  • Planning an AngularJS-to-Angular migration
  • Running AngularJS and Angular side by side
  • Rewriting directives and controllers as components
rmyndharis/antigravity-skills18462026年10月15日 更新

查看 rmyndharis 的全部技能

报告此技能的问题