# Kubernetes 将弃用 PSP

太长不看版：

> Merged：deprecate PSP in 1.21, but leave removal at 1.25 #97171

[Pod Security Policy](https://kubernetes.io/docs/concepts/policy/pod-security-policy/) 是 Kubernetes 的重要安全措施之一，它首先定义角色，其中规定了对 Pod 行为的限制，其中包括对特权容器、主机网络、Capability、加载卷类型等内容进行了限制，然后通过 RBAC 把 SA-Pod-PSP 三者结合起来，完成对 Pod 权限的限制。相对于 [SecurytContext](https://kubernetes.io/docs/concepts/policy/pod-security-policy/) 来说，PSP 更具强制性和可管理性，CIS Kubernetes Benchmark（v1.6）中明确地把启用 PSP 设置为记分项目，很多 Kubernetes 安全相关软件也会据此进行检查。

然而 PSP 是无法缺省启用的，还有一些[其它缺陷](https://docs.google.com/presentation/d/1Kv6BSBNyLCyglMbK7e6tVOaDYe89LV2aHL2Hlb-9HX8/edit#slide=id.g5d1d1d6ca2_1_0)，因此在 [#97171](https://github.com/kubernetes/kubernetes/pull/97171) 中，Kubernetes 1.21 把 PSP 加入了淘汰队列，并在 1.25 中移除。

讨论中可以看到，几个备选方案包括：

- 升级 PSP
- 第三方策略引擎
- 缺省启用宽松策略

目前可用的唯一方案就是启用策略引擎，因此 OPA/Gatekeeper 或 Kyverno 等策略引擎的重要性将进一步提高。遇到扫描报告里的“未启用 PSP”也可以理直气壮了。

## 参考链接

- `#97171`：`https://github.com/kubernetes/kubernetes/pull/97171`

- PodSecurityPolicy，Present and Future：`https://docs.google.com/presentation/d/1Kv6BSBNyLCyglMbK7e6tVOaDYe89LV2aHL2Hlb-9HX8/edit#slide=id.p`

- Pod Security Policy：`https://kubernetes.io/docs/concepts/policy/pod-security-policy/`

- Security Context：`https://kubernetes.io/docs/tasks/configure-pod-container/security-context/`
