implementing-kubernetes-pod-security-standards

Pod 安全标准(PSS)定义了三个安全策略级别——特权级、基线级和受限级——由 Kubernetes 1.25+ 内置的 Pod 安全准入(PSA)控制器强制执行。

9 stars

Best use case

implementing-kubernetes-pod-security-standards is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Pod 安全标准(PSS)定义了三个安全策略级别——特权级、基线级和受限级——由 Kubernetes 1.25+ 内置的 Pod 安全准入(PSA)控制器强制执行。

Teams using implementing-kubernetes-pod-security-standards should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/implementing-kubernetes-pod-security-standards/SKILL.md --create-dirs "https://raw.githubusercontent.com/killvxk/cybersecurity-skills-zh/main/skills/implementing-kubernetes-pod-security-standards/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/implementing-kubernetes-pod-security-standards/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How implementing-kubernetes-pod-security-standards Compares

Feature / Agentimplementing-kubernetes-pod-security-standardsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Pod 安全标准(PSS)定义了三个安全策略级别——特权级、基线级和受限级——由 Kubernetes 1.25+ 内置的 Pod 安全准入(PSA)控制器强制执行。

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 实施 Kubernetes Pod 安全标准

## 概述

Pod 安全标准(PSS)定义了三个安全策略级别——特权级(Privileged)、基线级(Baseline)和受限级(Restricted)——由 Kubernetes 1.25+ 内置的 Pod 安全准入(PSA)控制器强制执行。PSA 取代了已废弃的 PodSecurityPolicy,提供命名空间级别的强制执行,支持三种模式:enforce(强制)、audit(审计)和 warn(警告)。

## 前提条件

- Kubernetes 集群 1.25+(PSA GA 版本)
- 已配置集群管理员访问权限的 kubectl
- 了解 Linux 能力和安全上下文

## 核心概念

### 三个安全配置文件

| 配置文件 | 用途 | 限制 |
|---------|---------|-------------|
| **Privileged(特权级)** | 不受限制,用于系统工作负载 | 无 |
| **Baseline(基线级)** | 防止已知提权 | 禁止 hostNetwork、hostPID、hostIPC、特权容器、危险能力 |
| **Restricted(受限级)** | 强化的最佳实践 | 非 root、丢弃所有能力、需要 seccomp、建议只读 rootfs |

### 三种强制执行模式

| 模式 | 行为 |
|------|----------|
| **enforce(强制)** | 拒绝违反策略的 Pod |
| **audit(审计)** | 在审计日志中记录违规但允许 Pod 创建 |
| **warn(警告)** | 向用户返回警告但允许 Pod 创建 |

## 实施步骤

### 步骤 1:为命名空间打 PSA 标签

```yaml
# 受限命名空间 - 生产工作负载
apiVersion: v1
kind: Namespace
metadata:
  name: production
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/enforce-version: latest
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/audit-version: latest
    pod-security.kubernetes.io/warn: restricted
    pod-security.kubernetes.io/warn-version: latest
```

```yaml
# 基线命名空间 - 通用工作负载
apiVersion: v1
kind: Namespace
metadata:
  name: staging
  labels:
    pod-security.kubernetes.io/enforce: baseline
    pod-security.kubernetes.io/enforce-version: latest
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/audit-version: latest
    pod-security.kubernetes.io/warn: restricted
    pod-security.kubernetes.io/warn-version: latest
```

```yaml
# 特权命名空间 - 仅限系统组件
apiVersion: v1
kind: Namespace
metadata:
  name: kube-system
  labels:
    pod-security.kubernetes.io/enforce: privileged
    pod-security.kubernetes.io/enforce-version: latest
```

### 步骤 2:对现有命名空间应用标签

```bash
# 对生产环境应用受限强制执行
kubectl label namespace production \
  pod-security.kubernetes.io/enforce=restricted \
  pod-security.kubernetes.io/audit=restricted \
  pod-security.kubernetes.io/warn=restricted \
  --overwrite

# 对预发布环境应用基线级别,带受限级别警告
kubectl label namespace staging \
  pod-security.kubernetes.io/enforce=baseline \
  pod-security.kubernetes.io/audit=restricted \
  pod-security.kubernetes.io/warn=restricted \
  --overwrite

# 检查所有命名空间的标签
kubectl get namespaces -L pod-security.kubernetes.io/enforce
```

### 步骤 3:创建符合要求的 Pod 规格

```yaml
# 符合受限级别要求的 Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: secure-app
  namespace: production
spec:
  replicas: 3
  selector:
    matchLabels:
      app: secure-app
  template:
    metadata:
      labels:
        app: secure-app
    spec:
      automountServiceAccountToken: false
      securityContext:
        runAsNonRoot: true
        runAsUser: 65534
        runAsGroup: 65534
        fsGroup: 65534
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: app
          image: myregistry.com/myapp:v1.0.0@sha256:abc123
          ports:
            - containerPort: 8080
              protocol: TCP
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop:
                - ALL
            runAsNonRoot: true
            runAsUser: 65534
          resources:
            requests:
              memory: "64Mi"
              cpu: "100m"
            limits:
              memory: "256Mi"
              cpu: "500m"
          volumeMounts:
            - name: tmp
              mountPath: /tmp
            - name: cache
              mountPath: /var/cache
      volumes:
        - name: tmp
          emptyDir:
            sizeLimit: 100Mi
        - name: cache
          emptyDir:
            sizeLimit: 50Mi
```

### 步骤 4:渐进式迁移策略

```bash
# 阶段 1:审计模式 - 发现违规而不阻断
kubectl label namespace my-namespace \
  pod-security.kubernetes.io/audit=restricted \
  pod-security.kubernetes.io/warn=restricted

# 检查审计日志中的违规
kubectl logs -n kube-system -l component=kube-apiserver | grep "pod-security"

# 阶段 2:强制基线级别,对受限级别发出警告
kubectl label namespace my-namespace \
  pod-security.kubernetes.io/enforce=baseline \
  pod-security.kubernetes.io/warn=restricted \
  --overwrite

# 阶段 3:完全受限级别强制执行
kubectl label namespace my-namespace \
  pod-security.kubernetes.io/enforce=restricted \
  --overwrite
```

### 步骤 5:试运行强制执行测试

```bash
# 测试应用受限级别后会发生什么
kubectl label --dry-run=server --overwrite namespace my-namespace \
  pod-security.kubernetes.io/enforce=restricted

# 示例输出:
# Warning: existing pods in namespace "my-namespace" violate the new
# PodSecurity enforce level "restricted:latest"
# Warning: nginx-xxx: allowPrivilegeEscalation != false,
#   unrestricted capabilities, runAsNonRoot != true, seccompProfile
```

## 基线配置文件限制

| 控制项 | 受限要求 | 要求说明 |
|---------|-----------|-------------|
| HostProcess | 不得设置 | Pod 不能使用 Windows HostProcess |
| 主机命名空间 | 不得设置 | 禁止 hostNetwork、hostPID、hostIPC |
| 特权 | 不得设置 | 禁止 privileged: true |
| 能力 | 仅基线列表 | 仅允许 NET_BIND_SERVICE,受限级别需丢弃 ALL |
| HostPath 卷 | 不得使用 | 禁止 hostPath 卷挂载 |
| 主机端口 | 不得使用 | 容器规格中禁止 hostPort |
| AppArmor | 默认/运行时 | 不能设置为 unconfined |
| SELinux | 受限类型 | 仅允许 container_t、container_init_t、container_kvm_t |
| /proc 挂载类型 | 仅默认 | 必须使用默认 proc 挂载 |
| Seccomp | RuntimeDefault 或 Localhost | 受限级别必须指定 seccomp 配置文件 |
| Sysctls | 仅安全集合 | 仅限安全的 sysctls |

## 验证命令

```bash
# 验证命名空间标签
kubectl get ns --show-labels | grep pod-security

# 测试针对策略的 Pod 创建
kubectl run test-pod --image=nginx --namespace=production --dry-run=server

# 检查审计日志中的违规
kubectl get events --field-selector reason=FailedCreate -A

# 使用 Kubescape 扫描 PSS 合规性
kubescape scan framework nsa --namespace production
```

## 参考资料

- [Pod 安全标准 - Kubernetes](https://kubernetes.io/docs/concepts/security/pod-security-standards/)
- [Pod 安全准入 - Kubernetes](https://kubernetes.io/docs/concepts/security/pod-security-admission/)
- [从 PodSecurityPolicy 迁移](https://kubernetes.io/docs/tasks/configure-pod-container/migrate-from-psp/)
- [Kubescape PSS 扫描器](https://github.com/kubescape/kubescape)

Related Skills

triaging-security-incident

9
from killvxk/cybersecurity-skills-zh

使用 NIST SP 800-61r3 和 SANS PICERL 框架对安全事件进行初始分类,确定严重性、范围和所需响应行动。 按类型对事件分类,根据业务影响分配优先级,并路由到相应的响应团队。适用于事件分类、 安全告警分类、严重性评估、事件优先级排序或初始事件分析等请求场景。

triaging-security-incident-with-ir-playbook

9
from killvxk/cybersecurity-skills-zh

使用结构化 IR Playbook 对安全事件进行分类和优先排序,确定严重性、分配响应团队并启动适当的响应程序。

triaging-security-alerts-in-splunk

9
from killvxk/cybersecurity-skills-zh

在 Splunk Enterprise Security 中对安全告警进行分类,通过 SPL 查询和事件审查(Incident Review) 仪表板对重要事件进行严重性分类、调查、关联相关遥测并做出升级或关闭决策。 适用于 SOC 分析师需要处理关联搜索产生的告警队列、确定调查优先级, 或需要为交接给二/三级分析师记录分类决策时。

testing-websocket-api-security

9
from killvxk/cybersecurity-skills-zh

测试 WebSocket API 实现中的安全漏洞,包括 WebSocket 升级时缺少身份认证、跨站 WebSocket 劫持(Cross-Site WebSocket Hijacking,CSWSH)、通过 WebSocket 消息进行的注入攻击、输入校验不足、通过消息泛洪实施拒绝服务,以及通过 WebSocket 帧造成的信息泄露。测试人员使用 Burp Suite 拦截 WebSocket 握手和消息,构造恶意 payload,并测试 WebSocket 通道上的授权绕过。适用于 WebSocket 安全测试、WS 渗透测试、CSWSH 攻击或实时 API 安全评估相关请求。

testing-jwt-token-security

9
from killvxk/cybersecurity-skills-zh

在安全测试活动中,评估 JSON Web Token(JWT)实现中的密码学弱点、算法混淆攻击和授权绕过漏洞。

testing-api-security-with-owasp-top-10

9
from killvxk/cybersecurity-skills-zh

使用自动化和手工测试技术,针对 OWASP API 安全 Top 10 风险对 REST 和 GraphQL API 端点进行系统性评估。

securing-kubernetes-on-cloud

9
from killvxk/cybersecurity-skills-zh

本技能涵盖通过实施 Pod 安全标准(Pod Security Standards)、网络策略、工作负载身份、RBAC 权限控制、镜像准入控制和运行时安全监控,对 EKS、AKS 和 GKE 上的托管 Kubernetes 集群进行加固。涉及云平台特定安全功能,包括 EKS 的 IRSA、GKE 的工作负载身份(Workload Identity)以及 AKS 的托管身份(Managed Identity)。

scanning-kubernetes-manifests-with-kubesec

9
from killvxk/cybersecurity-skills-zh

使用 Kubesec 对 Kubernetes 资源清单执行安全风险分析,识别错误配置、权限提升风险以及与安全最佳实践的偏差。

performing-wireless-security-assessment-with-kismet

9
from killvxk/cybersecurity-skills-zh

使用 Kismet 通过被动射频监控进行无线网络安全评估,检测流氓接入点(Rogue AP)、隐藏 SSID、弱加密和未授权客户端。

performing-ssl-tls-security-assessment

9
from killvxk/cybersecurity-skills-zh

使用 sslyze Python 库评估 SSL/TLS 服务器配置,评估加密套件、证书链、协议版本、HSTS 头部,以及 Heartbleed 和 ROBOT 等已知漏洞。

performing-soap-web-service-security-testing

9
from killvxk/cybersecurity-skills-zh

通过分析 WSDL 定义,测试 XML 注入(XML Injection)、XXE、WS-Security 绕过和 SOAPAction 欺骗,对 SOAP Web 服务执行安全测试。

performing-serverless-function-security-review

9
from killvxk/cybersecurity-skills-zh

对 AWS Lambda、Azure Functions 和 GCP Cloud Functions 中的无服务器函数(Serverless Function)执行安全审查,识别过度宽松的执行角色(Execution Role)、不安全的环境变量、注入漏洞和缺失的运行时保护措施。