|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "弃用 PodSecurityPolicy:过去、现在、未来" |
| 4 | +date: 2021-04-06 |
| 5 | +slug: podsecuritypolicy-deprecation-past-present-and-future |
| 6 | +--- |
| 7 | +<!-- |
| 8 | +title: "PodSecurityPolicy Deprecation: Past, Present, and Future" |
| 9 | +--> |
| 10 | + |
| 11 | +<!-- |
| 12 | +**Author:** Tabitha Sable (Kubernetes SIG Security) |
| 13 | +--> |
| 14 | +作者:Tabitha Sable(Kubernetes SIG Security) |
| 15 | + |
| 16 | +<!-- |
| 17 | +PodSecurityPolicy (PSP) is being deprecated in Kubernetes 1.21, to be released later this week. |
| 18 | +This starts the countdown to its removal, but doesn’t change anything else. |
| 19 | +PodSecurityPolicy will continue to be fully functional for several more releases before being removed completely. |
| 20 | +In the meantime, we are developing a replacement for PSP that covers key use cases more easily and sustainably. |
| 21 | +--> |
| 22 | +PodSecurityPolicy (PSP) 在 Kubernetes 1.21 中被弃用。<!--to be released later this week这句感觉没必要翻译,非漏译--> |
| 23 | +PSP 日后会被移除,但目前不会改变任何其他内容。在移除之前,PSP 将继续在后续多个版本中完全正常运行。 |
| 24 | +与此同时,我们正在开发 PSP 的替代品,希望可以更轻松、更可持续地覆盖关键用例。 |
| 25 | + |
| 26 | +<!-- |
| 27 | +What are Pod Security Policies? Why did we need them? Why are they going away, and what’s next? |
| 28 | +How does this affect you? These key questions come to mind as we prepare to say goodbye to PSP, |
| 29 | +so let’s walk through them together. We’ll start with an overview of how features get removed from Kubernetes. |
| 30 | +--> |
| 31 | +什么是 PSP?为什么需要 PSP?为什么要弃用,未来又将如何发展? |
| 32 | +这对你有什么影响?当我们准备告别 PSP,这些关键问题浮现在脑海中, |
| 33 | +所以让我们一起来讨论吧。本文首先概述 Kubernetes 如何移除一些特性。 |
| 34 | + |
| 35 | +<!-- |
| 36 | +## What does deprecation mean in Kubernetes? |
| 37 | +--> |
| 38 | +## Kubernetes 中的弃用是什么意思? |
| 39 | + |
| 40 | +<!-- |
| 41 | +Whenever a Kubernetes feature is set to go away, our [deprecation policy](/docs/reference/using-api/deprecation-policy/) |
| 42 | +is our guide. First the feature is marked as deprecated, then after enough time has passed, it can finally be removed. |
| 43 | +--> |
| 44 | +每当 Kubernetes 决定弃用某项特性时,我们会遵循[弃用策略](/zh-cn/docs/reference/using-api/deprecation-policy/)。 |
| 45 | +首先将该特性标记为已弃用,然后经过足够长的时间后,最终将其移除。 |
| 46 | + |
| 47 | +<!-- |
| 48 | +Kubernetes 1.21 starts the deprecation process for PodSecurityPolicy. As with all feature deprecations, |
| 49 | +PodSecurityPolicy will continue to be fully functional for several more releases. |
| 50 | +The current plan is to remove PSP from Kubernetes in the 1.25 release. |
| 51 | +--> |
| 52 | +Kubernetes 1.21 启动了 PodSecurityPolicy 的弃用流程。与弃用任何其他功能一样, |
| 53 | +PodSecurityPolicy 将继续在后续几个版本中完全正常运行。目前的计划是在 1.25 版本中将其移除。 |
| 54 | + |
| 55 | +<!-- |
| 56 | +Until then, PSP is still PSP. There will be at least a year during which the newest Kubernetes releases will |
| 57 | +still support PSP, and nearly two years until PSP will pass fully out of all supported Kubernetes versions. |
| 58 | +--> |
| 59 | +在彻底移除之前,PSP 仍然是 PSP。至少在未来一年时间内,最新的 Kubernetes |
| 60 | +版本仍将继续支持 PSP。大约两年之后,PSP 才会在所有受支持的 Kubernetes 版本中彻底消失。 |
| 61 | + |
| 62 | +<!-- |
| 63 | +## What is PodSecurityPolicy? |
| 64 | +--> |
| 65 | +## 什么是 PodSecurityPolicy? |
| 66 | + |
| 67 | +<!-- |
| 68 | +[PodSecurityPolicy](/docs/concepts/security/pod-security-policy/) is |
| 69 | +a built-in [admission controller](/blog/2019/03/21/a-guide-to-kubernetes-admission-controllers/) |
| 70 | +that allows a cluster administrator to control security-sensitive aspects of the Pod specification. |
| 71 | +--> |
| 72 | +[PodSecurityPolicy](/zh-cn/docs/concepts/security/pod-security-policy/) |
| 73 | +是一个内置的[准入控制器](/blog/2019/03/21/a-guide-to-kubernetes-admission-controllers/), |
| 74 | +允许集群管理员控制 Pod 规约中涉及安全的敏感内容。 |
| 75 | + |
| 76 | +<!-- |
| 77 | +First, one or more PodSecurityPolicy resources are created in a cluster to define the requirements Pods must meet. |
| 78 | +Then, RBAC rules are created to control which PodSecurityPolicy applies to a given pod. |
| 79 | +If a pod meets the requirements of its PSP, it will be admitted to the cluster as usual. |
| 80 | +In some cases, PSP can also modify Pod fields, effectively creating new defaults for those fields. |
| 81 | +If a Pod does not meet the PSP requirements, it is rejected, and cannot run. |
| 82 | +--> |
| 83 | +首先,在集群中创建一个或多个 PodSecurityPolicy 资源来定义 Pod 必须满足的要求。 |
| 84 | +然后,创建 RBAC 规则来决定为特定的 Pod 应用哪个 PodSecurityPolicy。 |
| 85 | +如果 Pod 满足其 PSP 的要求,则照常被允许进入集群。 |
| 86 | +在某些情况下,PSP 还可以修改 Pod 字段,有效地为这些字段创建新的默认值。 |
| 87 | +如果 Pod 不符合 PSP 要求,则被拒绝进入集群,并且无法运行。 |
| 88 | + |
| 89 | +<!-- |
| 90 | +One more important thing to know about PodSecurityPolicy: it’s not the same as |
| 91 | +[PodSecurityContext](/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context). |
| 92 | +--> |
| 93 | +关于 PodSecurityPolicy,还需要了解:它与 |
| 94 | +[PodSecurityContext](/zh-cn/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context) 不同。 |
| 95 | + |
| 96 | +<!-- |
| 97 | +A part of the Pod specification, PodSecurityContext (and its per-container counterpart `SecurityContext`) |
| 98 | +is the collection of fields that specify many of the security-relevant settings for a Pod. |
| 99 | +The security context dictates to the kubelet and container runtime how the Pod should actually be run. |
| 100 | +In contrast, the PodSecurityPolicy only constrains (or defaults) the values that may be set on the security context. |
| 101 | +--> |
| 102 | +作为 Pod 规约的一部分,PodSecurityContext(及其每个容器对应的 `SecurityContext`) |
| 103 | +是一组字段的集合,这些字段为 Pod 指定了与安全相关的许多设置。 |
| 104 | +安全上下文指示 kubelet 和容器运行时究竟应该如何运行 Pod。 |
| 105 | +相反,PodSecurityPolicy 仅约束可能在安全上下文中设置的值(或设置默认值)。 |
| 106 | + |
| 107 | +<!-- |
| 108 | +The deprecation of PSP does not affect PodSecurityContext in any way. |
| 109 | +--> |
| 110 | +弃用 PSP 不会以任何方式影响 PodSecurityContext。 |
| 111 | + |
| 112 | +<!-- |
| 113 | +## Why did we need PodSecurityPolicy? |
| 114 | +--> |
| 115 | +## 以前为什么需要 PodSecurityPolicy? |
| 116 | + |
| 117 | +<!-- |
| 118 | +In Kubernetes, we define resources such as Deployments, StatefulSets, and Services that |
| 119 | +represent the building blocks of software applications. The various controllers inside |
| 120 | +a Kubernetes cluster react to these resources, creating further Kubernetes resources or |
| 121 | +configuring some software or hardware to accomplish our goals. |
| 122 | +--> |
| 123 | +在 Kubernetes 中,我们定义了 Deployment、StatefulSet 和 Service 等资源。 |
| 124 | +这些资源代表软件应用程序的构建块。Kubernetes 集群中的各种控制器根据这些资源做出反应, |
| 125 | +创建更多的 Kubernetes 资源或配置一些软件或硬件来实现我们的目标。 |
| 126 | + |
| 127 | +<!-- |
| 128 | +In most Kubernetes clusters, |
| 129 | +RBAC (Role-Based Access Control) [rules](/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) |
| 130 | +control access to these resources. `list`, `get`, `create`, `edit`, and `delete` are |
| 131 | +the sorts of API operations that RBAC cares about, |
| 132 | +but _RBAC does not consider what settings are being put into the resources it controls_. |
| 133 | +For example, a Pod can be almost anything from a simple webserver to |
| 134 | +a privileged command prompt offering full access to the underlying server node and all the data. |
| 135 | +It’s all the same to RBAC: a Pod is a Pod is a Pod. |
| 136 | +--> |
| 137 | +在大多数 Kubernetes 集群中,由 RBAC(基于角色的访问控制)[规则](/zh-cn/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) |
| 138 | +控制对这些资源的访问。 `list`、`get`、`create`、`edit` 和 `delete` 是 RBAC 关心的 API 操作类型, |
| 139 | +但 **RBAC 不考虑其所控制的资源中加入了哪些设置**。例如, |
| 140 | +Pod 几乎可以是任何东西,例如简单的网络服务器,或者是特权命令提示(提供对底层服务器节点和所有数据的完全访问权限)。 |
| 141 | +这对 RBAC 来说都是一样的:Pod 就是 Pod 而已。 |
| 142 | + |
| 143 | +<!-- |
| 144 | +To control what sorts of settings are allowed in the resources defined in your cluster, |
| 145 | +you need Admission Control in addition to RBAC. Since Kubernetes 1.3, |
| 146 | +PodSecurityPolicy has been the built-in way to do that for security-related Pod fields. |
| 147 | +Using PodSecurityPolicy, you can prevent “create Pod” from automatically meaning “root on every cluster node,” |
| 148 | +without needing to deploy additional external admission controllers. |
| 149 | +--> |
| 150 | +要控制集群中定义的资源允许哪些类型的设置,除了 RBAC 之外,还需要准入控制。 |
| 151 | +从 Kubernetes 1.3 开始,内置 PodSecurityPolicy 一直被作为 Pod 安全相关字段的准入控制机制。 |
| 152 | +使用 PodSecurityPolicy,可以防止“创建 Pod”这个能力自动变成“每个集群节点上的 root 用户”, |
| 153 | +并且无需部署额外的外部准入控制器。 |
| 154 | + |
| 155 | +<!-- |
| 156 | +## Why is PodSecurityPolicy going away? |
| 157 | +--> |
| 158 | +## 现在为什么 PodSecurityPolicy 要消失? |
| 159 | + |
| 160 | +<!-- |
| 161 | +In the years since PodSecurityPolicy was first introduced, we have realized that |
| 162 | +PSP has some serious usability problems that can’t be addressed without making breaking changes. |
| 163 | +--> |
| 164 | +自从首次引入 PodSecurityPolicy 以来,我们已经意识到 PSP 存在一些严重的可用性问题, |
| 165 | +只有做出断裂式的改变才能解决。 |
| 166 | + |
| 167 | +<!-- |
| 168 | +The way PSPs are applied to Pods has proven confusing to nearly everyone that has attempted to use them. |
| 169 | +It is easy to accidentally grant broader permissions than intended, |
| 170 | +and difficult to inspect which PSP(s) apply in a given situation. The “changing Pod defaults” feature can be handy, |
| 171 | +but is only supported for certain Pod settings and it’s not obvious when they will or will not apply to your Pod. |
| 172 | +Without a “dry run” or audit mode, it’s impractical to retrofit PSP to existing clusters safely, |
| 173 | +and it’s impossible for PSP to ever be enabled by default. |
| 174 | +--> |
| 175 | +实践证明,PSP 应用于 Pod 的方式让几乎所有尝试使用它们的人都感到困惑。 |
| 176 | +很容易意外授予比预期更广泛的权限,并且难以查看某种特定情况下应用了哪些 PSP。 |
| 177 | +“更改 Pod 默认值”功能很方便,但仅支持某些 Pod 设置,而且无法明确知道它们何时会或不会应用于的 Pod。 |
| 178 | +如果没有“试运行”或审计模式,将 PSP 安全地改造并应用到现有集群是不切实际的,并且永远都不可能默认启用 PSP。 |
| 179 | + |
| 180 | +<!-- |
| 181 | +For more information about these and other PSP difficulties, check out |
| 182 | +SIG Auth’s KubeCon NA 2019 Maintainer Track session video:{{< youtube "SFtHRmPuhEw?start=953" youtube-quote-sm >}} |
| 183 | +--> |
| 184 | +有关这些问题和其他 PSP 困难的更多信息,请查看 |
| 185 | +KubeCon NA 2019 的 SIG Auth 维护者频道会议记录:{{< youtube "SFtHRmPuhEw?start=953" youtube-quote-sm >}} |
| 186 | + |
| 187 | +<!-- |
| 188 | +Today, you’re not limited only to deploying PSP or writing your own custom admission controller. |
| 189 | +Several external admission controllers are available that incorporate lessons learned from PSP to |
| 190 | +provide a better user experience. [K-Rail](https://github.com/cruise-automation/k-rail), |
| 191 | +[Kyverno](https://github.com/kyverno/kyverno/), and |
| 192 | +[OPA/Gatekeeper](https://github.com/open-policy-agent/gatekeeper/) are all well-known, and each has its fans. |
| 193 | +--> |
| 194 | +如今,你不再局限于部署 PSP 或编写自己的自定义准入控制器。 |
| 195 | +有几个外部准入控制器可用,它们结合了从 PSP 中吸取的经验教训以提供更好的用户体验。 |
| 196 | +[K-Rail](https://github.com/cruise-automation/k-rail)、 |
| 197 | +[Kyverno](https://github.com/kyverno/kyverno/)、 |
| 198 | +[OPA/Gatekeeper](https://github.com/open-policy-agent/gatekeeper/) 都家喻户晓,各有粉丝。 |
| 199 | + |
| 200 | +<!-- |
| 201 | +Although there are other good options available now, we believe there is still value in |
| 202 | +having a built-in admission controller available as a choice for users. With this in mind, |
| 203 | +we turn toward building what’s next, inspired by the lessons learned from PSP. |
| 204 | +--> |
| 205 | +尽管现在还有其他不错的选择,但我们认为,提供一个内置的准入控制器供用户选择,仍然是有价值的事情。 |
| 206 | +考虑到这一点,以及受 PSP 经验的启发,我们转向下一步。 |
| 207 | + |
| 208 | +<!-- |
| 209 | +## What’s next? |
| 210 | +--> |
| 211 | +## 下一步是什么? |
| 212 | + |
| 213 | +<!-- |
| 214 | +Kubernetes SIG Security, SIG Auth, and a diverse collection of other community members |
| 215 | +have been working together for months to ensure that what’s coming next is going to be awesome. |
| 216 | +We have developed a Kubernetes Enhancement Proposal ([KEP 2579](https://github.com/kubernetes/enhancements/issues/2579)) |
| 217 | +and a prototype for a new feature, currently being called by the temporary name "PSP Replacement Policy." |
| 218 | +We are targeting an Alpha release in Kubernetes 1.22. |
| 219 | +--> |
| 220 | +Kubernetes SIG Security、SIG Auth 和其他社区成员几个月来一直在倾力合作,确保接下来的方案能令人惊叹。 |
| 221 | +我们拟定了 Kubernetes 增强提案([KEP 2579](https://github.com/kubernetes/enhancements/issues/2579)) |
| 222 | +以及一个新功能的原型,目前称之为“PSP 替代策略”。 |
| 223 | +我们的目标是在 Kubernetes 1.22 中发布 Alpha 版本。 |
| 224 | + |
| 225 | +<!-- |
| 226 | +PSP Replacement Policy starts with the realization that |
| 227 | +since there is a robust ecosystem of external admission controllers already available, |
| 228 | +PSP’s replacement doesn’t need to be all things to all people. |
| 229 | +Simplicity of deployment and adoption is the key advantage a built-in admission controller has |
| 230 | +compared to an external webhook, so we have focused on how to best utilize that advantage. |
| 231 | +--> |
| 232 | +PSP 替代策略始于,我们认识到已经有一个强大的外部准入控制器生态系统可用, |
| 233 | +所以,PSP 的替代品不需要满足所有人的所有需求。与外部 Webhook 相比, |
| 234 | +部署和采用的简单性是内置准入控制器的关键优势。我们专注于如何最好地利用这一优势。 |
| 235 | + |
| 236 | +<!-- |
| 237 | +PSP Replacement Policy is designed to be as simple as practically possible |
| 238 | +while providing enough flexibility to really be useful in production at scale. |
| 239 | +It has soft rollout features to enable retrofitting it to existing clusters, |
| 240 | +and is configurable enough that it can eventually be active by default. |
| 241 | +It can be deactivated partially or entirely, to coexist with external admission controllers for advanced use cases. |
| 242 | +--> |
| 243 | +PSP 替代策略旨在尽可能简单,同时提供足够的灵活性以支撑大规模生产场景。 |
| 244 | +它具有柔性上线能力,以便于将其改装到现有集群,并且新的策略是可配置的,可以设置为默认启用。 |
| 245 | +PSP 替代策略可以被部分或全部禁用,以便在高级使用场景中与外部准入控制器共存。 |
| 246 | + |
| 247 | +<!-- |
| 248 | +## What does this mean for you? |
| 249 | +--> |
| 250 | +## 这对你意味着什么? |
| 251 | + |
| 252 | +<!-- |
| 253 | +What this all means for you depends on your current PSP situation. |
| 254 | +If you’re already using PSP, there’s plenty of time to plan your next move. |
| 255 | +Please review the PSP Replacement Policy KEP and think about how well it will suit your use case. |
| 256 | +--> |
| 257 | +这一切对你意味着什么取决于你当前的 PSP 情况。如果已经在使用 PSP,那么你有足够的时间来计划下一步行动。 |
| 258 | +请查看 PSP 替代策略 KEP 并考虑它是否适合你的使用场景。 |
| 259 | + |
| 260 | +<!-- |
| 261 | +If you’re making extensive use of the flexibility of PSP with numerous PSPs and complex binding rules, |
| 262 | +you will likely find the simplicity of PSP Replacement Policy too limiting. |
| 263 | +Use the next year to evaluate the other admission controller choices in the ecosystem. |
| 264 | +There are resources available to ease this transition, |
| 265 | +such as the [Gatekeeper Policy Library](https://github.com/open-policy-agent/gatekeeper-library). |
| 266 | +--> |
| 267 | +如果你已经在通过众多 PSP 和复杂的绑定规则深度利用 PSP 的灵活性,你可能会发现 PSP 替代策略的简单性有太多限制。 |
| 268 | +此时,建议你在接下来的一年中评估一下生态系统中的其他准入控制器选择。有些资源可以让这种过渡更容易, |
| 269 | +比如 [Gatekeeper Policy Library](https://github.com/open-policy-agent/gatekeeper-library)。 |
| 270 | + |
| 271 | +<!-- |
| 272 | +If your use of PSP is relatively simple, with a few policies and straightforward binding to |
| 273 | +service accounts in each namespace, you will likely find PSP Replacement Policy to be a good match for your needs. |
| 274 | +Evaluate your PSPs compared to the Kubernetes [Pod Security Standards](/docs/concepts/security/pod-security-standards/) |
| 275 | +to get a feel for where you’ll be able to use the Restricted, Baseline, and Privileged policies. |
| 276 | +Please follow along with or contribute to the KEP and subsequent development, |
| 277 | +and try out the Alpha release of PSP Replacement Policy when it becomes available. |
| 278 | +--> |
| 279 | +如果只是使用 PSP 的基础功能,只用几个策略并直接绑定到每个命名空间中的服务帐户, |
| 280 | +你可能会发现 PSP 替代策略非常适合你的需求。 |
| 281 | +对比 Kubernetes [Pod 安全标准](/zh-cn/docs/concepts/security/pod-security-standards/) 评估你的 PSP, |
| 282 | +了解可以在哪些情形下使用限制策略、基线策略和特权策略。 |
| 283 | +欢迎关注或为 KEP 和后续发展做出贡献,并在可用时试用 PSP 替代策略的 Alpha 版本。 |
| 284 | + |
| 285 | +<!-- |
| 286 | +If you’re just beginning your PSP journey, you will save time and effort by keeping it simple. |
| 287 | +You can approximate the functionality of PSP Replacement Policy today by using the Pod Security Standards’ PSPs. |
| 288 | +If you set the cluster default by binding a Baseline or Restricted policy to the `system:serviceaccounts` group, |
| 289 | +and then make a more-permissive policy available as needed in certain |
| 290 | +Namespaces [using ServiceAccount bindings](/docs/concepts/policy/pod-security-policy/#run-another-pod), |
| 291 | +you will avoid many of the PSP pitfalls and have an easy migration to PSP Replacement Policy. |
| 292 | +If your needs are much more complex than this, your effort is probably better spent adopting |
| 293 | +one of the more fully-featured external admission controllers mentioned above. |
| 294 | +--> |
| 295 | +如果刚刚开始 PSP 之旅,你可以通过保持简单来节省时间和精力。 |
| 296 | +你可以使用 Pod 安全标准的 PSP 来获得和目前 PSP 替代策略相似的功能。 |
| 297 | +如果你将基线策略或限制策略绑定到 `system:serviceaccounts` 组来设置集群默认值, |
| 298 | +然后[使用 ServiceAccount 绑定](/zh-cn/docs/concepts/policy/pod-security-policy/#run-another-pod) |
| 299 | +在某些命名空间下根据需要制定更宽松的策略,就可以避免许多 PSP 陷阱并轻松迁移到 PSP 替代策略。 |
| 300 | +如果你的需求比这复杂得多,那么建议将精力花在采用比上面提到的功能更全的某个外部准入控制器。 |
| 301 | + |
| 302 | +<!-- |
| 303 | +We’re dedicated to making Kubernetes the best container orchestration tool we can, |
| 304 | +and sometimes that means we need to remove longstanding features to make space for better things to come. |
| 305 | +When that happens, the Kubernetes deprecation policy ensures you have plenty of time to plan your next move. |
| 306 | +In the case of PodSecurityPolicy, several options are available to suit a range of needs and use cases. |
| 307 | +Start planning ahead now for PSP’s eventual removal, and please consider contributing to its replacement! Happy securing! |
| 308 | +--> |
| 309 | +我们致力于使 Kubernetes 成为我们可以做到的最好的容器编排工具, |
| 310 | +有时这意味着我们需要删除长期存在的功能,以便为更好的特性腾出空间。 |
| 311 | +发生这种情况时,Kubernetes 弃用策略可确保你有足够的时间来计划下一步行动。 |
| 312 | +对于 PodSecurityPolicy,有几个选项可以满足一系列需求和用例。 |
| 313 | +现在就开始为 PSP 的最终移除提前制定计划,请考虑为它的替换做出贡献!<!--omitted "Happy securing!" as suggested--> |
| 314 | + |
| 315 | +<!-- |
| 316 | +**Acknowledgment:** It takes a wonderful group to make wonderful software. |
| 317 | +Thanks are due to everyone who has contributed to the PSP replacement effort, |
| 318 | +especially (in alphabetical order) Tim Allclair, Ian Coldwater, and Jordan Liggitt. |
| 319 | +It’s been a joy to work with y’all on this. |
| 320 | +--> |
| 321 | +**致谢:** 研发优秀的软件需要优秀的团队。感谢为 PSP 替代工作做出贡献的所有人, |
| 322 | +尤其是(按字母顺序)Tim Allclair、Ian Coldwater 和 Jordan Liggitt。 |
| 323 | +和你们共事非常愉快。 |
0 commit comments