Skip to content

Commit 583c8df

Browse files
authored
Merge pull request kubernetes#3326 from nabokihms/3325-self-user-attributes-review-api
KEP-3325: Auth API to get self user attributes
2 parents c3c2509 + 9f17245 commit 583c8df

File tree

3 files changed

+399
-0
lines changed

3 files changed

+399
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kep-number: 3325
2+
alpha:
3+
approver: "@deads2k"
Lines changed: 367 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,367 @@
1+
# KEP-3325: Self subject attributes review API
2+
3+
<!-- toc -->
4+
- [Release Signoff Checklist](#release-signoff-checklist)
5+
- [Summary](#summary)
6+
- [Motivation](#motivation)
7+
- [Goals](#goals)
8+
- [Non-Goals](#non-goals)
9+
- [Proposal](#proposal)
10+
- [Design Details](#design-details)
11+
- [Request](#request)
12+
- [RBAC](#rbac)
13+
- [Test Plan](#test-plan)
14+
- [Graduation Criteria](#graduation-criteria)
15+
- [Alpha](#alpha)
16+
- [Beta](#beta)
17+
- [GA](#ga)
18+
- [Production Readiness Review Questionnaire](#production-readiness-review-questionnaire)
19+
- [Feature Enablement and Rollback](#feature-enablement-and-rollback)
20+
- [Rollout, Upgrade and Rollback Planning](#rollout-upgrade-and-rollback-planning)
21+
- [Monitoring Requirements](#monitoring-requirements)
22+
- [Dependencies](#dependencies)
23+
- [Scalability](#scalability)
24+
- [Troubleshooting](#troubleshooting)
25+
- [Implementation History](#implementation-history)
26+
- [Alternatives](#alternatives)
27+
<!-- /toc -->
28+
29+
## Release Signoff Checklist
30+
31+
Items marked with (R) are required *prior to targeting to a milestone / release*.
32+
33+
- [ ] (R) Enhancement issue in release milestone, which links to KEP dir in [kubernetes/enhancements] (not the initial KEP PR)
34+
- [ ] (R) KEP approvers have approved the KEP status as `implementable`
35+
- [ ] (R) Design details are appropriately documented
36+
- [ ] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors)
37+
- [ ] e2e Tests for all Beta API Operations (endpoints)
38+
- [ ] (R) Ensure GA e2e tests for meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
39+
- [ ] (R) Minimum Two Week Window for GA e2e tests to prove flake free
40+
- [ ] (R) Graduation criteria is in place
41+
- [ ] (R) [all GA Endpoints](https://github.com/kubernetes/community/pull/1806) must be hit by [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
42+
- [ ] (R) Production readiness review completed
43+
- [ ] (R) Production readiness review approved
44+
- [ ] "Implementation History" section is up-to-date for milestone
45+
- [ ] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io]
46+
- [ ] Supporting documentation—e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes
47+
48+
<!--
49+
**Note:** This checklist is iterative and should be reviewed and updated every time this enhancement is being considered for a milestone.
50+
-->
51+
52+
[kubernetes.io]: https://kubernetes.io/
53+
[kubernetes/enhancements]: https://git.k8s.io/enhancements
54+
[kubernetes/kubernetes]: https://git.k8s.io/kubernetes
55+
[kubernetes/website]: https://git.k8s.io/website
56+
57+
## Summary
58+
59+
There is no resource which represents a user in Kubernetes. Instead, Kubernetes has authenticators to get user attributes from tokens or x509 certificates or by using the OIDC provider or receiving them from the external webhook. This KEP proposes adding a new API endpoint to see what attributes the current user has after the authentication.
60+
61+
## Motivation
62+
63+
Authentication is complicated, especially made by [proxy](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#authenticating-proxy) or [webhook](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#webhook-token-authentication) authenticators or their combinations.
64+
It may be obscure which user attributes the user eventually gets after all that magic happened before authentication.
65+
The motivation for this KEP is to reduce obscurity and help users with debugging the authentication stack.
66+
67+
### Goals
68+
69+
- Add the API endpoint to get user attributes
70+
- Add a corresponding kubectl command - `kubectl auth who-am-i`
71+
72+
### Non-Goals
73+
74+
## Proposal
75+
76+
Add a new API endpoint to the `authentication.k8s.io` group - `SelfSubjectAttributesReview`.
77+
The user will hit the endpoint after authentication happens, so all attributes will be available to return.
78+
79+
## Design Details
80+
81+
This design is inspired by the `*AccessReview` and `TokenReview` APIs.
82+
The endpoint has no input parameters or a `spec` field because only the authentication result is required.
83+
84+
### Request
85+
86+
The structure for building a request:
87+
```go
88+
type SelfSubjectAttributesReview struct {
89+
metav1.TypeMeta `json:",inline"`
90+
// Standard list metadata.
91+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
92+
// +optional
93+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
94+
// Status is filled in by the server with the user attributes.
95+
Status SelfSubjectAttributesReviewStatus `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"`
96+
}
97+
```
98+
```go
99+
type SelfSubjectAttributesReviewStatus struct {
100+
// User attributes of the current user.
101+
// +optional
102+
UserInfo authenticationv1.UserInfo `json:"userInfo,omitempty" protobuf:"bytes,1,opt,name=userInfo"`
103+
}
104+
```
105+
106+
On receiving a request, the Kubernetes API server fills the status with the user attributes and returns it to the user.
107+
108+
Request example (the body would be a `SelfSubjectAttributesReview` object):
109+
```
110+
POST /apis/authentication.k8s.io/v1alpha1/selfsubjectattributesreview
111+
```
112+
```json
113+
{
114+
"apiVersion": "authentication.k8s.io/v1alpha1",
115+
"kind": "SelfSubjectAttributesReview"
116+
}
117+
```
118+
Response example:
119+
120+
```json
121+
{
122+
"apiVersion": "authentication.k8s.io/v1alpha1",
123+
"kind": "SelfSubjectAttributesReview",
124+
"status": {
125+
"name": "jane.doe",
126+
"uid": "b6c7cfd4-f166-11ec-8ea0-0242ac120002",
127+
"groups": ["viewers", "editors"],
128+
"extra": {
129+
"provider_id": "token.company.dev"
130+
}
131+
}
132+
}
133+
```
134+
135+
User attributes are known at the moment of accessing the rest API endpoint and can be extracted from the request context.
136+
137+
NOTE: Unlike the TokenReview, there are no audiences in requests and responses since
138+
the SelfSubjectAttributesReview API can only be accessed using valid credentials against the API server,
139+
meaning that the audience must always be that of the API server. Thus learning this value is not practical.
140+
141+
### RBAC
142+
143+
RBAC rules to grant access to this API should be present in the cluster by default.
144+
It is implied that the `system:basic-user` cluster role will be extended to the following:
145+
```yaml
146+
apiVersion: rbac.authorization.k8s.io/v1
147+
kind: ClusterRole
148+
metadata:
149+
annotations:
150+
rbac.authorization.kubernetes.io/autoupdate: "true"
151+
labels:
152+
kubernetes.io/bootstrapping: rbac-defaults
153+
name: system:basic-user
154+
rules:
155+
- apiGroups:
156+
- authorization.k8s.io
157+
resources:
158+
- selfsubjectaccessreviews
159+
- selfsubjectrulesreviews
160+
verbs:
161+
- create
162+
- apiGroups:
163+
- authentication.k8s.io
164+
resources:
165+
- selfsubjectattributesreviews
166+
verbs:
167+
- create
168+
```
169+
170+
After reaching GA, the SelfSubjectAttributesReview API will be enabled by default.
171+
If necessary, it will be possible to disable this API by using the following kube-apiserver flag:
172+
```
173+
--runtime-config=authentication.k8s.io/v1alpha1/selfsubjectattributesreviews=false
174+
```
175+
176+
### Test Plan
177+
178+
Unit tests covering:
179+
180+
1. Request returns all user attributes
181+
2. Request returns some user attributes
182+
3. Request with a status returns overridden fields
183+
184+
Integration tests covering:
185+
186+
1. Successful authentication through a simple authenticator, e.g., token or certificate authenticator
187+
2. Successful authentication through a complicated authenticator, e.g., webhook or authentication proxy authenticator
188+
3. Failed authentication
189+
190+
Command line interface tests covering:
191+
1. How successful responses are rendered in the terminal with various output modes.
192+
2. How errors are rendered.
193+
194+
### Graduation Criteria
195+
196+
`authentication.k8s.io/v1alpha1` and `authentication.k8s.io/v1beta1` apis will be reintroduced to go through the graduation cycle.
197+
198+
#### Alpha
199+
200+
- Feature implemented behind a feature flag
201+
- Initial unit and integration tests completed and enabled
202+
203+
#### Beta
204+
205+
- Gather feedback from users
206+
207+
#### GA
208+
209+
- Corresponding kubectl command implemented
210+
211+
NOTE: Should not be a part of [conformance tests](https://git.k8s.io/community/contributors/devel/sig-architecture/conformance-tests.md).
212+
The fact that a user possesses a token does not necessarily imply the power to know to whom that token belongs.
213+
214+
## Production Readiness Review Questionnaire
215+
216+
### Feature Enablement and Rollback
217+
218+
###### How can this feature be enabled / disabled in a live cluster?
219+
220+
<!--
221+
Pick one of these and delete the rest.
222+
-->
223+
224+
- Feature gate
225+
- Feature gate name: `SelfSubjectAttributesReview`
226+
- Components depending on the feature gate:
227+
- kube-apiserver
228+
229+
```go
230+
FeatureSpec{
231+
Default: false,
232+
LockToDefault: false,
233+
PreRelease: featuregate.Alpha,
234+
}
235+
```
236+
237+
###### Does enabling the feature change any default behavior?
238+
239+
It only adds new behavior and does not affect other pars of the Kubernetes.
240+
241+
###### Can the feature be disabled once it has been enabled (i.e. can we roll back the enablement)?
242+
243+
Yes.
244+
245+
###### What happens if we reenable the feature if it was previously rolled back?
246+
247+
It is possible to toggle this feature any number of times.
248+
249+
###### Are there any tests for feature enablement/disablement?
250+
251+
Does not require special testing frameworks.
252+
253+
### Rollout, Upgrade and Rollback Planning
254+
255+
###### How can a rollout or rollback fail? Can it impact already running workloads?
256+
257+
Enabling the feature does not affect any workloads.
258+
259+
###### What specific metrics should inform a rollback?
260+
261+
Specific metrics are not required for the monitoring of this feature.
262+
263+
###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested?
264+
265+
<!--
266+
Describe manual testing that was done and the outcomes.
267+
Longer term, we may want to require automated upgrade/rollback tests, but we
268+
are missing a bunch of machinery and tooling and can't do that now.
269+
-->
270+
271+
###### Is the rollout accompanied by any deprecations and/or removals of features, APIs, fields of API types, flags, etc.?
272+
273+
Yes.
274+
275+
### Monitoring Requirements
276+
277+
###### How can an operator determine if the feature is in use by workloads?
278+
279+
It is possible to see the rate of requests to the REST API endpoint.
280+
281+
###### How can someone using this feature know that it is working for their instance?
282+
283+
It will be possible to make a request to the REST API endpoint.
284+
285+
###### What are the reasonable SLOs (Service Level Objectives) for the enhancement?
286+
287+
The feature utilizes core mechanisms of the Kubernetes API server, so the maximum possible SLO is applicable.
288+
289+
###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service?
290+
291+
The apiserver_request_* metrics family is helpful to be aware of how many requests to the endpoint are in your cluster and how many of them failed.
292+
```
293+
{__name__=~"apiserver_request_.*", group="authentication.k8s.io", resource="selfsubjectattributesreview"}
294+
```
295+
296+
###### Are there any missing metrics that would be useful to have to improve observability of this feature?
297+
298+
All useful metrics are already present. This feature only requires metrics linked to authentication process.
299+
300+
### Dependencies
301+
302+
###### Does this feature depend on any specific services running in the cluster?
303+
304+
It depends only on authentication and how this process is tuned in the current Kubernetes cluster.
305+
306+
### Scalability
307+
308+
###### Will enabling / using this feature result in any new API calls?
309+
310+
No.
311+
312+
###### Will enabling / using this feature result in introducing new API types?
313+
314+
```
315+
Group: authentication.k8s.io
316+
Kind: SelfSubjectAttributesReview
317+
```
318+
319+
###### Will enabling / using this feature result in any new calls to the cloud provider?
320+
321+
No.
322+
323+
###### Will enabling / using this feature result in increasing size or count of the existing API objects?
324+
325+
No.
326+
327+
###### Will enabling / using this feature result in increasing time taken by any operations covered by existing SLIs/SLOs?
328+
329+
No.
330+
331+
###### Will enabling / using this feature result in non-negligible increase of resource usage (CPU, RAM, disk, IO, ...) in any components?
332+
333+
No.
334+
335+
### Troubleshooting
336+
337+
###### How does this feature react if the API server and/or etcd is unavailable?
338+
339+
The authentication error will be returned.
340+
341+
###### What are other known failure modes?
342+
343+
The only possible errors are authentication errors.
344+
345+
###### What steps should be taken if SLOs are not being met to determine the problem?
346+
347+
No steps required.
348+
349+
## Implementation History
350+
351+
<!--
352+
Major milestones in the lifecycle of a KEP should be tracked in this section.
353+
Major milestones might include:
354+
- the `Summary` and `Motivation` sections being merged, signaling SIG acceptance
355+
- the `Proposal` section being merged, signaling agreement on a proposed design
356+
- the date implementation started
357+
- the first Kubernetes release where an initial version of the KEP was available
358+
- the version of Kubernetes where the KEP graduated to general availability
359+
- when the KEP was retired or superseded
360+
-->
361+
362+
## Alternatives
363+
364+
This feature can be implemented by delegating some requests to the external API server.
365+
A good example of this schema working is [vmware-tanzu/pinniped](https://github.com/vmware-tanzu/pinniped) and their [`whoami`](https://github.com/vmware-tanzu/pinniped/blob/main/apis/concierge/identity/types_whoami.go.tmpl) API.
366+
367+
However, it is complicated to maintain an additional API server for this case, and it integrates poorly with tooling, e.g., client-go, kubectl.

0 commit comments

Comments
 (0)