Skip to content

Commit b501dc4

Browse files
committed
Rename predicates to matchConditions
1 parent 45cd6fb commit b501dc4

File tree

1 file changed

+28
-34
lines changed
  • keps/sig-api-machinery/3716-webhook-predicates

1 file changed

+28
-34
lines changed

keps/sig-api-machinery/3716-webhook-predicates/README.md

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# KEP-3716: Admission Webhook Predicates
1+
# KEP-3716: Admission Webhook Match Conditions
22

33
<!-- toc -->
44
- [Release Signoff Checklist](#release-signoff-checklist)
@@ -70,18 +70,12 @@ Items marked with (R) are required *prior to targeting to a milestone / release*
7070

7171
## Summary
7272

73-
This KEP proposes adding "predicate" expressions to admission webhooks, as an extension to the
74-
existing `rules` to define the scope of a webhook. A `predicate` is a
73+
This KEP proposes adding "match conditions" to admission webhooks, as an extension to the
74+
existing `rules` to define the scope of a webhook. A `matchCondition` is a
7575
[CEL](https://github.com/google/cel-spec) expression that must evaluate to true for the admission
76-
request to be sent to the webhook. If a `predicate` evaluates to false, the webhook is skipped for
76+
request to be sent to the webhook. If a `matchCondition` evaluates to false, the webhook is skipped for
7777
that request (implicitly allowed).
7878

79-
<<[UNRESOLVED naming ]>>
80-
I'm not satisfied with the name `predicates` for this feature. Other ideas considered:
81-
- filters, prefilters
82-
- match{Predicates, Filters, Criteria, Expressions, Constraints, ...}
83-
<<[/UNRESOLVED]>>
84-
8579
## Motivation
8680

8781
**Reliability:** Admission webhooks continue to be an operational sore spot for many Kubernetes
@@ -122,8 +116,8 @@ Currently, if a webhook uses wildcard match rules, there is no way to filter out
122116
resources or requests from matching the wildcard. If the webhook instead enumerates every resource
123117
that should match, it must be kept up-to-date with every CRD that's added.
124118

125-
With CEL predicates, the webhook could specify wildcard match rules, and add predicates to filter
126-
out the desired resources:
119+
With CEL match conditions, the webhook could specify wildcard match rules, and add match conditions
120+
to filter out the desired resources:
127121

128122
```yaml
129123
rules:
@@ -134,7 +128,7 @@ rules:
134128
apiGroups: '*'
135129
apiVersions: '*'
136130
resources: '*'
137-
predicates:
131+
matchConditions:
138132
# Exclude leases from the webhook
139133
- expression: '!(request.resource.group == "coordination.k8s.io" && resource.resource == "leases")'
140134
```
@@ -148,10 +142,10 @@ System _resources_ can currently be exempted through a namespace or label select
148142
system components against non-system resources cannot be. For example, update pod status requests by
149143
Kubelets cannot be excluded from user webhooks intercepting all pod requests.
150144
151-
With `predicates`, a managed cluster could append system-exclusion rules to each webhook. For example:
145+
With `matchConditions`, a managed cluster could append system-exclusion rules to each webhook. For example:
152146

153147
```yaml
154-
predicates:
148+
matchConditions:
155149
# Exclude node requests from the webhook
156150
- expression: '!("system:nodes" in request.userInfo.groups)'
157151
```
@@ -172,7 +166,7 @@ that the request is within scope, and return early if it's not. This adds latenc
172166
failure point to irrelevant requests. This example requires an external integration, and thus is not
173167
a candidate for migration to CEL `ValidatingAdmissionPolicy`.
174168

175-
With predicates, the predicate expressions can check whether the request object is in-scope for the
169+
With match conditions, the expressions can check whether the request object is in-scope for the
176170
webhook:
177171

178172
```yaml
@@ -181,7 +175,7 @@ rules:
181175
apiGroups: '' # core
182176
apiVersions: '*'
183177
resources: 'pods'
184-
predicates:
178+
matchConditions:
185179
# Only include pods with an NFS volume.
186180
- expression: 'request.object.spec.volumes.exists(v, v.has(nfs))'
187181
```
@@ -200,26 +194,26 @@ predicates:
200194
### API
201195

202196
Both `ValidatingWebhook` and `MutatingWebhook` (in `admissionregistration.k8s.io`) will be updated
203-
with a new `Predicates` field:
197+
with a new `MatchConditions` field:
204198

205199
```go
206200
207201
type ValidatingWebhook struct {
208202
// ...
209203
210-
// Predicates is a list of conditions on the AdmissionRequest ('request') that must be met for a
204+
// MatchConditions is a list of conditions on the AdmissionRequest ('request') that must be met for a
211205
// request to be sent to this webhook.
212206
// +optional
213-
Predicates []Predicate `json:"predicates,omitempty"`
207+
MatchConditions []MatchCondition `json:"matchConditions,omitempty"`
214208
}
215209

216210
type MutatingWebhook struct {
217211
// ...
218-
Predicates []Predicate `json:"predicates,omitempty"`
212+
MatchConditions []MatchCondition `json:"matchConditions,omitempty"`
219213
}
220214

221-
// Predicate represents a condition which must by fulfilled for a request to be sent to a webhook.
222-
type Predicate struct {
215+
// MatchCondition represents a condition which must by fulfilled for a request to be sent to a webhook.
216+
type MatchCondition struct {
223217
// Expression represents the expression which will be evaluated by CEL.
224218
// ref: https://github.com/google/cel-spec
225219
// CEL expressions have access to the contents of the AdmissionRequest, organized into CEL variables:
@@ -257,7 +251,7 @@ type Predicate struct {
257251
}
258252
```
259253

260-
The predicate expression has access to the contents of the `AdmissionRequest` object (exposed as the
254+
The match condition expression has access to the contents of the `AdmissionRequest` object (exposed as the
261255
`request` variable), but is not given any additional information. Expressions requiring access to
262256
additional information (such as a paramater object) must be performed in the webhook, and are out of
263257
scope for this proposal.
@@ -266,35 +260,35 @@ scope for this proposal.
266260

267261
#### Security
268262

269-
**Risk: Attacker adds or changes a predicate to weaken an admission policy.**
263+
**Risk: Attacker adds or changes a match condition to weaken an admission policy.**
270264

271265
This is does not represent a new threat, as doing so would require update access to the admission
272266
registration object, and with that permission an attacker could already disable the policy through
273267
manipulating match rules, namespace selector, or object selector (or reroute the webhook entirely).
274268

275-
**Risk: Logic error in predicate expression.**
269+
**Risk: Logic error in match condition expression.**
276270

277-
Currently the predicate conditions must be encoded in the webhook backend itself. Moving the logic
271+
Currently the match conditions must be encoded in the webhook backend itself. Moving the logic
278272
into a CEL expression does not materially increase the risk of a logic bug.
279273

280274
#### Debugability
281275

282276
We do not normally log, audit, or emit an event when a webhook is out-of-scope for a request, and
283-
the same will _mostly_ be true for predicates.
277+
the same will _mostly_ be true for match conditions.
284278

285279
At [log level V(5)](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md#what-method-to-use),
286280
we will emit a log when a request that would otherwise be in-scope for a webhook is excluded for a
287-
non-matching predicate.
281+
non-matching match condition.
288282

289283
Short of increasing log verbosity, the recommended debug strategy is to capture or reproduce a
290-
relevant AdmissionRequest (for example, in a non-prod cluster disable all predicates and log the
291-
requests from a webhook). Then, manually test the predicates against the request, and iterate as
292-
necessary.
284+
relevant AdmissionRequest (for example, in a non-prod cluster disable all match conditions and log
285+
the requests from a webhook). Then, manually test the match conditions against the request, and
286+
iterate as necessary.
293287

294288
#### Performance
295289

296290
The CEL expression evaluation will leverage the same [Resource Constraints](https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/2876-crd-validation-expression-language#resource-constraints)
297-
used by CEL CRD Validation & CEL Admission Control. All the predicates for a given webhook will
291+
used by CEL CRD Validation & CEL Admission Control. All the match conditions for a given webhook will
298292
share the same resource budget.
299293

300294
<<[UNRESOLVED resource constraints ]>>
@@ -832,7 +826,7 @@ Why should this KEP _not_ be implemented?
832826

833827
### Exclusion Expressions
834828

835-
The `predicate` expression could be inverted, so that requests that match are excluded rather than
829+
The `matchCondition` expression could be inverted, so that requests that match are excluded rather than
836830
included. In this case, we would probably also want to change from requiring all expressions to
837831
match, to excluding the request if any match.
838832

0 commit comments

Comments
 (0)