-
Notifications
You must be signed in to change notification settings - Fork 391
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
✨ Implement RulesFor
for GlobalAuthorizer
and LocalAuthorizer
to enable SelfSubjectRulesReview
#3097
Conversation
Signed-off-by: Marvin Beckers <marvin@kubermatic.com>
roleLister rbacv1listers.RoleClusterLister | ||
roleBindingLister rbacv1listers.RoleBindingClusterLister | ||
clusterRoleBindingLister rbacv1listers.ClusterRoleBindingClusterLister | ||
clusterRoleLister rbacv1listers.ClusterRoleClusterLister |
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.
these were intentional I believe to ensure the informers are started. If you move them into the hot path, the Lister()
call might come to late after the shared informer factory has been started. Creates ugly races.
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.
code comment would be good if this is the case
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.
Yeah, let me bring this back and add a note. I wasn't aware of this and thought they were just written at different times and there was room to unify the code.
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'll do a little PR history search to see if I can find some additional context.
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.
we do similar things in the controllers. They all store listers in their struct to enforce creation of the informers at constructor time.
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.
Deleted my previous comment by mistake. I copied this pattern over from the GlobalAuthorizer
, which also takes SharedInformerFactory
input parameters. Should we adjust that one as well, or is there something special with it that will prevent those races mentioned?
644da14
to
8d784e6
Compare
8d784e6
to
3789416
Compare
@sttts @mjudeikis ready for re-review. |
6068c34
to
5b159c0
Compare
/retest looks like flakes ...? Let's see. Tests are not related I think, but maybe I broke something. |
5b159c0
to
3ffeccb
Compare
&rbac.ClusterRoleBindingLister{Lister: globalKubeInformers.Rbac().V1().ClusterRoleBindings().Lister().Cluster(clusterName)}, | ||
) | ||
}, | ||
globalRoleLister: globalKubeInformers.Rbac().V1().Roles().Lister(), |
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: globalRoles
Would be less noisy.
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 tried to keep it consistent with LocalAuthorizer
, which looks like this:
a := &LocalAuthorizer{
// listers are saved in the struct here to ensure that informers are started and we do not encounter race conditions with them.
roleLister: versionedInformers.Rbac().V1().Roles().Lister(),
roleBindingLister: versionedInformers.Rbac().V1().RoleBindings().Lister(),
clusterRoleLister: versionedInformers.Rbac().V1().ClusterRoles().Lister(),
clusterRoleBindingLister: versionedInformers.Rbac().V1().ClusterRoleBindings().Lister(),
}
@@ -41,6 +42,7 @@ type LocalAuthorizer struct { | |||
|
|||
func NewLocalAuthorizer(versionedInformers kcpkubernetesinformers.SharedInformerFactory) (authorizer.Authorizer, authorizer.RuleResolver) { | |||
a := &LocalAuthorizer{ | |||
// listers are saved in the struct here to ensure that informers are started and we do not encounter race conditions with them. |
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: are instantiated early and ... with starting them
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.
Much clearer, thanks. Updated the comments.
Some nits. /lgtm if you want to address the nits. |
LGTM label has been added. Git tree hash: f0636f9bf7e16fa0a836af78aa11003cf66051b8
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sttts The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…ment RulesFor Signed-off-by: Marvin Beckers <marvin@kubermatic.com>
Signed-off-by: Marvin Beckers <marvin@kubermatic.com>
Signed-off-by: Marvin Beckers <marvin@kubermatic.com>
3ffeccb
to
6b55a8e
Compare
/hold cancel Addressed comment nit. I'm not 100% sure how to proceed with the lister fields, but from my perspective it's okay, so this can go in with an lgtm. |
/lgtm |
LGTM label has been added. Git tree hash: 7b33ee050e76409f80b7eff394e2ae23daa6a498
|
Summary
This PR implements the stub
RulesFor
methods for bothGlobalAuthorizer
andLocalAuthorizer
to enable usage of theSelfSubjectRulesReview
API. I'll be completely honest, this felt "too easy", so I hope I'm doing the correct thing here. Output ofkubectl auth can-i --list
looked sensible to me.Basically, I've aligned the way both the global and the local authorizer generate their cluster-specific authorizer and just called
RulesFor
on the scoped authorizer created from it. After PR review, I've also added two e2e test cases that make sure that theSelfSubjectRulesReview
API gives expected responses.On a minor note, this PR cleans up the
OWNERS
file because it's from the before times (unless we want to keep access to this package limited, which might be fair).Related issue(s)
Fixes #1924
Release Notes