|
29 | 29 | - [Namespace scoped policy binding](#namespace-scoped-policy-binding)
|
30 | 30 | - [CEL Expression Composition](#cel-expression-composition)
|
31 | 31 | - [Use Cases](#use-cases)
|
| 32 | + - [Match Conditions](#match-conditions) |
32 | 33 | - [Variables](#variables)
|
33 | 34 | - [Secondary Authz](#secondary-authz)
|
34 | 35 | - [Access to namespace metadata](#access-to-namespace-metadata)
|
@@ -1098,6 +1099,63 @@ it when necessary. For instance, if multiple validation expressions used the
|
1098 | 1099 | same expensive expression, that expression could be refactored out into a
|
1099 | 1100 | variable.
|
1100 | 1101 |
|
| 1102 | +##### Match Conditions |
| 1103 | + |
| 1104 | +Note that the syntax of the `matchConditions` resource is intended to |
| 1105 | +align with the [Admission Webhook Match Conditions KEP #3716](https://github.com/kubernetes/enhancements/pull/3717), |
| 1106 | +so that KEP should be controlling with regard to deviations in the schema. |
| 1107 | +This section is focused specifically on how the `matchConditions` concept can |
| 1108 | +be applied to in-process admission. |
| 1109 | + |
| 1110 | +The match criteria in bindings are not expected to be able to cover all possible |
| 1111 | +ways users may want to scope their policies. For example, there is no way to |
| 1112 | +match off of kind, only resource. To provide extensibility for the match criteria |
| 1113 | +without requiring modifying every validation rule individually, a global predicate |
| 1114 | +system is needed. These predicates contain CEL statements that must be satisfied, otherwise |
| 1115 | +the policy will be ignored. In order to keep bindings language-agnostic and to support |
| 1116 | +singleton policies, the logic should live in the policy definition resource. To enable |
| 1117 | +customization per-binding, the CEL statements should have access to the parameter resource. |
| 1118 | + |
| 1119 | +Here is an example of a policy definition using match conditions (under the `matchConditions` field): |
| 1120 | + |
| 1121 | +```yaml |
| 1122 | +apiVersion: admissionregistration.k8s.io/v1alpha1 |
| 1123 | +kind: ValidatingAdmissionPolicy |
| 1124 | +metadata: |
| 1125 | + name: "replicalimit-policy.example.com" |
| 1126 | +Spec: |
| 1127 | + failurePolicy: Fail |
| 1128 | + paramKind: |
| 1129 | + apiVersion: rules.example.com/v1 |
| 1130 | + kind: ReplicaLimit |
| 1131 | + matchConstraints: |
| 1132 | + resourceRules: |
| 1133 | + - apiGroups: ["apps"] |
| 1134 | + apiVersions: ["v1"] |
| 1135 | + operations: ["CREATE", "UPDATE"] |
| 1136 | + resources: ["deployments"] |
| 1137 | + matchConditions: |
| 1138 | + - name: 'is-deployment' |
| 1139 | + expression: 'metadata.kind == "Deployment"' |
| 1140 | + - name: 'not-in-excluded-namespaces' |
| 1141 | + expression: '!(metadata.namespace in params.excludedNamespaces)' |
| 1142 | + validations: |
| 1143 | + - expression: "object.spec.replicas <= params.maxReplicas" |
| 1144 | + reason: Invalid |
| 1145 | +``` |
| 1146 | + |
| 1147 | +For demonstration purposes, we assume `match` has no support for `excludedNamespaces`. |
| 1148 | + |
| 1149 | +Note that `matchConditions` and `validations` look similar, but `matchConditions` entries only have the |
| 1150 | +`expression` field: their only function is to gate whether the expressions in `validations` are evaluated. |
| 1151 | + |
| 1152 | +`matchConditions` has the following behaviors: |
| 1153 | + |
| 1154 | +* Only the request object and parameters are accessible (no referential lookup) |
| 1155 | +* All match conditions must be satisfied (evaluate to `true`) before `validations` are tested |
| 1156 | +* If there is an error executing a match condition, the failure policy for the (definition, binding) tuple is invoked |
| 1157 | + |
| 1158 | + |
1101 | 1159 | ##### Variables
|
1102 | 1160 |
|
1103 | 1161 | Each CEL "program" is a single expression. There is no support for variable
|
|
0 commit comments