Skip to content

Commit 66362d7

Browse files
committed
Resolve enj's and luxas's review
Signed-off-by: Jian Qiu <[email protected]>
1 parent f450cf6 commit 66362d7

File tree

1 file changed

+73
-41
lines changed
  • keps/sig-auth/5284-constrained-impersonation

1 file changed

+73
-41
lines changed

keps/sig-auth/5284-constrained-impersonation/README.md

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ tags, and then generate with `hack/update-toc.sh`.
122122
- [Setting a special APIGroup suffix instead of special verb](#setting-a-special-apigroup-suffix-instead-of-special-verb)
123123
- [Check permission intersection of impersonator and target user](#check-permission-intersection-of-impersonator-and-target-user)
124124
- [Expand RBAC/SAR](#expand-rbacsar)
125+
- [Conditional Authorization](#conditional-authorization)
125126
- [Infrastructure Needed (Optional)](#infrastructure-needed-optional)
126127
<!-- /toc -->
127128

@@ -171,7 +172,8 @@ Items marked with (R) are required *prior to targeting to a milestone / release*
171172

172173
This is to add additional access control over the existing impersonation action. An impersonator
173174
who impersonates another user is required to have the additional permissions to impersonate on
174-
certain group resources and verbs.
175+
certain group resources and verbs. In order for the request to succeed, the impersonated principal
176+
must have permission to perform the request, just like before.
175177

176178
## Motivation
177179
Today an impersonator can impersonate another user if the impersonator has the permission of
@@ -222,16 +224,31 @@ and the user must not be a node (username with a prefix of `system:node:`) and t
222224
not be a service account (username with a prefix of `system:serviceaccount:`)
223225
The resource names must be usernames, group names or values in the user extras accoringly.
224226
- `impersonate:serviceaccount` that limits the impersonator to impersonate the serviceaccount with
225-
the certain name/namespace. The resources must be `serviceaccounts`.
227+
the certain name/namespace. The resource must be `serviceaccounts`.
226228
- `impersonate:node` that limits the impersonator to impersonate the node only. The resource
227229
must be `nodes`, and the resourceName should be the name of the node. The impersonator must have this
228230
verb to impersonate a node.
229231
- `impersonate:scheduled-node` that limits the impersonator to impersonate the node the
230-
impersonator is running on. The resources must be `nodes`.
232+
impersonator is running on. The resources must be `nodes`. For a controller impersonating the node
233+
that it is running on, it will need to know the node name obtained via downward API:
234+
```yaml
235+
env:
236+
- name: MY_NODE_NAME
237+
valueFrom:
238+
fieldRef:
239+
fieldPath: spec.nodeName
240+
```
241+
and then set in the kubeconfig:
242+
```go
243+
kubeConfig, _ := clientcmd.BuildConfigFromFlags("", "")
244+
kubeConfig.Impersonate = rest.ImpersonationConfig{
245+
UserName: "system:node:" + os.Getenv("MY_NODE_NAME"),
246+
}
247+
```
231248

232-
For clusters that use RBAC authz mode, two permissions will be required for impersonation. For example:
233-
to express "system:serviceaccount:default:default can impersonate a user named someUser solely to list
234-
and watch pods in the default namespace."
249+
Two permissions will be required for impersonation. An example of how to express
250+
"`system:serviceaccount:default:default` can impersonate a user named someUser solely to list
251+
and watch pods in the default namespace." using Kubernetes RBAC:
235252
1. The permission to constrained impersonate a certain user. This is a cluster scoped permission.
236253
```yaml
237254
apiVersion: rbac.authorization.k8s.io/v1
@@ -240,7 +257,7 @@ metadata:
240257
name: constrained-impersonate-only-someUser
241258
rules:
242259
- apiGroups:
243-
- authentications.k8s.io
260+
- authentication.k8s.io
244261
resources:
245262
- users # allowed resources are users/groups/userextras/uids
246263
resourceNames:
@@ -255,7 +272,7 @@ metadata:
255272
roleRef:
256273
apiGroup: rbac.authorization.k8s.io
257274
kind: ClusterRole
258-
name: impersonate
275+
name: constrained-impersonate-only-someUser
259276
subjects:
260277
- kind: ServiceAccount
261278
name: default
@@ -267,7 +284,7 @@ cluster scoped or namespace scoped.
267284
apiVersion: rbac.authorization.k8s.io/v1
268285
kind: Role
269286
metadata:
270-
name: impersonate-action
287+
name: impersonate-allow-only-listwatch-pods
271288
namespace: default
272289
rules:
273290
- apiGroups:
@@ -281,12 +298,12 @@ rules:
281298
apiVersion: rbac.authorization.k8s.io/v1
282299
kind: RoleBinding
283300
metadata:
284-
name: impersonate
301+
name: impersonate-allow-only-listwatch-pods
285302
namespace: default
286303
roleRef:
287304
apiGroup: rbac.authorization.k8s.io
288305
kind: Role
289-
name: impersonate-action
306+
name: impersonate-allow-only-listwatch-pods
290307
subjects:
291308
- kind: ServiceAccount
292309
name: default
@@ -306,7 +323,7 @@ apiVersion: authorization.k8s.io/v1
306323
kind: SubjectAccessReview
307324
spec:
308325
resourceAttributes:
309-
group: authentications.k8s.io
326+
group: authentication.k8s.io
310327
resource: users
311328
name: someUser
312329
verb: impersonate:user-info
@@ -433,10 +450,10 @@ in the `default` namespace.
433450
apiVersion: rbac.authorization.k8s.io/v1
434451
kind: ClusterRole
435452
metadata:
436-
name: impersonate:vm:console
453+
name: impersonate-user:vm:console
437454
rules:
438455
- apiGroups:
439-
- authentications.k8s.io
456+
- authentication.k8s.io
440457
resources:
441458
- users
442459
verbs:
@@ -445,11 +462,11 @@ rules:
445462
apiVersion: rbac.authorization.k8s.io/v1
446463
kind: ClusterRoleBinding
447464
metadata:
448-
name: impersonate:vm:console
465+
name: impersonate-user:vm:console
449466
roleRef:
450467
apiGroup: rbac.authorization.k8s.io
451468
kind: ClusterRole
452-
name: impersonate:vm:console
469+
name: impersonate-user:vm:console
453470
subjects:
454471
- kind: ServiceAccount
455472
name: deputy
@@ -458,7 +475,7 @@ subjects:
458475
apiVersion: rbac.authorization.k8s.io/v1
459476
kind: Role
460477
metadata:
461-
name: impersonate:vm:console
478+
name: impersonate:vm:console:get
462479
namespace: default
463480
rules:
464481
- apiGroups:
@@ -471,12 +488,12 @@ rules:
471488
apiVersion: rbac.authorization.k8s.io/v1
472489
kind: RoleBinding
473490
metadata:
474-
name: impersonate-user
491+
name: impersonate:vm:console:get
475492
namespace: default
476493
roleRef:
477494
apiGroup: rbac.authorization.k8s.io
478495
kind: Role
479-
name: impersonate:vm:console
496+
name: impersonate:vm:console:get
480497
subjects:
481498
- kind: ServiceAccount
482499
name: deputy
@@ -499,9 +516,9 @@ Consider including folks who also work outside the SIG or subproject.
499516
#### The verbs with `impersonate-on:` prefix has been used by other component.
500517

501518
There is possibility that the verbs with prefix of `impersonate-on:` have been
502-
used by other component, and been set in Role/ClusterRole. Since `impersonate`
519+
used by other component, and been set in Role/ClusterRole. Since `impersonate:<type>`
503520
permission is also required for impersonator, the component will not get more
504-
power when permssion of `impersonate-on:` is given.
521+
power when permission of `impersonate-on:` is given.
505522

506523
#### High request volume leads to high load on authorization chain.
507524

@@ -543,7 +560,7 @@ apiVersion: authorization.k8s.io/v1
543560
kind: SubjectAccessReview
544561
spec:
545562
resourceAttributes:
546-
group: authentications.k8s.io
563+
group: authentication.k8s.io
547564
resource: users
548565
name: someUser
549566
verb: impersonate:user-info
@@ -559,13 +576,13 @@ apiVersion: authorization.k8s.io/v1
559576
kind: SubjectAccessReview
560577
spec:
561578
resourceAttributes:
562-
group: authentications.k8s.io
579+
group: authentication.k8s.io
563580
resource: groups
564581
name: someGroup
565582
verb: impersonate:user-info
566583
user: impersonator
567584
```
568-
will be sent to the authorizer
585+
will be sent to the authorizer for each group.
569586

570587
#### Header `Impersonate-Uid` is set
571588

@@ -575,13 +592,13 @@ apiVersion: authorization.k8s.io/v1
575592
kind: SubjectAccessReview
576593
spec:
577594
resourceAttributes:
578-
group: authentications.k8s.io
595+
group: authentication.k8s.io
579596
resource: uids
580597
name: someUID
581598
verb: impersonate:user-info
582599
user: impersonator
583600
```
584-
will be sent to the authorizer
601+
will be sent to the authorizer.
585602

586603
#### Header with prefix `Impersonate-Extra-` is set
587604

@@ -591,14 +608,14 @@ apiVersion: authorization.k8s.io/v1
591608
kind: SubjectAccessReview
592609
spec:
593610
resourceAttributes:
594-
group: authentications.k8s.io
611+
group: authentication.k8s.io
595612
resource: userextras
596613
subresource: extraKey
597614
name: extraValue
598615
verb: impersonate:user-info
599616
user: impersonator
600617
```
601-
will be sent to the authorizer
618+
will be sent to the authorizer for each key and value pair.
602619

603620
### Verb `impersonate:serviceaccount`
604621

@@ -610,7 +627,7 @@ apiVersion: authorization.k8s.io/v1
610627
kind: SubjectAccessReview
611628
spec:
612629
resourceAttributes:
613-
group: authentications.k8s.io
630+
group: authentication.k8s.io
614631
resource: serviceaccounts
615632
name: serviceaccount-name
616633
namespace: serviceaccount-namespace
@@ -628,7 +645,7 @@ apiVersion: authorization.k8s.io/v1
628645
kind: SubjectAccessReview
629646
spec:
630647
resourceAttributes:
631-
group: authentications.k8s.io
648+
group: authentication.k8s.io
632649
resource: nodes
633650
name: someNode
634651
verb: impersonate:nodes
@@ -650,7 +667,7 @@ apiVersion: authorization.k8s.io/v1
650667
kind: SubjectAccessReview
651668
spec:
652669
resourceAttributes:
653-
group: authentications.k8s.io
670+
group: authentication.k8s.io
654671
resource: nodes
655672
verb: impersonate:scheduled-node
656673
user: impersonator
@@ -661,7 +678,7 @@ apiVersion: authorization.k8s.io/v1
661678
kind: SubjectAccessReview
662679
spec:
663680
resourceAttributes:
664-
group: authentications.k8s.io
681+
group: authentication.k8s.io
665682
resource: nodes
666683
name: node1
667684
verb: impersonate:node
@@ -756,8 +773,8 @@ This can be done with:
756773
- The impersonator cannot impersonate alice.
757774
- The impersonator can impersonate on listing and getting pods
758775
- The impersonator cannot impersonate on updating pods
759-
- The impersonator can impersonate on getting pod/exec subresource
760-
- The impersonator cannot impersonate on get pod/log subresource
776+
- The impersonator can impersonate on getting pods/exec subresource
777+
- The impersonator cannot impersonate on get pods/log subresource
761778
For RBAC authz mode, this might look like:
762779
```yaml
763780
apiVersion: rbac.authorization.k8s.io/v1
@@ -766,7 +783,7 @@ metadata:
766783
name: impersonate-bob
767784
rules:
768785
- apiGroups:
769-
- authentications.k8s.io
786+
- authentication.k8s.io
770787
resources:
771788
- users
772789
resourceNames:
@@ -803,7 +820,7 @@ metadata:
803820
name: impersonate-scheduled-node
804821
rules:
805822
- apiGroups:
806-
- authentications.k8s.io
823+
- authentication.k8s.io
807824
resources:
808825
- nodes
809826
verbs:
@@ -1014,7 +1031,7 @@ This section must be completed when targeting beta to a release.
10141031

10151032
###### How can a rollout or rollback fail? Can it impact already running workloads?
10161033

1017-
There is not impact on rollout, the impersonator with existing impersonate permission can still perform the action.
1034+
There is no impact on rollout, the impersonator with existing impersonate permission can still perform the action.
10181035
When the system rollback, impersonator with `impersonate-on:` and `impersonate:` permission will no longer
10191036
be authorized to impersonate. Impersonator will need to have the unscoped impersonate permission.
10201037

@@ -1025,9 +1042,16 @@ be authorized to impersonate. Impersonator will need to have the unscoped impers
10251042
What signals should users be paying attention to when the feature is young
10261043
that might indicate a serious problem?
10271044
-->
1028-
authorization_attempts_total shows greatly increased number.
1029-
authorization_duration_seconds_bucket shows greatly increased number of request
1030-
with longer duration.
1045+
1046+
`apiserver_authorization_decisions_total` shows greatly increased number.
1047+
However, we cannot identify the impersonation action from the metrics today.
1048+
We could introduce a new metrics `apiserver_authorization_decisions_total_by_verb` so that filtering
1049+
based on impersonation related verbs can tell the number.
1050+
We could also introduce a new metrics `apiserver_authorization_decisions_duration_seconds`.
1051+
1052+
When webhook authorizer is used, if `apiserver_authorization_webhook_evaluations_total` and
1053+
`apiserver_authorization_webhook_duration_seconds` shows greatly increase number, users should
1054+
also pay attention.
10311055

10321056
###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested?
10331057

@@ -1382,7 +1406,7 @@ the action when impersonating.
13821406

13831407
### Expand RBAC/SAR
13841408

1385-
Introduce additional API to define more fine grained access control rule, and ref the rule in SAR.
1409+
Introduce additional API to define more fine-grained access control rule, and ref the rule in SAR.
13861410
One example is
13871411

13881412
```yaml
@@ -1411,6 +1435,14 @@ And authorizer checks the accessRule on whether a certain impersonate action is
14111435
complicated approach that requires changes on existing RBAC/SAR, while the current proposal does not
14121436
introduce change on RBAC/SAR.
14131437

1438+
#### Conditional Authorization
1439+
1440+
Conditional authorization is the emerging work to provide more complicated authorization policy
1441+
with CEL expressions. Potentially it would be able to reduce the number of permission checks for the impersonation
1442+
in this proposal. The work is still in very early stage, and will bring many changes in the exising authorization
1443+
model. It is possible to enhance constrained impersonation in this proposal with conditional authorization in the
1444+
future.
1445+
14141446
## Infrastructure Needed (Optional)
14151447

14161448
<!--

0 commit comments

Comments
 (0)