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 rules #616

Merged
merged 1 commit into from
Jul 5, 2023
Merged

Audit RBAC rules #616

merged 1 commit into from
Jul 5, 2023

Conversation

jcanocan
Copy link
Contributor

@jcanocan jcanocan commented Jul 3, 2023

What this PR does / why we need it:
As it is now, some of the RBAC rules and/or verbs are not required for the operator to be able to perform all intended operations.
This PR audits all RBAC rules. The auditory has been carried out following a black box approach, i.e., remove all rules, deploy the operator, run functest, collect forbidden operations, add the missing rules/verbs and repeat. The auditing process has been split in the next action items:

  • Deploying the operator in KubevirtCI.
  • Deploying the operator in a CRC cluster and running the functest.
  • Deploying the operator in a 3 masters and 3 workers nodes and running the functest.
  • Deploying a custom downstream build and running the Tier 2 test.

Just in case changes are not clear enough, this is a simplified and normalized diff of the ClusterRole file before and after: https://www.textcompare.org/?id=64a2c9d599377eb6104d8ae3

The simplified version has been obtained using this script.

jira-ticket: https://issues.redhat.com/browse/CNV-24031

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Release note:

Reduce the `ClusterRole` rules used

@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L labels Jul 3, 2023
@kubevirt-bot kubevirt-bot requested review from akrejcir and lyarwood July 3, 2023 13:08
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 3, 2023
Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

Great effort! Added some comments.

@@ -94,14 +94,11 @@ func NewSspReconciler(client client.Client, uncachedReader client.Reader, infras

var _ reconcile.Reconciler = &sspReconciler{}

// +kubebuilder:rbac:groups=ssp.kubevirt.io,resources=ssps,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=ssp.kubevirt.io,resources=ssps/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=ssp.kubevirt.io,resources=ssps,verbs=list;watch;update
Copy link
Member

Choose a reason for hiding this comment

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

Why does SSP need to update the SSP CR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without that verb, the BeforeSuite fails on this assert

EventuallyWithOffset(1, func() bool {
. So I suppose that SSP needs to update at least the Generation field in presence changes to it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No the Generation field is updated by k8s API server.
SSP operator needs to add finalizer to the SSP CR:

func initialize(request *common.Request) error {
controllerutil.AddFinalizer(request.Instance, finalizerName)
return updateSspResource(request)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh nice! Thanks for the clarifications :-)

@@ -500,27 +423,14 @@ spec:
- virtualmachines/stop
verbs:
- update
- apiGroups:
Copy link
Member

Choose a reason for hiding this comment

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

Did you enable all feature gates during testing? SSP can deploy Tekton resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Tekton tasks have also been tested.

It removes all no required RBAC rules and verbs. The used process has
been a black box approach, i.e., remove all rules, deploy the operator,
run functest, collect forbidden operations, add the missing rules/verbs
and repeat.

To ensure a better coverage, Tier 2 tests have also been run.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jcanocan
Copy link
Contributor Author

jcanocan commented Jul 4, 2023

V2:

  • Rebased branch

@lyarwood
Copy link
Member

lyarwood commented Jul 4, 2023

/lgtm

Thanks this looks good to me, any lack of coverage in CI for these rules would be a serious bug IMHO so I'm happy trusting it for now.

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 4, 2023
Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

Thanks!

/approve

@jcanocan
Copy link
Contributor Author

jcanocan commented Jul 4, 2023

/retest-required

@0xFelix
Copy link
Member

0xFelix commented Jul 5, 2023

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 0xFelix

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 Jul 5, 2023
@kubevirt-bot kubevirt-bot merged commit 143d3e4 into kubevirt:main Jul 5, 2023
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.

5 participants