Skip to content

Commit 6fe28fb

Browse files
committed
Resolve kannon92 and enj's 2nd round review
Signed-off-by: Jian Qiu <[email protected]>
1 parent 63c30cc commit 6fe28fb

File tree

3 files changed

+67
-22
lines changed

3 files changed

+67
-22
lines changed

keps/prod-readiness/sig-auth/5284.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# of http://git.k8s.io/enhancements/OWNERS_ALIASES
44
kep-number: 5284
55
alpha:
6-
approver: "enj"
6+
approver: "deads2k"

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

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,13 @@ impersonate.
195195
Introduce verbs `impersonate:user-info`, `impersonate:serviceaccount` and `impersonate:scheduled-node`:
196196
- `impersonate:user-info` limits the impersonator to impersonate users with
197197
certain names/groups/userextras. The resources must be `users`/`groups`/`userextras`/`uids`.
198-
The resource names must be user names, group names or values in the user extras accoringly.
198+
and the user must not be a node (username with a prefix of `system:nodes`)
199+
The resource names must be usernames, group names or values in the user extras accoringly.
199200
- `impersonate:serviceaccount` that limits the impersonator to impersonate the serviceaccount with
200201
the certain name/namespace. The resources must be `serviceaccounts`.
202+
- `impersonate:node` that limits the impersonator to impersonate the node only. The resource
203+
must be `nodes`, and the resourceName should be the name of the node. The impersonator must have this
204+
verb to impersonate a node.
201205
- `impersonate:scheduled-node` that limits the impersonator to impersonate the node the
202206
impersonator is running on. The resources must be `nodes`.
203207

@@ -267,8 +271,9 @@ subjects:
267271
These permissions define: "The impersonator can impersonate a user with the name of
268272
someUser to list and watch pods in the default namespace."
269273

270-
When receiving an impersonation request to list pods from the user `impersonator` with the header of
271-
`Impersonate-User:someUser`, the apiserver:
274+
### Subject Access Review Details
275+
When receiving an impersonation request to list pods cluster-wid from the user `impersonator`
276+
with the header of `Impersonate-User:someUser`, the apiserver:
272277
- Verifies if the impersonator has the permission to impersonate with the scope of the user.
273278
A subjectaccessreview is sent to the authorizer:
274279
```yaml
@@ -384,13 +389,14 @@ subjects:
384389

385390
#### Story 2
386391

387-
As a controller, I am working as a deputy, receiving any user's request to access virtual machine console.
392+
As a controller, I am working as a deputy, receiving any user's request to access virtual machine console
393+
in the `default` namespace.
388394

389395
```yaml
390396
apiVersion: rbac.authorization.k8s.io/v1
391397
kind: ClusterRole
392398
metadata:
393-
name: impersonate-user
399+
name: impersonate:vm:console
394400
rules:
395401
- apiGroups:
396402
- authentications.k8s.io
@@ -402,11 +408,11 @@ rules:
402408
apiVersion: rbac.authorization.k8s.io/v1
403409
kind: ClusterRoleBinding
404410
metadata:
405-
name: impersonate-user
411+
name: impersonate:vm:console
406412
roleRef:
407413
apiGroup: rbac.authorization.k8s.io
408414
kind: ClusterRole
409-
name: impersonate-user
415+
name: impersonate:vm:console
410416
subjects:
411417
- kind: ServiceAccount
412418
name: deputy
@@ -460,6 +466,17 @@ used by other component, and been set in Role/ClusterRole. Since `impersonate`
460466
permission is also required for impersonator, the component will not get more
461467
power when permssion of `impersonate-on:` is given.
462468

469+
#### High request volume leads to high load on authorization chain.
470+
471+
For the scheduled node case, it is possible that a high request volume node
472+
agent could be constantly performing impersonated requests, each of which would
473+
add two extra authorization checks. This could put load on the authorization
474+
chain. We could cache the check results with a certain time period to mitigate
475+
it which will requires more complicated cache design:
476+
- the key should include resources/actions/subjects
477+
- the value should be marked as invalidated for a certain period.
478+
This part of design and implementation will be considered in beta phase.
479+
463480
## Design Details
464481

465482
<!--
@@ -558,16 +575,33 @@ spec:
558575
user: impersonator
559576
```
560577

561-
### Verb `impersonate:scheduled-node`
578+
### Verb `impersonate:node` and `impersonate:scheduled-node`
562579

563-
This is a special verb to check when two conditions are met:
580+
When the request has the header of `Impersonate-User`, and the value has the prefix of `system:nodes`,
581+
this verb is checked instead of `impersonate:user-info`. The subjectaccessreview below will be sent
582+
to the authorizer:
583+
```yaml
584+
apiVersion: authorization.k8s.io/v1
585+
kind: SubjectAccessReview
586+
spec:
587+
resourceAttributes:
588+
group: authentications.k8s.io
589+
resource: nodes
590+
name: someNode
591+
verb: impersonate:nodes
592+
user: impersonator
593+
```
594+
595+
`impersonate:scheduled-node` is a special verb to check when two conditions are met:
564596
1. The impersonator is impersonating a node by setting the header `Impersonate-User` and the value has a prefix
565597
of `system:node:` on the request.
566598
2. The user info of the impersonator has an extra with key `authentication.kubernetes.io/node-name`, and the value
567599
should be the same as the value in the request header of `Impersonate-User` after removing prefix `system:node:`.
568600
It indicates that the impersonator is running on the same node it is impersonating.
569601

570-
If the two conditions are both met, the following subjectaccessreview will be sent to the authorizer:
602+
The flow for checking these two verbs will be as following:
603+
1. If condition 1 is not met, verb `impersonate:user-info` will be checked instead.
604+
2. If both conditions are met, the verb `impersonate:scheduled-node` will be checked at first:
571605
```yaml
572606
apiVersion: authorization.k8s.io/v1
573607
kind: SubjectAccessReview
@@ -578,27 +612,27 @@ spec:
578612
verb: impersonate:scheduled-node
579613
user: impersonator
580614
```
581-
If one of the conditions is not met, verb `impersonate:scheduled-node` will not be checked and verb
582-
`impersonate:user-info` will be checked instead. For instance, if condition 2 is not met, the following
583-
subjectaccessreview will be sent.
615+
3. If check in step 2 is not passed, or only condition 1 is met, the verb impersonate:node will be checked:
584616
```yaml
585617
apiVersion: authorization.k8s.io/v1
586618
kind: SubjectAccessReview
587619
spec:
588620
resourceAttributes:
589621
group: authentications.k8s.io
590-
resource: users
591-
name: system:node:node1
592-
verb: impersonate:user-info
622+
resource: nodes
623+
name: node1
624+
verb: impersonate:node
593625
user: impersonator
594626
```
595627

596628
### Auditing
597629

598-
An audit event is recorded already for any allowed impersonation request. To record the reason why the impersonation
599-
is allowed, an annotation `allowed-impersonation-verbs` will be added. The value will be the list of impersonation
600-
related verbs checked. For example, `allowed-impersonation-verbs: impersonate:scheduled-node,impersonate-on:list`
601-
indicates that the impersonation request is allowed because it impersonates a scheduled node on list action.
630+
Audit events already contain the `impersonatedUser` field to denote if impersonation was used.
631+
To record the reason why the impersonation is allowed, an annotation `allowed-impersonation-verbs` will
632+
be added. The value will be the impersonation related verbs. For example,
633+
`allowed-impersonation-verbs: impersonate:scheduled-node` indicates that the impersonation request is
634+
allowed because it impersonates a scheduled node. The specific action such as `list` or `get`
635+
will not be included in the value given it can be inferred from the request itself.
602636

603637
### Test Plan
604638

@@ -1144,6 +1178,8 @@ This through this both in small and large cases, again with respect to the
11441178
[supported limits]: https://git.k8s.io/community//sig-scalability/configs-and-limits/thresholds.md
11451179
-->
11461180

1181+
NA
1182+
11471183
###### Can enabling / using this feature result in resource exhaustion of some node resources (PIDs, sockets, inodes, etc.)?
11481184

11491185
<!--
@@ -1187,6 +1223,12 @@ For each of them, fill in the following information by copying the below templat
11871223
Not required until feature graduated to beta.
11881224
- Testing: Are there any tests for failure mode? If not, describe why.
11891225
-->
1226+
- Impersonation permission is set but request is disallowed with external authorizer.
1227+
- Detection: metrics of `authorization success` will show the unauthorized requests
1228+
- Mitigations: Stop sending the impersonation requests
1229+
- Diagnostics: APIServer log will show the reason why the request is unauthorized.
1230+
- Testing: There is no general test for that, user using external authorizer need to
1231+
test for the specific authorizer.
11901232

11911233
###### What steps should be taken if SLOs are not being met to determine the problem?
11921234

@@ -1203,6 +1245,8 @@ Major milestones might include:
12031245
- when the KEP was retired or superseded
12041246
-->
12051247

1248+
- Kubernetes 1.34: Alpha version of the KEP.
1249+
12061250
## Drawbacks
12071251

12081252
- Several additional authorization checks are added introducing some overhead.

keps/sig-auth/5284-constrained-impersonation/kep.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ authors:
55
owning-sig: sig-auth
66
participating-sigs:
77
- sig-auth
8-
status: provisional
8+
status: implementable
99
creation-date: 2025-05-07
1010
reviewers:
1111
- "@deads2k"
1212
- "@enj"
1313
approvers:
1414
- "@enj"
15+
- "@liggitt"
1516

1617
see-also:
1718
replaces:

0 commit comments

Comments
 (0)