@@ -123,10 +123,12 @@ authorizers:
123
123
type : KubeConfig
124
124
kubeConfigFile : /kube-system-authz-webhook.yaml
125
125
matchConditions :
126
- - expression : |
127
- has(request.resourceAttributes) && (request.resourceAttributes.namespace == 'kube-system')
128
- - expression : |
129
- !('system:serviceaccounts:kube-system' in request.user.groups)
126
+ # only send resource requests to the webhook
127
+ - expression : has(request.resourceAttributes)
128
+ # only intercept requests to kube-system
129
+ - expression : request.resourceAttributes.namespace == 'kube-system'
130
+ # don't intercept requests from kube-system service accounts
131
+ - expression : !('system:serviceaccounts:kube-system' in request.user.groups)
130
132
- type : Node
131
133
- type : RBAC
132
134
- type : Webhook
@@ -158,6 +160,42 @@ update/delete the protected set of CRDs.
158
160
159
161
Relevant Discussion Thread is sig-apimachinery : https://groups.google.com/g/kubernetes-sig-api-machinery/c/MBa19WTETMQ
160
162
163
+ A relevant configuration for this scenario with the assumptions :
164
+ 1. The "protected" CRDs are installed in the kube-system namespace.
165
+ 2. They can only be modified by users in the group "system:serviceaccounts:kube-superuser"
166
+
167
+ Note : The above are hypothetical for now since there has been no decision on
168
+ protection rules for system CRDs. The below example is only for demonstration
169
+ purposes.
170
+ ` ` ` yaml
171
+ apiVersion: apiserver.config.k8s.io/v1alpha1
172
+ kind: AuthorizationConfiguration
173
+ authorizers:
174
+ - type: Webhook
175
+ name: system-crd-protector
176
+ webhook:
177
+ unauthorizedTTL: 30s
178
+ timeout: 3s
179
+ subjectAccessReviewVersion: v1
180
+ failurePolicy: Deny
181
+ connectionInfo:
182
+ type: KubeConfig
183
+ kubeConfigFile: /kube-system-authz-webhook.yaml
184
+ matchConditions:
185
+ # only send resource requests to the webhook
186
+ - expression: has(request.resourceAttributes)
187
+ # only intercept requests to kube-system (assumption i)
188
+ - expression: request.resourceAttributes.namespace == 'kube-system'
189
+ # don't intercept requests from kube-system service accounts
190
+ - expression: !('system:serviceaccounts:kube-kube-superuser' in request.user.groups)
191
+ # only intercept update, delete and deletecollection requests
192
+ - expression: request.resourceAttributes.verb == 'update'
193
+ - expression: request.resourceAttributes.verb == 'delete'
194
+ - expression: request.resourceAttributes.verb == 'deletecollection'
195
+ - type: Node
196
+ - type: RBAC
197
+ ` ` `
198
+
161
199
# ### Story 2: Preventing unnecessarily nested webhooks
162
200
163
201
Consider a system administrator who would like to apply a set of validations
@@ -298,10 +336,13 @@ authorizers:
298
336
# CEL expressions have access to the contents of the SubjectAccessReview
299
337
# in the version specified by subjectAccessReviewVersion in the request variable.
300
338
# Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
301
- - expression : |
302
- has(request.resourceAttributes) && (request.resourceAttributes.namespace == 'kube-system')
303
- - expression : |
304
- !('system:serviceaccounts:kube-system' in request.user.groups)
339
+ #
340
+ # only send resource requests to the webhook
341
+ - expression : has(request.resourceAttributes)
342
+ # only intercept requests to kube-system
343
+ - expression : request.resourceAttributes.namespace == 'kube-system'
344
+ # don't intercept requests from kube-system service accounts
345
+ - expression : !('system:serviceaccounts:kube-system' in request.user.groups)
305
346
- type : Node
306
347
- type : RBAC
307
348
- type : Webhook
0 commit comments