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

✨ Implement RulesFor for GlobalAuthorizer and LocalAuthorizer to enable SelfSubjectRulesReview #3097

Merged
merged 4 commits into from
Apr 4, 2024

Conversation

embik
Copy link
Member

@embik embik commented Mar 25, 2024

Summary

This PR implements the stub RulesFor methods for both GlobalAuthorizer and LocalAuthorizer to enable usage of the SelfSubjectRulesReview API. I'll be completely honest, this felt "too easy", so I hope I'm doing the correct thing here. Output of kubectl 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 the SelfSubjectRulesReview 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

Implement `SelfSubjectRulesReview` API, enabling usage of e.g. `kubectl auth can-i --list`

Signed-off-by: Marvin Beckers <marvin@kubermatic.com>
@embik embik requested a review from sttts March 25, 2024 13:17
@kcp-ci-bot kcp-ci-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 25, 2024
roleLister rbacv1listers.RoleClusterLister
roleBindingLister rbacv1listers.RoleBindingClusterLister
clusterRoleBindingLister rbacv1listers.ClusterRoleBindingClusterLister
clusterRoleLister rbacv1listers.ClusterRoleClusterLister
Copy link
Member

@sttts sttts Mar 28, 2024

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.

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member Author

@embik embik Mar 30, 2024

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.

Copy link
Member

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.

Copy link
Member Author

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?

@embik embik force-pushed the authorizer-rules-for branch from 644da14 to 8d784e6 Compare April 3, 2024 09:43
@kcp-ci-bot kcp-ci-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 3, 2024
@embik embik force-pushed the authorizer-rules-for branch from 8d784e6 to 3789416 Compare April 3, 2024 09:47
@embik
Copy link
Member Author

embik commented Apr 3, 2024

@sttts @mjudeikis ready for re-review.

@embik embik requested review from sttts and mjudeikis April 3, 2024 09:48
@embik embik force-pushed the authorizer-rules-for branch from 6068c34 to 5b159c0 Compare April 3, 2024 10:33
@embik
Copy link
Member Author

embik commented Apr 3, 2024

/retest

looks like flakes ...? Let's see. Tests are not related I think, but maybe I broke something.

@embik embik force-pushed the authorizer-rules-for branch from 5b159c0 to 3ffeccb Compare April 3, 2024 12:13
&rbac.ClusterRoleBindingLister{Lister: globalKubeInformers.Rbac().V1().ClusterRoleBindings().Lister().Cluster(clusterName)},
)
},
globalRoleLister: globalKubeInformers.Rbac().V1().Roles().Lister(),
Copy link
Member

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.

Copy link
Member Author

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.
Copy link
Member

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

Copy link
Member Author

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.

@sttts
Copy link
Member

sttts commented Apr 4, 2024

Some nits.

/lgtm
/approve
/hold

if you want to address the nits.

@kcp-ci-bot kcp-ci-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 4, 2024
@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 4, 2024
@kcp-ci-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: f0636f9bf7e16fa0a836af78aa11003cf66051b8

@kcp-ci-bot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kcp-ci-bot kcp-ci-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 4, 2024
embik added 3 commits April 4, 2024 11:57
…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>
@embik embik force-pushed the authorizer-rules-for branch from 3ffeccb to 6b55a8e Compare April 4, 2024 09:57
@kcp-ci-bot kcp-ci-bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 4, 2024
@kcp-ci-bot kcp-ci-bot requested a review from sttts April 4, 2024 09:57
@embik
Copy link
Member Author

embik commented Apr 4, 2024

/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.

@kcp-ci-bot kcp-ci-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 4, 2024
@sttts
Copy link
Member

sttts commented Apr 4, 2024

/lgtm

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 4, 2024
@kcp-ci-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 7b33ee050e76409f80b7eff394e2ae23daa6a498

@kcp-ci-bot kcp-ci-bot merged commit ca53991 into kcp-dev:main Apr 4, 2024
16 checks passed
@embik embik deleted the authorizer-rules-for branch April 4, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: API server panics on SelfSubjectRulesReview requests
4 participants