Skip to content

Commit 306bb81

Browse files
authored
Merge pull request #40659 from Zhuzhenghao/1.27/extensible-admission-controllers
[zh] sync 1.27 extensible admission controllers
2 parents d3c0cd5 + 3ba3ac3 commit 306bb81

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

content/zh-cn/docs/reference/access-authn-authz/extensible-admission-controllers.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,151 @@ The `matchPolicy` for an admission webhooks defaults to `Equivalent`.
10591059
-->
10601060
准入 Webhook 所用的 `matchPolicy` 默认为 `Equivalent`。
10611061

1062+
<!--
1063+
### Matching requests: `matchConditions`
1064+
-->
1065+
### 匹配请求:`matchConditions` {#matching-requests-matchConditions}
1066+
1067+
{{< feature-state state="alpha" for_k8s_version="v1.27" >}}
1068+
1069+
{{< note >}}
1070+
<!--
1071+
Use of `matchConditions` requires the [featuregate](/docs/reference/command-line-tools-reference/feature-gates/)
1072+
`AdmissionWebhookMatchConditions` to be explicitly enabled on the kube-apiserver before this feature can be used.
1073+
-->
1074+
使用 `matchConditions` 需要先在 kube-apiserver
1075+
上明确启用[功能门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
1076+
`AdmissionWebhookMatchConditions`,然后才能使用此功能。
1077+
{{< /note >}}
1078+
1079+
<!--
1080+
You can define _match conditions_for webhooks if you need fine-grained request filtering. These
1081+
conditions are useful if you find that match rules, `objectSelectors` and `namespaceSelectors` still
1082+
doesn't provide the filtering you want over when to call out over HTTP. Match conditions are
1083+
[CEL expressions](/docs/reference/using-api/cel/). All match conditions must evaluate to true for the
1084+
webhook to be called.
1085+
-->
1086+
如果你需要细粒度地过滤请求,你可以为 Webhook 定义**匹配条件**。
1087+
如果你发现匹配规则、`objectSelectors` 和 `namespaceSelectors` 仍然不能提供你想要的何时进行 HTTP
1088+
调用的过滤条件,那么添加这些条件会很有用。
1089+
匹配条件是 [CEL 表达式](/docs/reference/using-api/cel/)。
1090+
所有匹配条件都必须为 true 才能调用 Webhook。
1091+
1092+
<!--
1093+
Here is an example illustrating a few different uses for match conditions:
1094+
-->
1095+
以下是一个例子,说明了匹配条件的几种不同用法:
1096+
1097+
```yaml
1098+
apiVersion: admissionregistration.k8s.io/v1
1099+
kind: ValidatingWebhookConfiguration
1100+
webhooks:
1101+
- name: my-webhook.example.com
1102+
matchPolicy: Equivalent
1103+
rules:
1104+
- operations: ['CREATE','UPDATE']
1105+
apiGroups: ['*']
1106+
apiVersions: ['*']
1107+
resources: ['*']
1108+
failurePolicy: 'Ignore' # 失败时继续处理请求但跳过 Webhook (可选值)
1109+
sideEffects: None
1110+
clientConfig:
1111+
service:
1112+
namespace: my-namespace
1113+
name: my-webhook
1114+
caBundle: '<omitted>'
1115+
matchConditions:
1116+
- name: 'exclude-leases' # 每个匹配条件必须有唯一的名称
1117+
expression: '!(request.resource.group == "coordination.k8s.io" && request.resource.resource == "leases")' # 匹配非租约资源
1118+
- name: 'exclude-kubelet-requests'
1119+
expression: '!("system:nodes" in request.userInfo.groups)' # 匹配非节点用户发出的请求
1120+
- name: 'rbac' # 跳过 RBAC 请求,该请求将由第二个 Webhook 处理
1121+
expression: 'request.resource.group != "rbac.authorization.k8s.io"'
1122+
1123+
# 这个示例演示了如何使用 “authorizer”。
1124+
# 授权检查比简单的表达式更复杂,因此在这个示例中,使用第二个 Webhook 来针对 RBAC 请求进行处理。
1125+
# 两个 Webhook 都可以由同一个端点提供服务。
1126+
- name: rbac.my-webhook.example.com
1127+
matchPolicy: Equivalent
1128+
rules:
1129+
- operations: ['CREATE','UPDATE']
1130+
apiGroups: ['rbac.authorization.k8s.io']
1131+
apiVersions: ['*']
1132+
resources: ['*']
1133+
failurePolicy: 'Fail' # 失败时拒绝请求 (默认值)
1134+
sideEffects: None
1135+
clientConfig:
1136+
service:
1137+
namespace: my-namespace
1138+
name: my-webhook
1139+
caBundle: '<omitted>'
1140+
matchConditions:
1141+
- name: 'breakglass'
1142+
# 跳过由授权给 “breakglass” 的用户在这个 Webhook 上发起的请求。
1143+
# “breakglass” API 不需要在这个检查之外存在。
1144+
expression: '!authorizer.group("admissionregistration.k8s.io").resource("validatingwebhookconfigurations").name("my-webhook.example.com").check("breakglass").allowed()'
1145+
```
1146+
1147+
<!--
1148+
Match conditions have access to the following CEL variables:
1149+
-->
1150+
匹配条件可以访问以下 CEL 变量:
1151+
1152+
<!--
1153+
- `object` - The object from the incoming request. The value is null for DELETE requests. The object
1154+
version may be converted based on the [matchPolicy](#matching-requests-matchpolicy).
1155+
-->
1156+
- `object` - 来自传入请求的对象。对于 DELETE 请求,该值为 null。
1157+
该对象版本可能根据 [matchPolicy](#matching-requests-matchpolicy) 进行转换。
1158+
<!--
1159+
- `oldObject` - The existing object. The value is null for CREATE requests.
1160+
-->
1161+
- `oldObject` - 现有对象。对于 CREATE 请求,该值为 null。
1162+
<!--
1163+
- `request` - The request portion of the [AdmissionReview](#request), excluding `object` and `oldObject`.
1164+
-->
1165+
- `request` - [AdmissionReview](#request) 的请求部分,不包括 object 和 oldObject。
1166+
<!--
1167+
- `authorizer` - A CEL Authorizer. May be used to perform authorization checks for the principal
1168+
(authenticated user) of the request. See
1169+
[Authz](https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz) in the Kubernetes CEL library
1170+
documentation for more details.
1171+
-->
1172+
- `authorizer` - 一个 CEL 鉴权组件。可用于对请求的主体(经过身份认证的用户)执行鉴权检查。
1173+
更多详细信息,请参阅 Kubernetes CEL 库文档中的
1174+
[Authz](https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz)。
1175+
<!--
1176+
- `authorizer.requestResource` - A shortcut for an authorization check configured with the request
1177+
resource (group, resource, (subresource), namespace, name).
1178+
-->
1179+
- `authorizer.requestResource` - 对配置的请求资源(组、资源、(子资源)、名字空间、名称)进行授权检查的快捷方式。
1180+
1181+
<!--
1182+
For more information on CEL expressions, refer to the
1183+
[Common Expression Language in Kubernetes reference](/docs/reference/using-api/cel/).
1184+
-->
1185+
了解有关 CEL 表达式的更多信息,请参阅
1186+
[Kubernetes 参考文档中的通用表达式语言](/zh-cn/docs/reference/using-api/cel/)。
1187+
1188+
<!--
1189+
In the event of an error evaluating a match condition the webhook is never called. Whether to reject
1190+
the request is determined as follows:
1191+
-->
1192+
如果在对匹配条件求值时出现错误,则不会调用 Webhook。根据以下方式确定是否拒绝请求:
1193+
1194+
<!--
1195+
1. If **any** match condition evaluated to `false` (regardless of other errors), the API server skips the webhook.
1196+
-->
1197+
1. 如果**任何一个**匹配条件求值结果为 `false`(不管其他错误),API 服务器将跳过 Webhook。
1198+
<!--
1199+
1. Otherwise:
1200+
- for [`failurePolicy: Fail`](#failure-policy), reject the request (without calling the webhook).
1201+
- for [`failurePolicy: Ignore`](#failure-policy), proceed with the request but skip the webhook.
1202+
-->
1203+
1. 否则:
1204+
- 对于 [`failurePolicy: Fail`](#failure-policy),拒绝请求(不调用 Webhook)。
1205+
- 对于 [`failurePolicy: Ignore`](#failure-policy),继续处理请求但跳过 Webhook。
1206+
10621207
<!--
10631208
### Contacting the webhook
10641209
-->

0 commit comments

Comments
 (0)