diff --git a/content/zh/docs/reference/access-authn-authz/abac.md b/content/zh/docs/reference/access-authn-authz/abac.md index 789e1cd3db..f025efb881 100644 --- a/content/zh/docs/reference/access-authn-authz/abac.md +++ b/content/zh/docs/reference/access-authn-authz/abac.md @@ -38,7 +38,7 @@ Attribute-based access control (ABAC) defines an access control paradigm whereby To enable `ABAC` mode, specify `--authorization-policy-file=SOME_FILENAME` and `--authorization-mode=ABAC` on startup. The file format is [one JSON object per line](http://jsonlines.org/). There -should be no enclosing list or map, just one map per line. +should be no enclosing list or map, only one map per line. Each line is a "policy object", where each such object is a map with the following properties: @@ -73,7 +73,7 @@ properties: 基于 `ABAC` 模式,可以这样指定策略文件 `--authorization-policy-file=SOME_FILENAME`。 -此文件格式是 [JSON Lines](https://jsonlines.org/),不应存在封闭的列表或映射,每行一个映射。 +此文件格式是 [JSON Lines](https://jsonlines.org/),不应存在外层的列表或映射,每行应只有一个映射。 每一行都是一个策略对象,策略对象是具有以下属性的映射: @@ -258,7 +258,7 @@ Kubectl 使用 api-server 的 `/api` 和 `/apis` 端点来发现服务资源类 ``` -[完整文件示例](https://releases.k8s.io/{{< param "githubbranch" >}}/pkg/auth/authorizer/abac/example_policy_file.jsonl) +[完整文件示例](https://releases.k8s.io/{{< param "fullversion" >}}/pkg/auth/authorizer/abac/example_policy_file.jsonl) ## 服务帐户的快速说明 diff --git a/content/zh/docs/reference/access-authn-authz/admission-controllers.md b/content/zh/docs/reference/access-authn-authz/admission-controllers.md index d7d612af16..7007e9bc23 100644 --- a/content/zh/docs/reference/access-authn-authz/admission-controllers.md +++ b/content/zh/docs/reference/access-authn-authz/admission-controllers.md @@ -1171,8 +1171,30 @@ PodNodeSelector 允许 Pod 强制在特定标签的节点上运行。 另请参阅 PodTolerationRestriction 准入插件,该插件可防止 Pod 在特定污点的节点上运行。 {{< /note >}} +### PodSecurity {#podsecurity} + +{{< feature-state for_k8s_version="v1.22" state="alpha" >}} + + +这是下节已被废弃的 [PodSecurityPolicy](#podsecuritypolicy) 准入控制器的替代品。 +此准入控制器负责在创建和修改 Pod 时根据请求的安全上下文和 +[Pod 安全标准](/zh/docs/concepts/security/pod-security-standards/) +来确定是否可以执行请求。 + +更多信息请参阅 [Pod 安全性准入控制器](/zh/docs/concepts/security/pod-security-admission/)。 + ### PodSecurityPolicy {#podsecuritypolicy} +{{< feature-state for_k8s_version="v1.21" state="deprecated" >}} + +输出类似于: + ``` yes ``` @@ -231,6 +235,10 @@ yes ```shell kubectl auth can-i create deployments --namespace prod ``` + + +输出类似于: + ``` no ``` @@ -246,16 +254,39 @@ to determine what action other users can perform. ```bash kubectl auth can-i list secrets --namespace dev --as dave ``` + + +输出类似于: + ``` no ``` + +类似地,检查名字空间 `dev` 里的 `dev-sa` 服务账号是否可以列举名字空间 `target` 里的 Pod: + +```bash +kubectl auth can-i list pods \ + --namespace target \ + --as system:serviceaccount:dev:dev-sa +``` + + +输出类似于: + +``` +yes +``` + -## 通过创建 Pod 提升权限 +## 通过创建或编辑工作负载提升权限 {#privilege-escalation-via-pod-creation} -能够在名字空间中创建 Pod 的用户可能会提升其在该名字空间内的权限。 -他们可以创建在该名字空间内访问其权限的 Pod。 -他们可以创建 Pod 访问用户自己无法读取的 Secret,或者在具有不同/更高权限的 -服务帐户下运行的 Pod 。 +能够在名字空间中创建或者编辑 Pod 的用户, +无论是直接操作还是通过[控制器](/zh/docs/concepts/architecture/controller/)(例如,一个 Operator)来操作, +都可以提升他们在该名字空间内的权限。 {{< caution >}} -系统管理员在授予对 Pod 创建的访问权限时要小心。 -被授予在名字空间中创建 Pod(或创建 Pod 的控制器)的权限的用户可以: -读取名字空间中的所有 Secret;读取名字空间中的所有 ConfigMap; -并模拟名字空间中的任意服务账号并执行账号可以执行的任何操作。 -无论采用何种鉴权方式,这都适用。 +系统管理员在授予对工作负载的创建或编辑的权限时要小心。 +关于这些权限如何被误用的详细信息请参阅 +[提升途径](#escalation-paths) {{< /caution >}} + +### 提升途径 {#escalation-paths} +- 挂载该名字空间内的任意 Secret + - 可以用来访问其他工作负载专用的 Secret + - 可以用来获取权限更高的服务账号的令牌 +- 使用该名字空间内的任意服务账号 + - 可以用另一个工作负载的身份来访问 Kubernetes API(伪装) + - 可以执行该服务账号的任意特权操作 +- 挂载该名字空间里其他工作负载专用的 ConfigMap + - 可以用来获取其他工作负载专用的信息,例如数据库主机名。 +- 挂载该名字空间里其他工作负载的卷 + - 可以用来获取其他工作负载专用的信息,并且更改它。 + +{{< caution >}} + +系统管理员在部署改变以上部分的 CRD 的时候要小心。 +它们可能会打开权限提升的途径。 +在决定你的 RBAC 控制时应该考虑这方面的问题。 +{{< /caution >}} + + ## {{% heading "whatsnext" %}} @@ -159,8 +160,9 @@ ClusterRole 可以和 Role 相同完成授权。 * 集群范围资源(比如 {{< glossary_tooltip text="节点(Node)" term_id="node" >}}) * 非资源端点(比如 `/healthz`) -* 跨名字空间访问的名字空间作用域的资源(如 Pods),比如,你可以使用 - ClusterRole 来允许某特定用户执行 `kubectl get pods --all-namespaces` +* 跨名字空间访问的名字空间作用域的资源(如 Pods) + + 比如,你可以使用 ClusterRole 来允许某特定用户执行 `kubectl get pods --all-namespaces` -你不能针对 `create` 或者 `deletecollection` 请求来实施 resourceName 限制。 -对于 `create` 操作而言,这是因为在鉴权时还不知道对象名称。 +你不能使用资源名字来限制 `create` 或者 `deletecollection` 请求。 +对于 `create` 请求而言,这是因为在鉴权时可能还不知道新对象的名字。 +如果你使用 resourceName 来限制 `list` 或者 `watch` 请求, +客户端必须在它们的 `list` 或者 `watch` 请求里包含一个与指定的 resourceName 匹配的 `metadata.name` 字段选择器。 +例如,`kubectl get configmaps --field-selector=metadata.name=my-configmap` {{< /note >}} 允许管理员访问权限,旨在使用 RoleBinding 在名字空间内执行授权。 + 如果在 RoleBinding 中使用,则可授予对名字空间中的大多数资源的读/写权限, 包括创建角色和角色绑定的能力。 -但是它不允许对资源配额或者名字空间本身进行写操作。 +此角色不允许对资源配额或者名字空间本身进行写操作。 +此角色也不允许对 Kubernetes v1.22+ 创建的 Endpoints 进行写操作。 +更多信息参阅[“Endpoints 写权限”小节](#write-access-for-endpoints)。 @@ -1071,12 +1084,17 @@ Allows read/write access to most objects in a namespace. This role does not allow viewing or modifying roles or role bindings. However, this role allows accessing Secrets and running Pods as any ServiceAccount in the namespace, so it can be used to gain the API access levels of any ServiceAccount in -the namespace. +the namespace. This role also does not allow write access to Endpoints in +clusters created using Kubernetes v1.22+. More information is available in the +["Write Access for Endpoints" section](#write-access-for-endpoints). --> 允许对名字空间的大多数对象进行读/写操作。 + 它不允许查看或者修改角色或者角色绑定。 不过,此角色可以访问 Secret,以名字空间中任何 ServiceAccount 的身份运行 Pods, 所以可以用来了解名字空间内所有服务账户的 API 访问级别。 +此角色也不允许对 Kubernetes v1.22+ 创建的 Endpoints 进行写操作。 +更多信息参阅[“Endpoints 写操作”小节](#write-access-for-endpoints)。 @@ -1327,10 +1345,10 @@ Role for the node- 无 允许访问大部分 -动态卷驱动 +动态卷驱动 所需要的资源。 @@ -1957,6 +1975,40 @@ In order from most secure to least secure, the approaches are: --group=system:serviceaccounts ``` + +## Endpoints 写权限 {#write-access-for-endpoints} + +在 Kubernetes v1.22 之前版本创建的集群里, +"edit" 和 "admin" 聚合角色包含对 Endpoints 的写权限。 +作为 [CVE-2021-25740](https://github.com/kubernetes/kubernetes/issues/103675) 的缓解措施, +此访问权限不包含在 Kubernetes 1.22 以及更高版本集群的聚合角色里。 + +升级到 Kubernetes v1.22 版本的现有集群不会包括此变化。 +[CVE 公告](https://github.com/kubernetes/kubernetes/issues/103675) +包含了在现有集群里限制此访问权限的指引。 + +如果你希望在新集群的聚合角色里保留此访问权限,你可以创建下面的 ClusterRole: + +{{< codenew file="access/endpoints-aggregated.yaml" >}} +