Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auth API to get self subject attributes #111333

Merged
merged 1 commit into from Sep 14, 2022

Conversation

nabokihms
Copy link
Member

@nabokihms nabokihms commented Jul 22, 2022

Signed-off-by: m.nabokikh maksim.nabokikh@flant.com

What type of PR is this?

/kind feature
/kind api-change

What this PR does / why we need it:

As KEP states:

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.

Which issue(s) this PR fixes:

This PR is a part of kubernetes/enhancements#3325

Special notes for your reviewer:

  • new API endpoints
  • code generation
  • kubectl command
  • unit tests
  • feature flag
  • e2e tests

Does this PR introduce a user-facing change?

Add auth API to get self subject attributes (new selfsubjectreviews API is added). 
The corresponding command for kubctl is provided - `kubectl auth whoami`.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

- [KEP]: https://github.com/kubernetes/enhancements/issues/3325
- [Docs]: https://github.com/kubernetes/website/pull/35385
- [e2e]: https://github.com/kubernetes/test-infra/pull/26999

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 22, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @nabokihms. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jul 22, 2022
@nabokihms
Copy link
Member Author

/sig auth

@k8s-ci-robot k8s-ci-robot added sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 22, 2022
@k8s-ci-robot k8s-ci-robot added area/kubectl area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jul 22, 2022
@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@@ -220,6 +220,7 @@ func ClusterRoles() []rbacv1.ClusterRole {
Rules: []rbacv1.PolicyRule{
// TODO add future selfsubjectrulesreview, project request APIs, project listing APIs
rbacv1helpers.NewRule("create").Groups(authorizationGroup).Resources("selfsubjectaccessreviews", "selfsubjectrulesreviews").RuleOrDie(),
rbacv1helpers.NewRule("create").Groups(authenticationGroup).Resources("selfsubjectattributesreviews").RuleOrDie(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means that distros that wish to restrict access to this API, must disable API when it goes GA. I think this is reasonable, but wanted to call it out explicitly for other reviewers.

Copy link
Member

@enj enj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not reviewed this PR yet but the feature gate comment is wrong now.

pkg/features/kube_features.go Outdated Show resolved Hide resolved
@enj
Copy link
Member

enj commented Aug 23, 2022

/lgtm cancel

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 23, 2022
@nabokihms nabokihms requested review from enj and removed request for aojea and deads2k August 24, 2022 14:01
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2022
@liggitt
Copy link
Member

liggitt commented Aug 31, 2022

master is open for 1.26, once this gets rebased it looks ready for merge

@enj enj added this to Needs Triage in SIG Auth Old Sep 12, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 14, 2022
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
@nabokihms
Copy link
Member Author

/retest

@deads2k
Copy link
Contributor

deads2k commented Sep 14, 2022

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 14, 2022
@k8s-ci-robot k8s-ci-robot merged commit 4e8b11d into kubernetes:master Sep 14, 2022
SIG Auth Old automation moved this from Needs Triage to Closed / Done Sep 14, 2022
@sftim
Copy link
Contributor

sftim commented Sep 20, 2022

- [KEP]: https://github.com/kubernetes/enhancements/issues/3325
- [Docs]: https://github.com/kubernetes/website/pull/35385
- [e2e]: https://github.com/kubernetes/test-infra/pull/26999

“Docs” should be a link to the documentation for the feature, not to the PR that first added it. @nabokihms would you be willing to revise?

@nabokihms
Copy link
Member Author

@sftim yes, I will, but I think we should wait for the doc to be merged first.

sar := &authenticationv1alpha1.SelfSubjectReview{}
response, err := o.authClient.SelfSubjectReviews().Create(context.TODO(), sar, metav1.CreateOptions{})
if err != nil {
if errors.IsNotFound(err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the feature is not enabled on the server, the permission to run this will not be included in the basic-user role, and users are likely to get a forbidden error... it might be worth detecting forbidden errors and saying something like "The selfsubjectreviews API is not enabled in the cluster or you do not have permission to call it..." to clarify the possible reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/code-generation area/dependency Issues or PRs related to dependency changes area/kubectl area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.26
Archived in project
SIG Auth Old
Closed / Done
Development

Successfully merging this pull request may close these issues.

None yet