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

Audit RBAC, avoid global (*) permissions #2866

Merged
merged 4 commits into from
Aug 31, 2023

Conversation

akalenyu
Copy link
Collaborator

@akalenyu akalenyu commented Aug 24, 2023

There are some permissions that are logically not needed, and some others where we can just reduce the verb set.
Trying to follow https://kubernetes.io/docs/concepts/security/rbac-good-practices/

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #
https://bugzilla.redhat.com/show_bug.cgi?id=2183659

Special notes for your reviewer:

Release note:

BugFix: Global permissions [*] seen across CDI components

@kubevirt-bot kubevirt-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 DCO signed all their commits. labels Aug 24, 2023
@akalenyu akalenyu marked this pull request as draft August 24, 2023 12:55
@kubevirt-bot kubevirt-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 24, 2023
@@ -54,7 +54,12 @@ func getClusterPolicyRules() []rbacv1.PolicyRule {
"clusterroles",
},
Verbs: []string{
"*",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mhenriks Apparently we have been using escalate for a while, which means the operator
can create clusterroles with more rights than it has
https://kubernetes.io/docs/concepts/security/rbac-good-practices/#escalate-verb

Copy link
Member

Choose a reason for hiding this comment

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

Yikes!

@akalenyu akalenyu force-pushed the less-global-permission-rules branch from 376f0f0 to 1971de3 Compare August 27, 2023 10:27
@akalenyu
Copy link
Collaborator Author

/test pull-containerized-data-importer-e2e-hpp-latest
/test pull-containerized-data-importer-non-csi-hpp
/test pull-containerized-data-importer-e2e-upg
/test pull-containerized-data-importer-e2e-destructive

@akalenyu akalenyu force-pushed the less-global-permission-rules branch from 1971de3 to 5441d2c Compare August 28, 2023 10:07
@akalenyu
Copy link
Collaborator Author

/test all

There are some permissions which are logically not needed,
and some others where we can just reduce the verb set allowed.

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
Following https://kubernetes.io/docs/concepts/security/rbac-good-practices/#control-admission-webhooks
We know the names of our validating/mutating webhooks upfront,
so we can only allow update/delete on those.

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
@akalenyu akalenyu force-pushed the less-global-permission-rules branch from 5441d2c to 9054204 Compare August 28, 2023 15:20
@akalenyu akalenyu marked this pull request as ready for review August 28, 2023 15:20
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 28, 2023
@akalenyu
Copy link
Collaborator Author

/cc @mhenriks

},
Resources: []string{
"customresourcedefinitions",
"customresourcedefinitions/status",
"*",
Copy link
Member

@Barakmor1 Barakmor1 Aug 31, 2023

Choose a reason for hiding this comment

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

nit:
why * shouldn't it be just CDI?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All CDI resources (datavolumes/datasources/..)

Copy link
Member

@Barakmor1 Barakmor1 Aug 31, 2023

Choose a reason for hiding this comment

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

As far as i know the operator doesn't create,update or delete datavolumes/datasources/..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Quick example

cl := &cdiv1.CDIConfigList{}
err := args.Client.List(context.TODO(), cl)

And we should also have uninstall logic that deletes the remaining resources

Copy link
Member

Choose a reason for hiding this comment

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

Oh sorry i missed that 👍

@mhenriks
Copy link
Member

/lgtm
/approve

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 31, 2023
@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mhenriks

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 31, 2023
@kubevirt-bot kubevirt-bot merged commit 9b890db into kubevirt:main Aug 31, 2023
18 checks passed
@awels
Copy link
Member

awels commented Sep 1, 2023

/cherrypick release-v1.57

@kubevirt-bot
Copy link
Contributor

@awels: new pull request created: #2886

In response to this:

/cherrypick release-v1.57

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.

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 DCO signed all their commits. 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants