-
Notifications
You must be signed in to change notification settings - Fork 40k
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 selfsubjectrulesreview in authorization #48051
Add selfsubjectrulesreview in authorization #48051
Conversation
Hi @xilabao. 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 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. I understand the commands that are listed here. |
@ericchiang you were thinking something similar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
Would like to see the kubectl code as a different PR. If it's just @kubernetes/sig-auth-pr-reviews that needs to review then we can probably get this in faster. What do you think?
) | ||
|
||
type RESTStorageProvider struct { | ||
Authorizer authorizer.Authorizer | ||
Authorizer authorizer.Authorizer | ||
AuthorizationRuleResolver rbacregistryvalidation.AuthorizationRuleResolver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other kind of authorizers. Can we ensure that this isn't actually tied to the RBAC authorizer by introducing another interface like authorizer.Authorizer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated. PTAL @ericchiang
dedc6db
to
ebc53b5
Compare
ebc53b5
to
6c4e095
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've got some generated code in your first commit.
Also can you explain a bit about what the third commit "create the methods in the generated expansion files" means? Are you creating those manually? Sorry, I'm not super familiar with the generated clientset.
// AuthorizationRulesGetter provides a function that get the list of rules that apply to a given user in a given namespace and error. | ||
// If an error is returned, the slice of rules may not be complete, but it contains all retrievable rules. This is done because policy | ||
// rules are purely additive and policy determinations can be made on the basis of those rules that are found. | ||
type AuthorizationRulesGetter interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The equivalent openshift type is called "AuthorizaitonRuleResolver"[1]. I think authorizaiton.RuleResolver
would be a much more natural fit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think authorizaiton.RuleResolver would be a much more natural fit.
Done.
} | ||
|
||
// Authorizes against a chain of authorizer.AuthorizationRulesGetter objects and returns nil if successful and returns error if unsuccessful | ||
func (authzHandler unionAuthzRulesHandler) RulesFor(user user.Info, namespace string) ([]authorizationapi.ResourceRule, []authorizationapi.NonResourceRule, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected some sort of logic to de-dup identical rules from different authorizers or when one returns a wildcard rule that encompasses the other rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected some sort of logic to de-dup identical rules from different authorizers or when one returns a wildcard rule that encompasses the other rules.
could we sort in kubectl code?
|
||
func NewREST(authorizationRulesGetter authorizer.AuthorizationRulesGetter) *REST { | ||
return &REST{authorizationRulesGetter} | ||
//return &REST{ruleResolver: ruleResolver} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove commented out return.
if !ok { | ||
return nil, apierrors.NewBadRequest("no user present on request") | ||
} | ||
namespace, _ := genericapirequest.NamespaceFrom(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we grabbing a namespace? Isn't the SelfSubjectRulesReview non-namespaced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we grabbing a namespace? Isn't the SelfSubjectRulesReview non-namespaced?
I think that SelfSubjectRulesReview can get the cluster wide rules and the rules in the specified namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which specified namespace? The resource isn't namespaced, so I don't see a way for this to ever hold a value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericchiang you are right. SelfSubjectRulesReview should be namespaced. fixed. ptal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SelfSubjectRulesReview should be namespaced.
No, it definitely should definitely be cluster wide or you'd never be able to get information about cluster level resources. e.g. we need this to help determine what namespaces users have access too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't look right... I'd expect the types to be cluster-scoped, and there to be a spec that allows indicating the namespace to evaluate at (see SelfSubjectAccessReview.Spec.ResourceAttributes.Namespace as a parallel)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't look right... I'd expect the types to be cluster-scoped, a
It seems weird to have a cluster scoped resource that is only valid in the context of a namespace. We can't reasonably evaluate permissions across all namespaces because of fanout. We could give strictly cluster-scoped powers, but that's of limited utility. You're just trying for parity with SAR?
// If an error is returned, the slice of rules may not be complete, but it contains all retrievable rules. This is done because policy | ||
// rules are purely additive and policy determinations can be made on the basis of those rules that are found. | ||
type AuthorizationRulesGetter interface { | ||
RulesFor(user user.Info, namespace string) ([]authorizationapi.ResourceRule, []authorizationapi.NonResourceRule, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to articulate how this method works for cluster wide (non-namespaced) rule evaluation. Particularly since this is only being used to fill out a non-namespaced resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to articulate how this method works for cluster wide (non-namespaced) rule evaluation. Particularly since this is only being used to fill out a non-namespaced resource.
comments added
@@ -20,6 +20,7 @@ import ( | |||
"net/http" | |||
|
|||
"k8s.io/apiserver/pkg/authentication/user" | |||
authorizationapi "k8s.io/kubernetes/pkg/apis/authorization" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know the implications of having this start to import an API package since before it was nicely self contained. cc @deads2k any thoughts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know the implications of having this start to import an API package since before it was nicely self contained.
Done. use "k8s.io/api/authorization/v1" instead of "k8s.io/kubernetes/pkg/apis/authorization"
cfcc972
to
7fb4c2f
Compare
I create those methods manually. I ref to the discussion at #31271 (comment) |
/ok-to-test |
9eaaa68
to
5f4deda
Compare
This is working and I don't see any other outstanding concerns about the API
/lgtm |
/test pull-kubernetes-e2e-kops-aws |
ae322d7
to
790374d
Compare
/test pull-kubernetes-bazel |
/test pull-kubernetes-kubemark-e2e-gce |
/approve |
/test pull-kubernetes-kubemark-e2e-gce |
/lgtm /assign @smarterclayton |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, ericchiang, smarterclayton, xilabao Associated issue: 47834 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/retest |
/test pull-kubernetes-kubemark-e2e-gce |
/retest Review the full test history for this PR. |
/test pull-kubernetes-verify |
/retest |
1 similar comment
/retest |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 45724, 48051, 46444, 51056, 51605) |
@xilabao: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
What this PR does / why we need it:
Which issue this PR fixes: fixes #47834 #31292
Special notes for your reviewer:
Release note:
/cc @deads2k @liggitt