Skip to content

Commit 095743a

Browse files
authored
Merge pull request #53358 from my-git9/npe-4169
[zh-cn]sync authorization validating-admission-policy mutating-admission-policy
2 parents 7a8864f + 2a439c8 commit 095743a

File tree

3 files changed

+77
-25
lines changed

3 files changed

+77
-25
lines changed

content/zh-cn/docs/reference/access-authn-authz/authorization.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ Kubernetes 需要 REST API 请求所共有的属性,
265265
要了解有关 Node 鉴权模式的更多信息,请参阅 [Node 鉴权](/zh-cn/docs/reference/access-authn-authz/node/)
266266

267267
`Webhook`
268-
: Kubernetes 的 [Webhook 鉴权模式](/docs/reference/access-authn-authz/webhook/)用于鉴权,进行同步 HTTP 调用,
269-
阻塞请求直到远程 HTTP 服务响应查询。你可以编写自己的软件来处理这种向外调用,也可以使用生态系统中的解决方案。
268+
: Kubernetes 的 [Webhook 鉴权模式](/docs/reference/access-authn-authz/webhook/)用于鉴权,
269+
进行同步 HTTP 调用,阻塞请求直到远程 HTTP 服务响应查询。
270+
你可以编写自己的软件来处理这种向外调用,也可以使用生态系统中的解决方案。
270271

271272
<a id="warning-always-allow" />
272273

@@ -363,8 +364,8 @@ Kubernetes 允许你配置可包含多个 Webhook 的鉴权链。
363364
该链中的鉴权项可以具有明确定义的参数,这些参数可以按特定顺序检查请求,
364365
从而为你提供细粒度的控制,例如在失败时明确拒绝。
365366

366-
配置文件方法甚至允许你指定 [CEL](/zh-cn/docs/reference/using-api/cel/)规则,
367-
在将请求发送到 Webhook 之前对其进行预过滤,从而帮助你防止不必要的调用。
367+
配置文件方法甚至允许你指定 [CEL](/zh-cn/docs/reference/using-api/cel/)
368+
规则,在将请求发送到 Webhook 之前对其进行预过滤,从而帮助你防止不必要的调用。
368369
修改配置文件时,API 服务器还会自动重新加载鉴权链。
369370

370371
<!--
@@ -406,11 +407,23 @@ authorizers:
406407
# Same as setting `--authorization-webhook-cache-authorized-ttl` flag
407408
# Default: 5m0s
408409
authorizedTTL: 30s
410+
# If set to false, 'authorized' responses from the webhook are not cached
411+
# and the specified authorizedTTL is ignored/has no effect.
412+
# Same as setting `--authorization-webhook-cache-authorized-ttl` flag to `0`.
413+
# Note: Setting authorizedTTL to `0` results in its default value being used.
414+
# Default: true
415+
cacheAuthorizedRequests: true
409416
# The duration to cache 'unauthorized' responses from the webhook
410417
# authorizer.
411418
# Same as setting `--authorization-webhook-cache-unauthorized-ttl` flag
412419
# Default: 30s
413420
unauthorizedTTL: 30s
421+
# If set to false, 'unauthorized' responses from the webhook are not cached
422+
# and the specified unauthorizedTTL is ignored/has no effect.
423+
# Same as setting `--authorization-webhook-cache-unauthorized-ttl` flag to `0`.
424+
# Note: Setting unauthorizedTTL to `0` results in its default value being used.
425+
# Default: true
426+
cacheUnauthorizedRequests: true
414427
# Timeout for the webhook request
415428
# Maximum allowed is 30s.
416429
# Required, with no default.
@@ -506,10 +519,22 @@ authorizers:
506519
# 与设置 `--authorization-webhook-cache-authorized-ttl` 标志相同
507520
# 默认值:5m0s
508521
authorizedTTL: 30s
522+
# 如果设置为 false,来自 Webhook 的 'authorized' 响应不会被缓存,
523+
# 并且指定的 authorizedTTL 将被忽略/不起作用。
524+
# 等同于将 `--authorization-webhook-cache-authorized-ttl` 标志设置为 `0`
525+
# 注意:将 authorizedTTL 设置为 `0` 会导致使用其默认值。
526+
# 默认值:true
527+
cacheAuthorizedRequests: true
509528
# 缓存来自 Webhook 鉴权组件的“未授权”响应的持续时间。
510529
# 与设置 `--authorization-webhook-cache-unauthorized-ttl` 标志相同
511530
# 默认值:30s
512531
unauthorizedTTL: 30s
532+
# 如果设置为 false,来自 webhook 的 'unauthorized' 响应不会被缓存,
533+
# 并且指定的 unauthorizedTTL 将被忽略/不起作用。
534+
# 等同于将 `--authorization-webhook-cache-unauthorized-ttl` 标志设置为 `0`
535+
# 注意:将 unauthorizedTTL 设置为 `0` 会导致使用其默认值。
536+
# 默认值:true
537+
cacheUnauthorizedRequests: true
513538
# Webhook 请求超时
514539
# 允许的最大时间为 30 秒。
515540
# 必填,没有默认值。
@@ -554,7 +579,7 @@ authorizers:
554579
# 如果请求变量中 subjectAccessReviewVersion 指定的版本是 v1beta1,
555580
# 在评估 CEL 表达式之前,内容将转换为 v1 版本。
556581
#
557-
# CEL 文档:https://kubernetes.io/docs/reference/using-api/cel/
582+
# CEL 文档:https://kubernetes.io/zh-cn/docs/reference/using-api/cel/
558583
#
559584
# 仅向 Webhook 发送资源请求
560585
- expression: has(request.resourceAttributes)
@@ -734,8 +759,8 @@ As a system administrator, you should be cautious when deploying CustomResourceD
734759
that let users make changes to the above areas. These may open privilege escalations paths.
735760
Consider the consequences of this kind of change when deciding on your authorization controls.
736761
-->
737-
作为系统管理员,在部署允许用户更改上述区域的 CustomResourceDefinitions 时应谨慎行事,这些可能会打开特权升级路径。
738-
在配置你的鉴权控制时,请考虑这种变化的后果。
762+
作为系统管理员,在部署允许用户更改上述区域的 CustomResourceDefinitions 时应谨慎行事,
763+
这些可能会打开特权升级路径。在配置你的鉴权控制时,请考虑这种变化的后果。
739764
{{< /caution >}}
740765

741766
<!--
@@ -801,7 +826,8 @@ no
801826
Similarly, to check whether a ServiceAccount named `dev-sa` in Namespace `dev`
802827
can list Pods in the Namespace `target`:
803828
-->
804-
类似地,检查名字空间 `dev` 里的 `dev-sa` 服务账户是否可以列举名字空间 `target` 里的 Pod:
829+
类似地,检查名字空间 `dev` 里的 `dev-sa` 服务账户是否可以列举名字空间
830+
`target` 里的 Pod:
805831

806832
```bash
807833
kubectl auth can-i list pods \
@@ -900,4 +926,3 @@ status:
900926
* 有关概述,请阅读[控制对 Kubernetes API 的访问](/zh-cn/docs/concepts/security/controlling-access/)
901927
* 要了解有关准入控制的更多信息,请参阅[使用准入控制器](/zh-cn/docs/reference/access-authn-authz/admission-controllers/)
902928
* 阅读更多关于 [Kubernetes 中的通用表达语言](/zh-cn/docs/reference/using-api/cel/)
903-

content/zh-cn/docs/reference/access-authn-authz/mutating-admission-policy.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,31 @@ content_type: concept
1313

1414
<!-- overview -->
1515

16-
{{< feature-state for_k8s_version="v1.32" state="alpha" >}}
16+
{{< feature-state for_k8s_version="v1.34" state="beta" >}}
1717
<!-- due to feature gate history, use manual version specification here -->
1818

1919
<!--
2020
This page provides an overview of _MutatingAdmissionPolicies_.
2121
-->
2222
本页概要介绍 **MutatingAdmissionPolicy(变更性准入策略)**
2323

24+
<!--
25+
MutatingAdmissionPolicies allow you change what happens when someone writes a change to the Kubernetes API.
26+
If you want to use declarative policies just to prevent a particular kind of change to resources (for example: protecting platform namespaces from deletion),
27+
[ValidatingAdmissionPolicy](/docs/reference/access-authn-authz/validating-admission-policy/)
28+
is
29+
a simpler and more effective alternative.
30+
31+
To use the feature, enable the `MutatingAdmissionPolicy` feature gate (which is off by default) and set `--runtime-config=admissionregistration.k8s.io/v1beta1=true` on the kube-apiserver.
32+
-->
33+
MutatingAdmissionPolicies 允许你在有人向 Kubernetes API 写入变更时修改发生的操作。
34+
如果你只想使用声明式策略来阻止对资源的某种更改(例如:保护平台命名空间不被删除),
35+
[ValidatingAdmissionPolicy](/zh-cn/docs/reference/access-authn-authz/validating-admission-policy/)
36+
是更简单且更有效的替代方案。
37+
38+
要使用此特性,需要启用 `MutatingAdmissionPolicy` 特性门控(默认是关闭的),
39+
并在 kube-apiserver 上设置 `--runtime-config=admissionregistration.k8s.io/v1beta1=true`
40+
2441
<!-- body -->
2542

2643
<!--
@@ -46,7 +63,8 @@ that can be parameterized and scoped to resources as needed by cluster administr
4663
变更操作可以通过使用[服务器端应用合并策略](/zh-cn/docs/reference/using-api/server-side-apply/#merge-strategy)所合并的**应用配置**来定义,
4764
也可以使用 [JSON 补丁](https://jsonpatch.com/)来定义。
4865

49-
变更性准入策略的可配置能力很强,策略的编写者可以根据集群管理员的需要,定义参数化的策略以及限定到某类资源的策略。
66+
变更性准入策略的可配置能力很强,策略的编写者可以根据集群管理员的需要,
67+
定义参数化的策略以及限定到某类资源的策略。
5068

5169
<!--
5270
## What resources make a policy
@@ -128,7 +146,7 @@ passing through admission.
128146
-->
129147
`.spec.mutations` 字段由一系列表达式组成,这些表达式求值后将形成资源补丁。
130148
所生成的补丁可以是[应用配置](#patch-type-apply-configuration)[JSON 补丁](#patch-type-json-patch)
131-
你不能将 mutations 设置为空列表。在对所有表达式求值后,API 服务器将所得到的变更应用到正在通过准入阶段的资源。
149+
你不能将 `mutations` 设置为空列表。在对所有表达式求值后,API 服务器将所得到的变更应用到正在通过准入阶段的资源。
132150

133151
<!--
134152
To configure a mutating admission policy for use in a cluster, a binding is
@@ -245,8 +263,8 @@ CEL 表达式可以访问以 CEL 变量组织起来的 API 请求内容及一些
245263
The `apiVersion`, `kind`, `metadata.name`, `metadata.generateName` and `metadata.labels` are always accessible from the root of the
246264
object. No other metadata properties are accessible.
247265
-->
248-
`apiVersion``kind``metadata.name``metadata.generateName` `metadata.labels`
249-
始终可以从对象的根进行访问。其他元数据属性不可访问。
266+
`apiVersion``kind``metadata.name``metadata.generateName`
267+
`metadata.labels` 始终可以从对象的根进行访问。其他元数据属性不可访问。
250268

251269
#### `JSONPatch` {#patch-type-json-patch}
252270

@@ -299,7 +317,8 @@ To define a JSON object for the patch operation `value`, use CEL `Object` types.
299317
<!--
300318
To use strings containing '/' and '~' as JSONPatch path keys, use `jsonpatch.escapeKey()`. For example:
301319
-->
302-
要使用包含 '/' 和 '~' 的字符串作为 JSONPatch 路径键,可以使用 `jsonpatch.escapeKey()`。例如:
320+
要使用包含 '/' 和 '~' 的字符串作为 JSONPatch 路径键,可以使用
321+
`jsonpatch.escapeKey()`。例如:
303322

304323
```
305324
[
@@ -347,8 +366,8 @@ CEL expressions have access to the contents of the API request, organized into C
347366
-->
348367
CEL 表达式可以访问以 CEL 变量组织的 API 请求的内容及一些其他有用变量:
349368

350-
- `object` - 来自传入请求的对象。对于 DELETE 请求,取值为 null。
351-
- `oldObject` - 现有对象。对于 CREATE 请求,取值为 null。
369+
- `object` - 来自传入请求的对象。对于 DELETE 请求,取值为 `null`
370+
- `oldObject` - 现有对象。对于 CREATE 请求,取值为 `null`
352371
- `request` - API 请求的属性。
353372
- `params` - 正被评估的策略绑定所引用的参数资源。仅在策略具有 `paramKind` 时填充。
354373
<!--
@@ -360,7 +379,7 @@ CEL 表达式可以访问以 CEL 变量组织的 API 请求的内容及一些其
360379
- `authorizer.requestResource` - A CEL ResourceCheck constructed from the `authorizer` and configured with the
361380
request resource.
362381
-->
363-
- `namespaceObject` - 传入对象所属的命名空间对象。对于集群范围的资源,取值为 null。
382+
- `namespaceObject` - 传入对象所属的命名空间对象。对于集群范围的资源,取值为 `null`
364383
- `variables` - 组合变量的映射,包含从变量名称到其惰性评估值的映射。
365384
例如,名为 `foo` 的变量可以以 `variables.foo` 的形式访问。
366385
- `authorizer` - 一个 CEL 鉴权组件。可用于对请求的主体(用户或服务账户)执行鉴权检查。

content/zh-cn/docs/reference/access-authn-authz/validating-admission-policy.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ must be defined for a policy to have an effect.
7979
If a `ValidatingAdmissionPolicy` does not need to be configured via parameters, simply leave
8080
`spec.paramKind` in `ValidatingAdmissionPolicy` not specified.
8181
-->
82-
至少要定义一个 `ValidatingAdmissionPolicy` 和一个相对应的 `ValidatingAdmissionPolicyBinding` 才能使策略生效。
82+
至少要定义一个 `ValidatingAdmissionPolicy` 和一个相对应的 `ValidatingAdmissionPolicyBinding`
83+
才能使策略生效。
8384

8485
如果 `ValidatingAdmissionPolicy` 不需要参数配置,不设置 `ValidatingAdmissionPolicy` 中的
8586
`spec.paramKind` 即可。
@@ -92,7 +93,8 @@ with great caution. The following describes how to quickly experiment with Valid
9293
-->
9394
## 开始使用验证准入策略 {#getting-started-with-validating-admission-policy}
9495

95-
验证准入策略是集群控制平面的一部分。你应该非常谨慎地编写和部署它们。下面介绍如何快速试验验证准入策略。
96+
验证准入策略是集群控制平面的一部分,你应该非常谨慎地编写和部署它们。
97+
下面介绍如何快速试验验证准入策略。
9698

9799
<!--
98100
### Creating a ValidatingAdmissionPolicy
@@ -619,11 +621,17 @@ CEL 表达式可以访问按 CEL 变量来组织的 Admission 请求/响应的
619621
- `authorizer.requestResource` - 针对请求资源(组、资源、(子资源)、命名空间、名称)所配置的鉴权检查的快捷方式。
620622

621623
<!--
622-
The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from
623-
the root of the object. No other metadata properties are accessible.
624+
In CEL expressions, variables like `object` and `oldObject` are strongly-typed.
625+
You can access any field in the object's schema, such as `object.metadata.labels` and fields in `spec`.
626+
627+
For any Kubernetes object, including schemaless Custom Resources, CEL guarantees access to a minimal set of properties:
628+
`apiVersion`, `kind`, `metadata.name`, and `metadata.generateName`.
624629
-->
625-
总是可以从对象的根访问的属性有 `apiVersion``kind``metadata.name``metadata.generateName`
626-
其他元数据属性不能访问。
630+
在 CEL 表达式中,像 `object``oldObject` 这样的变量是强类型的。
631+
你可以访问对象模式中的任意字段,例如 `object.metadata.labels``spec` 中的字段。
632+
633+
对于任意 Kubernetes 对象,包括无模式的自定义资源,CEL 保证至少可以访问以下一组属性:
634+
`apiVersion``kind``metadata.name``metadata.generateName`
627635

628636
<!--
629637
Equality on arrays with list type of 'set' or 'map' ignores element order, i.e. [1, 2] == [2, 1].
@@ -886,7 +894,7 @@ For example, given the following policy definition:
886894
<!--
887895
The status will yield the following information:
888896
-->
889-
status 字段将提供以下信息:
897+
`status` 字段将提供以下信息:
890898

891899
```yaml
892900
status:

0 commit comments

Comments
 (0)