Skip to content

Commit ee75a14

Browse files
committed
Resolve enj's and luxas's review
Signed-off-by: Jian Qiu <jqiu@redhat.com>
1 parent f450cf6 commit ee75a14

File tree

1 file changed

+63
-40
lines changed
  • keps/sig-auth/5284-constrained-impersonation

1 file changed

+63
-40
lines changed

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

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ Items marked with (R) are required *prior to targeting to a milestone / release*
171171

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

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

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."
248+
Two permissions will be required for impersonation. An example of how to express
249+
"`system:serviceaccount:default:default` can impersonate a user named someUser solely to list
250+
and watch pods in the default namespace." using Kubernetes RBAC:
235251
1. The permission to constrained impersonate a certain user. This is a cluster scoped permission.
236252
```yaml
237253
apiVersion: rbac.authorization.k8s.io/v1
@@ -240,7 +256,7 @@ metadata:
240256
name: constrained-impersonate-only-someUser
241257
rules:
242258
- apiGroups:
243-
- authentications.k8s.io
259+
- authentication.k8s.io
244260
resources:
245261
- users # allowed resources are users/groups/userextras/uids
246262
resourceNames:
@@ -255,7 +271,7 @@ metadata:
255271
roleRef:
256272
apiGroup: rbac.authorization.k8s.io
257273
kind: ClusterRole
258-
name: impersonate
274+
name: constrained-impersonate-only-someUser
259275
subjects:
260276
- kind: ServiceAccount
261277
name: default
@@ -267,7 +283,7 @@ cluster scoped or namespace scoped.
267283
apiVersion: rbac.authorization.k8s.io/v1
268284
kind: Role
269285
metadata:
270-
name: impersonate-action
286+
name: impersonate-allow-only-listwatch-pods
271287
namespace: default
272288
rules:
273289
- apiGroups:
@@ -281,12 +297,12 @@ rules:
281297
apiVersion: rbac.authorization.k8s.io/v1
282298
kind: RoleBinding
283299
metadata:
284-
name: impersonate
300+
name: impersonate-allow-only-listwatch-pods
285301
namespace: default
286302
roleRef:
287303
apiGroup: rbac.authorization.k8s.io
288304
kind: Role
289-
name: impersonate-action
305+
name: impersonate-allow-only-listwatch-pods
290306
subjects:
291307
- kind: ServiceAccount
292308
name: default
@@ -306,7 +322,7 @@ apiVersion: authorization.k8s.io/v1
306322
kind: SubjectAccessReview
307323
spec:
308324
resourceAttributes:
309-
group: authentications.k8s.io
325+
group: authentication.k8s.io
310326
resource: users
311327
name: someUser
312328
verb: impersonate:user-info
@@ -433,10 +449,10 @@ in the `default` namespace.
433449
apiVersion: rbac.authorization.k8s.io/v1
434450
kind: ClusterRole
435451
metadata:
436-
name: impersonate:vm:console
452+
name: impersonate-user:vm:console
437453
rules:
438454
- apiGroups:
439-
- authentications.k8s.io
455+
- authentication.k8s.io
440456
resources:
441457
- users
442458
verbs:
@@ -445,11 +461,11 @@ rules:
445461
apiVersion: rbac.authorization.k8s.io/v1
446462
kind: ClusterRoleBinding
447463
metadata:
448-
name: impersonate:vm:console
464+
name: impersonate-user:vm:console
449465
roleRef:
450466
apiGroup: rbac.authorization.k8s.io
451467
kind: ClusterRole
452-
name: impersonate:vm:console
468+
name: impersonate-user:vm:console
453469
subjects:
454470
- kind: ServiceAccount
455471
name: deputy
@@ -458,7 +474,7 @@ subjects:
458474
apiVersion: rbac.authorization.k8s.io/v1
459475
kind: Role
460476
metadata:
461-
name: impersonate:vm:console
477+
name: impersonate:vm:console:get
462478
namespace: default
463479
rules:
464480
- apiGroups:
@@ -471,12 +487,12 @@ rules:
471487
apiVersion: rbac.authorization.k8s.io/v1
472488
kind: RoleBinding
473489
metadata:
474-
name: impersonate-user
490+
name: impersonate:vm:console:get
475491
namespace: default
476492
roleRef:
477493
apiGroup: rbac.authorization.k8s.io
478494
kind: Role
479-
name: impersonate:vm:console
495+
name: impersonate:vm:console:get
480496
subjects:
481497
- kind: ServiceAccount
482498
name: deputy
@@ -499,9 +515,9 @@ Consider including folks who also work outside the SIG or subproject.
499515
#### The verbs with `impersonate-on:` prefix has been used by other component.
500516

501517
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`
518+
used by other component, and been set in Role/ClusterRole. Since `impersonate:<type>`
503519
permission is also required for impersonator, the component will not get more
504-
power when permssion of `impersonate-on:` is given.
520+
power when permission of `impersonate-on:` is given.
505521

506522
#### High request volume leads to high load on authorization chain.
507523

@@ -543,7 +559,7 @@ apiVersion: authorization.k8s.io/v1
543559
kind: SubjectAccessReview
544560
spec:
545561
resourceAttributes:
546-
group: authentications.k8s.io
562+
group: authentication.k8s.io
547563
resource: users
548564
name: someUser
549565
verb: impersonate:user-info
@@ -559,13 +575,13 @@ apiVersion: authorization.k8s.io/v1
559575
kind: SubjectAccessReview
560576
spec:
561577
resourceAttributes:
562-
group: authentications.k8s.io
578+
group: authentication.k8s.io
563579
resource: groups
564580
name: someGroup
565581
verb: impersonate:user-info
566582
user: impersonator
567583
```
568-
will be sent to the authorizer
584+
will be sent to the authorizer for each group.
569585

570586
#### Header `Impersonate-Uid` is set
571587

@@ -575,13 +591,13 @@ apiVersion: authorization.k8s.io/v1
575591
kind: SubjectAccessReview
576592
spec:
577593
resourceAttributes:
578-
group: authentications.k8s.io
594+
group: authentication.k8s.io
579595
resource: uids
580596
name: someUID
581597
verb: impersonate:user-info
582598
user: impersonator
583599
```
584-
will be sent to the authorizer
600+
will be sent to the authorizer.
585601

586602
#### Header with prefix `Impersonate-Extra-` is set
587603

@@ -591,14 +607,14 @@ apiVersion: authorization.k8s.io/v1
591607
kind: SubjectAccessReview
592608
spec:
593609
resourceAttributes:
594-
group: authentications.k8s.io
610+
group: authentication.k8s.io
595611
resource: userextras
596612
subresource: extraKey
597613
name: extraValue
598614
verb: impersonate:user-info
599615
user: impersonator
600616
```
601-
will be sent to the authorizer
617+
will be sent to the authorizer for each key and value pair.
602618

603619
### Verb `impersonate:serviceaccount`
604620

@@ -610,7 +626,7 @@ apiVersion: authorization.k8s.io/v1
610626
kind: SubjectAccessReview
611627
spec:
612628
resourceAttributes:
613-
group: authentications.k8s.io
629+
group: authentication.k8s.io
614630
resource: serviceaccounts
615631
name: serviceaccount-name
616632
namespace: serviceaccount-namespace
@@ -628,7 +644,7 @@ apiVersion: authorization.k8s.io/v1
628644
kind: SubjectAccessReview
629645
spec:
630646
resourceAttributes:
631-
group: authentications.k8s.io
647+
group: authentication.k8s.io
632648
resource: nodes
633649
name: someNode
634650
verb: impersonate:nodes
@@ -650,7 +666,7 @@ apiVersion: authorization.k8s.io/v1
650666
kind: SubjectAccessReview
651667
spec:
652668
resourceAttributes:
653-
group: authentications.k8s.io
669+
group: authentication.k8s.io
654670
resource: nodes
655671
verb: impersonate:scheduled-node
656672
user: impersonator
@@ -661,7 +677,7 @@ apiVersion: authorization.k8s.io/v1
661677
kind: SubjectAccessReview
662678
spec:
663679
resourceAttributes:
664-
group: authentications.k8s.io
680+
group: authentication.k8s.io
665681
resource: nodes
666682
name: node1
667683
verb: impersonate:node
@@ -756,8 +772,8 @@ This can be done with:
756772
- The impersonator cannot impersonate alice.
757773
- The impersonator can impersonate on listing and getting pods
758774
- 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
775+
- The impersonator can impersonate on getting pods/exec subresource
776+
- The impersonator cannot impersonate on get pods/log subresource
761777
For RBAC authz mode, this might look like:
762778
```yaml
763779
apiVersion: rbac.authorization.k8s.io/v1
@@ -766,7 +782,7 @@ metadata:
766782
name: impersonate-bob
767783
rules:
768784
- apiGroups:
769-
- authentications.k8s.io
785+
- authentication.k8s.io
770786
resources:
771787
- users
772788
resourceNames:
@@ -803,7 +819,7 @@ metadata:
803819
name: impersonate-scheduled-node
804820
rules:
805821
- apiGroups:
806-
- authentications.k8s.io
822+
- authentication.k8s.io
807823
resources:
808824
- nodes
809825
verbs:
@@ -1014,7 +1030,7 @@ This section must be completed when targeting beta to a release.
10141030

10151031
###### How can a rollout or rollback fail? Can it impact already running workloads?
10161032

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

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

10321055
###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested?
10331056

0 commit comments

Comments
 (0)