Skip to content

Commit 350c779

Browse files
committed
Resolve deads2k's review
Signed-off-by: Jian Qiu <[email protected]>
1 parent 6fe28fb commit 350c779

File tree

1 file changed

+100
-37
lines changed
  • keps/sig-auth/5284-constrained-impersonation

1 file changed

+100
-37
lines changed

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

Lines changed: 100 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,37 @@ tags, and then generate with `hack/update-toc.sh`.
7676
- [Goals](#goals)
7777
- [Non-Goals](#non-goals)
7878
- [Proposal](#proposal)
79+
- [Subject Access Review Details](#subject-access-review-details)
80+
- [workflow when the feature is enabled](#workflow-when-the-feature-is-enabled)
7981
- [User Stories (Optional)](#user-stories-optional)
8082
- [Story 1](#story-1)
8183
- [Story 2](#story-2)
82-
- [Notes/Constraints/Caveats (Optional)](#notesconstraintscaveats-optional)
8384
- [Risks and Mitigations](#risks-and-mitigations)
85+
- [The verbs with <code>impersonate-on:</code> prefix has been used by other component.](#the-verbs-with-impersonate-on-prefix-has-been-used-by-other-component)
86+
- [High request volume leads to high load on authorization chain.](#high-request-volume-leads-to-high-load-on-authorization-chain)
87+
- [Delegating permission of impersonating wildcard action or wildcard subjects is not supported](#delegating-permission-of-impersonating-wildcard-action-or-wildcard-subjects-is-not-supported)
8488
- [Design Details](#design-details)
89+
- [Verb <code>impersonate:user-info</code>](#verb-impersonateuser-info)
90+
- [Header <code>Impersonate-User</code> is set](#header-impersonate-user-is-set)
91+
- [Header <code>Impersonate-Group</code> is set](#header-impersonate-group-is-set)
92+
- [Header <code>Impersonate-Uid</code> is set](#header-impersonate-uid-is-set)
93+
- [Header with prefix <code>Impersonate-Extra-</code> is set](#header-with-prefix-impersonate-extra--is-set)
94+
- [Verb <code>impersonate:serviceaccount</code>](#verb-impersonateserviceaccount)
95+
- [Verb <code>impersonate:node</code> and <code>impersonate:scheduled-node</code>](#verb-impersonatenode-and-impersonatescheduled-node)
96+
- [Auditing](#auditing)
8597
- [Test Plan](#test-plan)
8698
- [Prerequisite testing updates](#prerequisite-testing-updates)
8799
- [Unit tests](#unit-tests)
88100
- [Integration tests](#integration-tests)
89101
- [e2e tests](#e2e-tests)
90102
- [Graduation Criteria](#graduation-criteria)
103+
- [Alpha](#alpha)
104+
- [Beta](#beta)
105+
- [GA](#ga)
91106
- [Upgrade / Downgrade Strategy](#upgrade--downgrade-strategy)
92107
- [Version Skew Strategy](#version-skew-strategy)
108+
- [New kube-apiserver, old <code>impersonate</code> permission](#new-kube-apiserver-old-impersonate-permission)
109+
- [Old kube-apiserver, new <code>impersonate-on:</code> and <code>impersonate:</code> permission](#old-kube-apiserver-new-impersonate-on-and-impersonate-permission)
93110
- [Production Readiness Review Questionnaire](#production-readiness-review-questionnaire)
94111
- [Feature Enablement and Rollback](#feature-enablement-and-rollback)
95112
- [Rollout, Upgrade and Rollback Planning](#rollout-upgrade-and-rollback-planning)
@@ -100,6 +117,11 @@ tags, and then generate with `hack/update-toc.sh`.
100117
- [Implementation History](#implementation-history)
101118
- [Drawbacks](#drawbacks)
102119
- [Alternatives](#alternatives)
120+
- [Use <code>impersonate:user-info</code> instead of <code>impersonate:serviceaccount</code> and <code>impersonate:node</code>](#use-impersonateuser-info-instead-of-impersonateserviceaccount-and-impersonatenode)
121+
- [Subject Access Review](#subject-access-review)
122+
- [Setting a special APIGroup suffix instead of special verb](#setting-a-special-apigroup-suffix-instead-of-special-verb)
123+
- [Check permission intersection of impersonator and target user](#check-permission-intersection-of-impersonator-and-target-user)
124+
- [Expand RBAC/SAR](#expand-rbacsar)
103125
- [Infrastructure Needed (Optional)](#infrastructure-needed-optional)
104126
<!-- /toc -->
105127

@@ -192,7 +214,8 @@ Introduce a set of verbs with prefix of `impersonate-on:`, e.g. `impersonate-on:
192214
`impersonate-on:get`. The impersonator needs to have these verbs with certain resources to
193215
impersonate.
194216

195-
Introduce verbs `impersonate:user-info`, `impersonate:serviceaccount` and `impersonate:scheduled-node`:
217+
Introduce verbs `impersonate:user-info`, `impersonate:serviceaccount`, `impersonate:node` and
218+
`impersonate:scheduled-node`:
196219
- `impersonate:user-info` limits the impersonator to impersonate users with
197220
certain names/groups/userextras. The resources must be `users`/`groups`/`userextras`/`uids`.
198221
and the user must not be a node (username with a prefix of `system:nodes`)
@@ -206,13 +229,14 @@ verb to impersonate a node.
206229
impersonator is running on. The resources must be `nodes`.
207230

208231
For clusters that use RBAC authz mode, two permissions will be required for impersonation. For example:
209-
1. The permission to impersonate a certain user. This is a cluster scoped
210-
permission.
232+
to express "system:serviceaccount:default:default can impersonate a user named someUser solely to list
233+
and watch pods in the default namespace."
234+
1. The permission to constrained impersonate a certain user. This is a cluster scoped permission.
211235
```yaml
212236
apiVersion: rbac.authorization.k8s.io/v1
213237
kind: ClusterRole
214238
metadata:
215-
name: impersonate
239+
name: constrained-impersonate-only-someUser
216240
rules:
217241
- apiGroups:
218242
- authentications.k8s.io
@@ -272,7 +296,7 @@ These permissions define: "The impersonator can impersonate a user with the name
272296
someUser to list and watch pods in the default namespace."
273297

274298
### Subject Access Review Details
275-
When receiving an impersonation request to list pods cluster-wid from the user `impersonator`
299+
When receiving an impersonation request to list pods cluster-wide from the user `impersonator`
276300
with the header of `Impersonate-User:someUser`, the apiserver:
277301
- Verifies if the impersonator has the permission to impersonate with the scope of the user.
278302
A subjectaccessreview is sent to the authorizer:
@@ -295,6 +319,7 @@ kind: SubjectAccessReview
295319
spec:
296320
resourceAttributes:
297321
resource: pods
322+
namespace: default
298323
verb: impersonate-on:list
299324
user: impersonator
300325
```
@@ -471,11 +496,17 @@ power when permssion of `impersonate-on:` is given.
471496
For the scheduled node case, it is possible that a high request volume node
472497
agent could be constantly performing impersonated requests, each of which would
473498
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.
499+
chain. Comparing to other alternatives which would also introduce at least
500+
one authorization check for each request call, the proposal is able to
501+
satisfy more use case.
502+
503+
#### Delegating permission of impersonating wildcard action or wildcard subjects is not supported
504+
505+
Permissions must be delegated using specified verbs with the prefix of `impersonate:` and
506+
`impersonate-on:`. Expressing a permission to impersonate ANY subject or ANY action is not
507+
possible, since the authorization model does not have the concept of partial wildcard on verbs.
508+
It should be ok since all these permission for constrained impersonation are strictly additive which
509+
means it should be added when certain impersonation requests are needed.
479510

480511
## Design Details
481512

@@ -708,12 +739,19 @@ This can be done with:
708739
- a search in the Kubernetes bug triage tool (https://storage.googleapis.com/k8s-triage/index.html)
709740
-->
710741

711-
- SubjectAccessReview check on impersonating user. For RBAC authz mode, this might look like:
742+
- SubjectAccessReview check on impersonating user.
743+
- The impersonator can impersonate bob.
744+
- The impersonator cannot impersonate alice.
745+
- The impersonator can impersonate on listing and getting pods
746+
- The impersonator cannot impersonate on updating pods
747+
- The impersonator can impersonate on getting pod/exec subresource
748+
- The impersonator cannot impersonate on get pod/log subresource
749+
For RBAC authz mode, this might look like:
712750
```yaml
713751
apiVersion: rbac.authorization.k8s.io/v1
714752
kind: ClusterRole
715753
metadata:
716-
name: impersonate-user
754+
name: impersonate-bob
717755
rules:
718756
- apiGroups:
719757
- authentications.k8s.io
@@ -727,28 +765,30 @@ rules:
727765
apiVersion: rbac.authorization.k8s.io/v1
728766
kind: Role
729767
metadata:
730-
name: impersonate:vm:console
768+
name: impersonate-pod-action
731769
namespace: default
732770
rules:
733-
- apiGroups:
734-
- ""
735-
resources:
736-
- nodes
771+
- resources:
772+
- pods
773+
- pod/exec
737774
verbs:
738775
- impersonate-on:list
776+
- impersonate-on:get
739777
```
740-
- The impersonator can impersonate bob.
741-
- The impersonator cannot impersonate alice.
742-
- The impersonator can impersonate on listing nodes
743-
- The impersonator cannot impersonate on updating nodes
744-
745-
- SAR check on impersonate scheduled node with permissions. The impersonator has the
778+
- SAR check on impersonating scheduled node with permissions. The impersonator has the
746779
user extra info of `"authentication.kubernetes.io/node-name": "node1"`
780+
- The impersonator can impersonate node1.
781+
- The impersonator cannot impersonate node2.
782+
- The impersonator cannot impersonate bob.
783+
- The impersonator can impersonate on listing pods.
784+
- The impersonator cannot impersonate on updating pods,
785+
786+
with the permission like this:
747787
```yaml
748788
apiVersion: rbac.authorization.k8s.io/v1
749789
kind: ClusterRole
750790
metadata:
751-
name: impersonate-user
791+
name: impersonate-scheduled-node
752792
rules:
753793
- apiGroups:
754794
- authentications.k8s.io
@@ -760,7 +800,7 @@ rules:
760800
apiVersion: rbac.authorization.k8s.io/v1
761801
kind: Role
762802
metadata:
763-
name: impersonate:vm:console
803+
name: impersonate-pod-action
764804
namespace: default
765805
rules:
766806
- apiGroups:
@@ -770,18 +810,30 @@ rules:
770810
verbs:
771811
- impersonate-on:list
772812
```
773-
- The impersonator can impersonate node1.
774-
- The impersonator cannot impersonate node2.
775-
- The impersonator cannot impersonate bob.
776-
- The impersonator can impersonate on listing pods.
777-
- The impersonator cannot impersonate on updating pods,
778813
779-
- [test name](https://github.com/kubernetes/kubernetes/blob/2334b8469e1983c525c0c6382125710093a25883/test/integration/...): [integration master](https://testgrid.k8s.io/sig-release-master-blocking#integration-master?include-filter-by-regex=MyCoolFeature), [triage search](https://storage.googleapis.com/k8s-triage/index.html?test=MyCoolFeature)
814+
- SAR check on impersonating service account
815+
- SAR check on impersonating nodes
816+
817+
Each test should cover positive and negative cases with multiple resources and verbs.
818+
819+
- Permission delegation:
820+
- bob has the `impersonate:user-info` permission, and can delegate the `impersonate:user-info`
821+
permission to alice.
822+
- bob cannot delegate the `impersonate:node` permission to alice.
823+
- bob has the `impersonate:list` permission on pods resource, and can delegate the permission
824+
to alice.
825+
- bob cannot delegate the `impersonate:update` permission on pods resource to alice.
780826

781827
##### e2e tests
782828

783-
This feature is fully tested with unit and integration tests. An eventual conformance
784-
test is needed as part of GA
829+
In addition to testing with unit and integration tests. E2E tests will be added covering below cases.
830+
831+
- A user cannot impersonate a subresource until the correct constrained impersonation permissions is
832+
set for the user.
833+
- A sericeaccount with the correct constrained impersonation permission is able to impersonate
834+
the node to list pods.
835+
836+
An eventual conformance test is needed as part of GA.
785837

786838
- [test name](https://github.com/kubernetes/kubernetes/blob/2334b8469e1983c525c0c6382125710093a25883/test/e2e/...): [SIG ...](https://testgrid.k8s.io/sig-...?include-filter-by-regex=MyCoolFeature), [triage search](https://storage.googleapis.com/k8s-triage/index.html?test=MyCoolFeature)
787839

@@ -823,8 +875,7 @@ Below are some examples to consider, in addition to the aforementioned [maturity
823875

824876
- Determine if additional tests are necessary
825877
- Ensure reliability of existing tests
826-
- Determine if some caching mechanism should be introduced to reduce the extra
827-
permission check call
878+
- Determine if some mechanism should be introduced to reduce the extra permission checks
828879

829880
#### GA
830881

@@ -924,7 +975,7 @@ Yes. Set the feature gate to false and restart the kube-apiserver.
924975

925976
###### What happens if we reenable the feature if it was previously rolled back?
926977

927-
No addtional configuration is needed.
978+
No additional configuration is needed.
928979

929980
###### Are there any tests for feature enablement/disablement?
930981

@@ -1253,6 +1304,18 @@ Major milestones might include:
12531304

12541305
## Alternatives
12551306

1307+
### Use `impersonate:user-info` instead of `impersonate:serviceaccount` and `impersonate:node`
1308+
1309+
Verb `impersonate:serviceaccount` and `impersonate:node` are special cases of verb
1310+
`impersonate:user-info`. Without these two verbs, it is still possible to use verb
1311+
`impersonate:user-info` with certain username, e.g. username with the prefix
1312+
`system:serviceaccounts:` or the prerix `system:nodes`. However, providing the two special
1313+
verbs would delegation of permissions and support more expressions:
1314+
1315+
- Verb `impersonate:serviceaccount` can support a permission to allow impersonating any
1316+
serviceaccounts in a certain namespace.
1317+
- Verb `impersonate:node` can support a permission to allow impersonating any node.
1318+
12561319
### Subject Access Review
12571320

12581321
The controller can sends a SAR request, and then uses its own permission to perform the action.

0 commit comments

Comments
 (0)