1
1
---
2
2
layout : blog
3
- title : ' Multi-Webhook Authorization Made Easy'
3
+ title : ' Multi-Webhook and Modular Authorization Made Easy'
4
4
date : 2024-04-nn
5
- slug : multi-webhook-authorization-made-easy
5
+ slug : multi-webhook-and-modular- authorization-made-easy
6
6
---
7
7
8
8
** Authors:** [ Rita Zhang] ( https://github.com/ritazh ) (Microsoft), [ Jordan
@@ -13,7 +13,7 @@ Capili](https://github.com/stealthybox) (VMware)
13
13
# Enhancing Kubernetes Authorization with Multiple Webhooks and Structured Configuration
14
14
15
15
## Introduction
16
- Kubernetes continuous to evolve to meet the intricate requirements of system
16
+ Kubernetes continues to evolve to meet the intricate requirements of system
17
17
administrators and developers alike. A critical aspect of Kubernetes that
18
18
ensures the security and integrity of the cluster is the API server
19
19
authorization. Until recently, the configuration of the authorization chain in
@@ -24,24 +24,25 @@ define complex, fine-grained authorization policies. The latest Structured
24
24
Authorization Configuration feature ([ KEP-3221] ( https://kep.k8s.io/3221 ) ) aims
25
25
to revolutionize this aspect by introducing a more structured and versatile way
26
26
to configure the authorization chain, focusing on enabling multiple webhooks and
27
- providing explicit control mechanisms such as the explicit Deny authorizer .
27
+ providing explicit control mechanisms.
28
28
29
29
## The Need for Improvement
30
30
Cluster administrators have long sought the ability to specify multiple
31
- authorization webhooks within the API Server handler chain. This need arises
32
- from the desire to create layered security policies, where requests can be
33
- validated against multiple criteria or sets of rules in a specific order. The
34
- previous limitations also made it difficult to declaratively configure the
31
+ authorization webhooks within the API Server handler chain and have control over
32
+ detailed behavior like timeout and failure policy for each webhook. This need
33
+ arises from the desire to create layered security policies, where requests can
34
+ be validated against multiple criteria or sets of rules in a specific order. The
35
+ previous limitations also made it difficult to dynamically configure the
35
36
authorizer chain, leaving no room to efficiently manage complex authorization
36
37
scenarios.
37
38
38
39
The [ Structured Authorization Configuration
39
40
feature] ( /docs/reference/access-authn-authz/authorization/#configuring-the-api-server-using-an-authorization-config-file )
40
41
addresses these limitations by introducing a configuration file format to
41
42
configure Kubernetes API Server Authorization chain. This format allows
42
- specifying multiple webhooks in the authorization chain while all other types of
43
- authorizers should at most be specified once. Each webhook authorizer comes with
44
- its well-defined parameters, including timeout settings, failure policies, and
43
+ specifying multiple webhooks in the authorization chain ( all other authorization
44
+ types are specified no more than once) . Each webhook authorizer comes with its
45
+ well-defined parameters, including timeout settings, failure policies, and
45
46
conditions for invocation with [ CEL] ( /docs/reference/using-api/cel/ ) rules to
46
47
pre-filter requests before they are dispatched to webhooks, helping you to
47
48
prevent unnecessary invocations. The configuration also supports automatic
@@ -158,17 +159,18 @@ order, and failure modes.
158
159
159
160
### Protecting Installed CRDs
160
161
Ensuring the availability of Custom Resource Definitions (CRDs) at cluster
161
- startup has been a key demand, One of the blockers for having a controller
162
+ startup has been a key demand. One of the blockers for having a controller
162
163
reconciling those CRDs is to have a protection mechanism for them, which can be
163
- achieved through multiple Authorization Webhooks. This was not possible before.
164
- Now with the Structured Authorization Configuration feature, administrators can
165
- specify multiple webhooks offering a solution where RBAC falls short, especially
166
- in denying permissions to 'non-system' users for certain CRDs.
164
+ achieved through multiple authorization webhooks. This was not possible before
165
+ as specifying multiple authorization webhooks in the Kubernetes API Server
166
+ authorization chain was simply not possible. Now with the Structured
167
+ Authorization Configuration feature, administrators can specify multiple
168
+ webhooks offering a solution where RBAC falls short, especially in denying
169
+ permissions to 'non-system' users for certain CRDs.
167
170
168
171
Assuming the following for this scenario:
169
- - The "protected" CRDs are installed in the kube-system namespace.
170
- - They can only be modified by users in the group
171
- ` system:serviceaccounts:kube-superuser`
172
+ - The "protected" CRDs are installed.
173
+ - They can only be modified by users in the group ` admin`
172
174
173
175
` ` ` yaml
174
176
apiVersion: apiserver.config.k8s.io/v1beta1
@@ -188,12 +190,11 @@ authorizers:
188
190
matchConditions:
189
191
# only send resource requests to the webhook
190
192
- expression: has(request.resourceAttributes)
191
- # only intercept requests to kube-system
192
- - expression: request.resourceAttributes.namespace == 'kube-system'
193
- # don't intercept requests from kube-system service accounts
194
- - expression: !('system:serviceaccounts:kube-system' in request.user.groups)
195
- # only intercept update, delete or deletecollection requests
196
- - expression: request.resourceAttributes.verb in ['update', 'delete','deletecollection']
193
+ # only intercept requests for CRDs
194
+ - expression: request.resourceAttributes.resource.resource = "customresourcedefinitions"
195
+ - expression: request.resourceAttributes.resource.group = ""
196
+ # only intercept update, patch, delete, or deletecollection requests
197
+ - expression: request.resourceAttributes.verb in ['update', 'patch', 'delete','deletecollection']
197
198
- type: Node
198
199
- type: RBAC
199
200
` ` `
@@ -212,8 +213,8 @@ consistent and predictable responses.
212
213
apiVersion: apiserver.config.k8s.io/v1beta1
213
214
kind: AuthorizationConfiguration
214
215
authorizers:
215
- - name: system-crd-protector
216
- type: Webhook
216
+ - type: Webhook
217
+ name: system-crd-protector
217
218
webhook:
218
219
unauthorizedTTL: 30s
219
220
timeout: 3s
@@ -226,10 +227,11 @@ authorizers:
226
227
matchConditions:
227
228
# only send resource requests to the webhook
228
229
- expression: has(request.resourceAttributes)
229
- # only intercept requests to kube-system
230
- - expression: request.resourceAttributes.namespace == 'kube-system'
231
- # don't intercept requests from kube-system service accounts
232
- - expression: !('system:serviceaccounts:kube-system' in request.user.groups)
230
+ # only intercept requests for CRDs
231
+ - expression: request.resourceAttributes.resource.resource = "customresourcedefinitions"
232
+ - expression: request.resourceAttributes.resource.group = ""
233
+ # only intercept update, patch, delete, or deletecollection requests
234
+ - expression: request.resourceAttributes.verb in ['update', 'patch', 'delete','deletecollection']
233
235
- type: Node
234
236
- type: RBAC
235
237
- name: opa
@@ -255,7 +257,7 @@ authorizers:
255
257
# # What's next?
256
258
For Kubernetes v1.31, we expect the feature to stay in beta while we get more
257
259
feedback. Then once the feature is ready for GA, the feature flag will be
258
- removed.
260
+ removed and the configuration file version will be promoted to v1 .
259
261
260
262
You can learn more about this feature on the [structured authorization
261
263
configuration](/docs/reference/access-authn-authz/authorization/#configuring-the-api-server-using-an-authorization-config-file)
@@ -270,7 +272,9 @@ for real world scenarios. To use this feature, you must specify the path to the
270
272
authorization configuration using the `--authorization-config` command line
271
273
argument. From Kubernetes 1.30, the feature is in beta and enabled by default.
272
274
If you want to keep using command line flags instead of a configuration file,
273
- those will continue to work as-is.
275
+ those will continue to work as-is. Specifying both `--authorization-config` and
276
+ ` --authorization-modes` /`--authorization-webhook-*` won't work. You need to drop
277
+ the older flags from your kube-apiserver command.
274
278
275
279
The following kind Cluster configuration sets that command argument on the
276
280
APIserver to load an AuthorizationConfiguration from a file
@@ -280,7 +284,7 @@ certificate files can also be put in the files directory.
280
284
kind: Cluster
281
285
apiVersion: kind.x-k8s.io/v1alpha4
282
286
featureGates:
283
- StructuredAuthorizationConfiguration: true # only required for v1.29; enabled by default in v1.30
287
+ StructuredAuthorizationConfiguration: true # enabled by default in v1.30
284
288
kubeadmConfigPatches:
285
289
- |
286
290
kind: ClusterConfiguration
0 commit comments