Skip to content

Commit ed864a5

Browse files
committed
[zh] Sync reference: validating-admission-policy.md
1 parent a4a8dae commit ed864a5

File tree

10 files changed

+71
-53
lines changed

10 files changed

+71
-53
lines changed

content/zh-cn/docs/reference/access-authn-authz/service-accounts-admin.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Kubernetes 区分用户账号和服务账号的概念,主要基于以下原因
109109
<!--
110110
## Bound service account tokens
111111
-->
112-
## 绑定的服务账户令牌 {#bound-service-account-tokens}
112+
## 绑定的服务账号令牌 {#bound-service-account-tokens}
113113

114114
<!--
115115
ServiceAccount tokens can be bound to API objects that exist in the kube-apiserver.
@@ -279,6 +279,27 @@ Here's an example of how that looks for a launched Pod:
279279

280280
以下示例演示如何查找已启动的 Pod:
281281

282+
<!--
283+
```yaml
284+
...
285+
- name: kube-api-access-<random-suffix>
286+
projected:
287+
sources:
288+
- serviceAccountToken:
289+
path: token # must match the path the app expects
290+
- configMap:
291+
items:
292+
- key: ca.crt
293+
path: ca.crt
294+
name: kube-root-ca.crt
295+
- downwardAPI:
296+
items:
297+
- fieldRef:
298+
apiVersion: v1
299+
fieldPath: metadata.namespace
300+
path: namespace
301+
```
302+
-->
282303
```yaml
283304
...
284305
- name: kube-api-access-<随机后缀>
@@ -497,7 +518,7 @@ ensures a ServiceAccount named "default" exists in every active namespace.
497518
-->
498519
## 控制平面细节 {#control-plane-details}
499520

500-
### ServiceAccount 控制器 {#serviceaccount-controller}
521+
### ServiceAccount 控制器 {#serviceaccount-controller}
501522

502523
ServiceAccount 控制器管理名字空间内的 ServiceAccount,
503524
并确保每个活跃的名字空间中都存在名为 `default` 的 ServiceAccount。
@@ -595,7 +616,7 @@ it does the following when a Pod is created:
595616
<!--
596617
### Legacy ServiceAccount token tracking controller
597618
-->
598-
### 传统 ServiceAccount 令牌追踪控制器
619+
### 传统 ServiceAccount 令牌追踪控制器 {#legacy-serviceaccount-token-tracking-controller}
599620

600621
{{< feature-state feature_gate_name="LegacyServiceAccountTokenTracking" >}}
601622

@@ -607,12 +628,12 @@ account tokens began to be monitored by the system.
607628
-->
608629
此控制器在 `kube-system` 命名空间中生成名为
609630
`kube-apiserver-legacy-service-account-token-tracking` 的 ConfigMap。
610-
这个 ConfigMap 记录了系统开始监视传统服务账户令牌的时间戳
631+
这个 ConfigMap 记录了系统开始监视传统服务账号令牌的时间戳
611632

612633
<!--
613634
### Legacy ServiceAccount token cleaner
614635
-->
615-
### 传统 ServiceAccount 令牌清理器
636+
### 传统 ServiceAccount 令牌清理器 {#legacy-serviceaccount-token-cleaner}
616637

617638
{{< feature-state feature_gate_name="LegacyServiceAccountTokenCleanUp" >}}
618639

@@ -713,6 +734,9 @@ kubelet 确保该卷包含允许容器作为正确 ServiceAccount 进行身份
713734

714735
以下示例演示如何查找已启动的 Pod:
715736

737+
<!--
738+
# decimal equivalent of octal 0644
739+
-->
716740
```yaml
717741
...
718742
- name: kube-api-access-<random-suffix>
@@ -871,6 +895,9 @@ Otherwise, first find the Secret for the ServiceAccount.
871895
-->
872896
否则,先找到 ServiceAccount 所用的 Secret。
873897

898+
<!--
899+
# This assumes that you already have a namespace named 'examplens'
900+
-->
874901
```shell
875902
# 此处假设你已有一个名为 'examplens' 的名字空间
876903
kubectl -n examplens get serviceaccount/example-automated-thing -o yaml

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

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ content_type: concept
1818
<!--
1919
This page provides an overview of Validating Admission Policy.
2020
-->
21-
2221
本页面提供验证准入策略(Validating Admission Policy)的概述。
2322

2423
<!-- body -->
@@ -63,7 +62,6 @@ A policy is generally made up of three resources:
6362
A native type such as ConfigMap or a CRD defines the schema of a parameter resource.
6463
`ValidatingAdmissionPolicy` objects specify what Kind they are expecting for their parameter resource.
6564
-->
66-
6765
- `ValidatingAdmissionPolicy` 描述策略的抽象逻辑(想想看:“这个策略确保一个特定标签被设置为一个特定值”)。
6866

6967
- 一个 `ValidatingAdmissionPolicyBinding` 将上述资源联系在一起,并提供作用域。
@@ -86,22 +84,12 @@ If a `ValidatingAdmissionPolicy` does not need to be configured via parameters,
8684
如果 `ValidatingAdmissionPolicy` 不需要参数配置,不设置 `ValidatingAdmissionPolicy` 中的
8785
`spec.paramKind` 即可。
8886

89-
## {{% heading "prerequisites" %}}
90-
91-
<!--
92-
- Ensure the `ValidatingAdmissionPolicy` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled.
93-
- Ensure that the `admissionregistration.k8s.io/v1beta1` API is enabled.
94-
-->
95-
- 确保 `ValidatingAdmissionPolicy` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)被启用。
96-
- 确保 `admissionregistration.k8s.io/v1beta1` API 被启用。
97-
9887
<!--
9988
## Getting Started with Validating Admission Policy
10089
10190
Validating Admission Policy is part of the cluster control-plane. You should write and deploy them
10291
with great caution. The following describes how to quickly experiment with Validating Admission Policy.
10392
-->
104-
10593
## 开始使用验证准入策略 {#getting-started-with-validating-admission-policy}
10694

10795
验证准入策略是集群控制平面的一部分。你应该非常谨慎地编写和部署它们。下面介绍如何快速试验验证准入策略。
@@ -179,9 +167,9 @@ The supported `validationActions` are:
179167
as a [warning](/blog/2020/09/03/warnings/).
180168
- `Audit`: Validation failure is included in the audit event for the API request.
181169
-->
182-
- `Deny`: 验证失败会导致请求被拒绝。
183-
- `Warn`: 验证失败会作为[警告](/blog/2020/09/03/warnings/)报告给请求客户端。
184-
- `Audit`: 验证失败会包含在 API 请求的审计事件中。
170+
- `Deny`验证失败会导致请求被拒绝。
171+
- `Warn`验证失败会作为[警告](/zh-cn/blog/2020/09/03/warnings/)报告给请求客户端。
172+
- `Audit`验证失败会包含在 API 请求的审计事件中。
185173

186174
<!--
187175
For example, to both warn clients about a validation failure and to audit the
@@ -199,6 +187,7 @@ API response body and the HTTP warning headers.
199187
-->
200188
`Deny` 和 `Warn` 不能一起使用,因为这种组合会不必要地将验证失败重复输出到
201189
API 响应体和 HTTP 警告头中。
190+
202191
<!--
203192
A `validation` that evaluates to false is always enforced according to these
204193
actions. Failures defined by the `failurePolicy` are enforced
@@ -211,9 +200,9 @@ otherwise the failures are ignored.
211200

212201
<!--
213202
See [Audit Annotations: validation failures](/docs/reference/labels-annotations-taints/audit-annotations/#validation-policy-admission-k8s-io-validation-failure) for more details about the validation failure audit annotation.
214-
-->
215-
有关验证失败审计注解的详细信息,请参见
216-
[审计注解:验证失败](/zh-cn/docs/reference/labels-annotations-taints/audit-annotations/#validation-policy-admission-k8s-io-validation_failure)。
203+
-->
204+
有关验证失败审计注解的详细信息,
205+
请参见[审计注解:验证失败](/zh-cn/docs/reference/labels-annotations-taints/audit-annotations/#validation-policy-admission-k8s-io-validation_failure)。
217206

218207
<!--
219208
### Parameter resources
@@ -225,7 +214,7 @@ and then a policy binding ties a policy by name (via policyName) to a particular
225214
If parameter configuration is needed, the following is an example of a ValidatingAdmissionPolicy
226215
with parameter configuration.
227216
-->
228-
### 参数资源
217+
### 参数资源 {#parameter-resources}
229218

230219
参数资源允许策略配置与其定义分开。
231220
一个策略可以定义 paramKind,给出参数资源的 GVK,
@@ -394,7 +383,9 @@ CEL 提供了 `has()` 方法,它检查传递给它的键是否存在。CEL 还
394383
395384
结合这两者,我们可以提供一种验证可选参数的方法:
396385
397-
`!has(params.optionalNumber) || (params.optionalNumber >= 5 && params.optionalNumber <= 10)`
386+
```
387+
!has(params.optionalNumber) || (params.optionalNumber >= 5 && params.optionalNumber <= 10)
388+
```
398389
399390
<!--
400391
Here, we first check that the optional parameter is present with `!has(params.optionalNumber)`.
@@ -500,7 +491,7 @@ admission policy are handled. Allowed values are `Ignore` or `Fail`.
500491
501492
Note that the `failurePolicy` is defined inside `ValidatingAdmissionPolicy`:
502493
-->
503-
### 失效策略
494+
### 失效策略 {#failure-policy}
504495
505496
`failurePolicy` 定义了如何处理错误配置和准入策略的 CEL 表达式取值为 error 的情况。
506497
@@ -520,7 +511,14 @@ Note that the `failurePolicy` is defined inside `ValidatingAdmissionPolicy`:
520511
To learn more, see the [CEL language specification](https://github.com/google/cel-spec)
521512
CEL expressions have access to the contents of the Admission request/response, organized into CEL
522513
variables as well as some other useful variables:
514+
-->
515+
### 检查表达式 {#validation-expression}
516+
517+
`spec.validations[i].expression` 代表将使用 CEL 来计算表达式。
518+
要了解更多信息,请参阅 [CEL 语言规范](https://github.com/google/cel-spec)。
519+
CEL 表达式可以访问按 CEL 变量来组织的 Admission 请求/响应的内容,以及其他一些有用的变量 :
523520
521+
<!--
524522
- 'object' - The object from the incoming request. The value is null for DELETE requests.
525523
- 'oldObject' - The existing object. The value is null for CREATE requests.
526524
- 'request' - Attributes of the [admission request](/docs/reference/config-api/apiserver-admission.v1/#admission-k8s-io-v1-AdmissionRequest).
@@ -533,12 +531,6 @@ variables as well as some other useful variables:
533531
- `authorizer.requestResource` - A shortcut for an authorization check configured with the request
534532
resource (group, resource, (subresource), namespace, name).
535533
-->
536-
### 检查表达式
537-
538-
`spec.validations[i].expression` 代表将使用 CEL 来计算表达式。
539-
要了解更多信息,请参阅 [CEL 语言规范](https://github.com/google/cel-spec)。
540-
CEL 表达式可以访问按 CEL 变量来组织的 Admission 请求/响应的内容,以及其他一些有用的变量 :
541-
542534
- 'object' - 来自传入请求的对象。对于 DELETE 请求,该值为 null。
543535
- 'oldObject' - 现有对象。对于 CREATE 请求,该值为 null。
544536
- 'request' - [准入请求](/zh-cn/docs/reference/config-api/apiserver-admission.v1/#admission-k8s-io-v1-AdmissionRequest)的属性。
@@ -567,7 +559,7 @@ Concatenation on arrays with x-kubernetes-list-type use the semantics of the lis
567559
列表类型为 "set" 或 "map" 的数组上的等价关系比较会忽略元素顺序,即 [1, 2] == [2, 1]。
568560
使用 x-kubernetes-list-type 连接数组时使用列表类型的语义:
569561
570-
- 'set': `X + Y` 执行并集,其中 `X` 中所有元素的数组位置被保留,`Y` 中不相交的元素被追加,保留其元素的偏序关系。
562+
- 'set'`X + Y` 执行并集,其中 `X` 中所有元素的数组位置被保留,`Y` 中不相交的元素被追加,保留其元素的偏序关系。
571563
- 'map':`X + Y` 执行合并,保留 `X` 中所有键的数组位置,但是当 `X` 和 `Y` 的键集相交时,其值被 `Y` 的值覆盖。
572564
`Y` 中键值不相交的元素被追加,保留其元素之间的偏序关系。
573565
@@ -662,7 +654,7 @@ the request is determined as follows:
662654
663655
For example, here is an admission policy with an audit annotation:
664656
-->
665-
### 审计注解
657+
### 审计注解 {#audit-annotations}
666658
667659
`auditAnnotations` 可用于在 API 请求的审计事件中包括审计注解。
668660
@@ -733,7 +725,7 @@ message expression must evaluate to a string.
733725
For example, to better inform the user of the reason of denial when the policy refers to a parameter,
734726
we can have the following validation:
735727
-->
736-
### 消息表达式
728+
### 消息表达式 {#message-expression}
737729
738730
为了在策略拒绝请求时返回更友好的消息,我们在 `spec.validations[i].messageExpression`
739731
中使用 CEL 表达式来构造消息。
@@ -768,8 +760,7 @@ Note that static message is validated against multi-line strings.
768760
这比静态消息 "too many replicas" 更具说明性。
769761
770762
如果既定义了消息表达式,又在 `spec.validations[i].message` 中定义了静态消息,
771-
则消息表达式优先于静态消息。
772-
但是,如果消息表达式求值失败,则将使用静态消息。
763+
则消息表达式优先于静态消息。但是,如果消息表达式求值失败,则将使用静态消息。
773764
此外,如果消息表达式求值为多行字符串,则会丢弃求值结果并使用静态消息(如果存在)。
774765
请注意,静态消息也要检查是否存在多行字符串。
775766
@@ -786,7 +777,7 @@ and an empty `status.typeChecking` means that no errors were detected.
786777
787778
For example, given the following policy definition:
788779
-->
789-
### 类型检查
780+
### 类型检查 {#type-checking}
790781
791782
创建或更新策略定义时,验证过程将解析它包含的表达式,在发现错误时报告语法错误并拒绝该定义。
792783
之后,引用的变量将根据 `spec.matchConstraints` 的匹配类型检查类型错误,包括缺少字段和类型混淆。
@@ -855,7 +846,7 @@ Type Checking has the following limitation:
855846

856847
- 没有通配符匹配。
857848
如果 `spec.matchConstraints.resourceRules` 中的任何一个 `apiGroups`、`apiVersions`
858-
或 `resources` 包含 "\*",则不会检查与 "\*" 匹配的类型。
849+
或 `resources` 包含 `"\*"`,则不会检查与 `"\*"` 匹配的类型。
859850
- 匹配的类型数量最多为 10 种。这是为了防止手动指定过多类型的策略消耗过多计算资源。
860851
按升序处理组、版本,然后是资源,忽略第 11 个及其之后的组合。
861852
- 类型检查不会以任何方式影响策略行为。即使类型检查检测到错误,策略也将继续评估。
@@ -870,7 +861,7 @@ If an expression grows too complicated, or part of the expression is reusable an
870861
you can extract some part of the expressions into variables. A variable is a named expression that can be referred later
871862
in `variables` in other expressions.
872863
-->
873-
### 变量组合
864+
### 变量组合 {#variable-composition}
874865

875866
如果表达式变得太复杂,或者表达式的一部分可重用且进行评估时计算开销较大,可以将表达式的某些部分提取为变量。
876867
变量是一个命名表达式,后期可以在其他表达式中的 `variables` 中引用。
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: admissionregistration.k8s.io/v1alpha1
1+
apiVersion: admissionregistration.k8s.io/v1
22
kind: ValidatingAdmissionPolicyBinding
33
metadata:
44
name: "demo-binding-test.example.com"
@@ -8,4 +8,4 @@ spec:
88
matchResources:
99
namespaceSelector:
1010
matchLabels:
11-
environment: test
11+
environment: test

content/zh-cn/examples/validatingadmissionpolicy/basic-example-policy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: admissionregistration.k8s.io/v1beta1
1+
apiVersion: admissionregistration.k8s.io/v1
22
kind: ValidatingAdmissionPolicy
33
metadata:
44
name: "demo-policy.example.com"

content/zh-cn/examples/validatingadmissionpolicy/binding-with-param-prod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: admissionregistration.k8s.io/v1beta1
1+
apiVersion: admissionregistration.k8s.io/v1
22
kind: ValidatingAdmissionPolicyBinding
33
metadata:
44
name: "replicalimit-binding-nontest"

content/zh-cn/examples/validatingadmissionpolicy/binding-with-param.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: admissionregistration.k8s.io/v1beta1
1+
apiVersion: admissionregistration.k8s.io/v1
22
kind: ValidatingAdmissionPolicyBinding
33
metadata:
44
name: "replicalimit-binding-test.example.com"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
apiVersion: admissionregistration.k8s.io/v1beta1
1+
apiVersion: admissionregistration.k8s.io/v1
22
kind: ValidatingAdmissionPolicy
33
spec:
44
...
5-
failurePolicy: Ignore # The default is "Fail"
5+
failurePolicy: Ignore # 默认为 "Fail"
66
validations:
77
- expression: "object.spec.xyz == params.x"

content/zh-cn/examples/validatingadmissionpolicy/policy-with-param.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: admissionregistration.k8s.io/v1beta1
1+
apiVersion: admissionregistration.k8s.io/v1
22
kind: ValidatingAdmissionPolicy
33
metadata:
44
name: "replicalimit-policy.example.com"

content/zh-cn/examples/validatingadmissionpolicy/typechecking-multiple-match.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: admissionregistration.k8s.io/v1beta1
1+
apiVersion: admissionregistration.k8s.io/v1
22
kind: ValidatingAdmissionPolicy
33
metadata:
44
name: "replica-policy.example.com"
@@ -10,6 +10,6 @@ spec:
1010
operations: ["CREATE", "UPDATE"]
1111
resources: ["deployments","replicasets"]
1212
validations:
13-
- expression: "object.replicas > 1" # should be "object.spec.replicas > 1"
13+
- expression: "object.replicas > 1" # 应为 "object.spec.replicas > 1"
1414
message: "must be replicated"
1515
reason: Invalid

content/zh-cn/examples/validatingadmissionpolicy/typechecking.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: admissionregistration.k8s.io/v1beta1
1+
apiVersion: admissionregistration.k8s.io/v1
22
kind: ValidatingAdmissionPolicy
33
metadata:
44
name: "deploy-replica-policy.example.com"
@@ -10,6 +10,6 @@ spec:
1010
operations: ["CREATE", "UPDATE"]
1111
resources: ["deployments"]
1212
validations:
13-
- expression: "object.replicas > 1" # should be "object.spec.replicas > 1"
13+
- expression: "object.replicas > 1" # 应为 "object.spec.replicas > 1"
1414
message: "must be replicated"
15-
reason: Invalid
15+
reason: Invalid

0 commit comments

Comments
 (0)