Skip to content

Conversation

@JonCrowther
Copy link
Contributor

@JonCrowther JonCrowther commented Sep 29, 2023

Issue: #42215

New Feature

Adds NamespacedRules to the GlobalRole field. Details of the field can be found in the issue, but in summation:

  • When a global role (GR) is created, a role is created in each namespace with the listed rules
  • When a global role binding (GRB) is created, a role binding is created in each namespace that binds to the namespaced roles
  • When the role/role binding is modified, it checks if it's owned by a GR/GRB and then enqueues it to be verified

The work is split in the following commits:

  1. Add the NamespacedRules field
  2. Add GRB support
  3. Add GR support
  4. Add enqueueing

Testing

  1. Create a GlobalRole with the new NamespacedRules field
    • It creates Roles based on the NamespacedRules
  2. Create a GlobalRoleBinding with the above GlobalRole
    • It creates RoleBindings based on the NamespacedRules of the GR
  3. Delete GR/GRB
    • Removes all Roles/RoleBindings

Engineering Testing

Manual Testing

Automated Testing

  • Test types added/modified:
    • Unit
    • Integration (Go Framework) TODO
    • Integration (v2prov Framework) TODO

Summary: Unit tests for all new code and integration tests (TODO)

QA Testing Considerations

Regressions Considerations

This is a new field, so there shouldn't be any regressions. While the update/create functions for GR/GRBs got modified, the new check only occurs when the field is populated.

Existing / newly added automated tests that provide evidence there are no regressions:

  • The existing RBAC integration tests prove that the previous RBAC functionality has not been modified

Security Considerations

Need a security assessment to ensure this doesn't introduce CVEs

@JonCrowther JonCrowther self-assigned this Sep 29, 2023
@JonCrowther JonCrowther force-pushed the namespaced-rule-field branch 2 times, most recently from 65f7cc0 to 4849f6b Compare October 2, 2023 14:08
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this test to get 100% code coverage of enqueue.go. I didn't make or modify this function

@JonCrowther JonCrowther force-pushed the namespaced-rule-field branch from 4849f6b to c43f703 Compare October 2, 2023 14:56
@JonCrowther JonCrowther marked this pull request as ready for review October 2, 2023 15:14
@JonCrowther
Copy link
Contributor Author

Integration tests are in progress, opening for review to get feedback on functionality.

@JonCrowther JonCrowther requested review from MbolotSuse, eliyamlevy, pjbgf and tomleb and removed request for tomleb October 2, 2023 15:15
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

two small nits:

Copy link
Contributor

@MbolotSuse MbolotSuse left a comment

Choose a reason for hiding this comment

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

Couple of standout issues:

  • We need to use name.SafeConcatName on the label values
  • The purge methods should delete roles/bindings in the same namespace that claim ownership by a GR/GRB but aren't actually owned by that GR/GRB
  • We can't update the roleRef on a binding, so you need to delete/create for the binding case instead of update

@JonCrowther
Copy link
Contributor Author

JonCrowther commented Oct 16, 2023

Newest commit adds the following small reworks:

  • Use of wrangler.SafeConcatName for the label
  • Moved the purge unit tests into the larger reconcile unit tests
  • More unit tests that had been missed
  • More comments
  • Improved explanation of how * is not supported
  • Through manual testing, realized I needed DeleteNamespaced to delete Roles and RoleBindings, not just Delete
  • Ran go mod tidy to make the CI happy

Large rework:

  • Instead of searching for incorrectly made Role and RoleBindings, I create a list of all the correct items (using UID) while creating/updating all the Role/Bindings. After I select all Role/Bindings with the owner label and delete any that are not in my list of UIDs to keep. That way it should be more comprehensive in deleting Role/Bindings and avoid edge cases

@JonCrowther JonCrowther force-pushed the namespaced-rule-field branch 2 times, most recently from b7363dc to 6f7ee6c Compare October 16, 2023 21:54
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

Pointed a few minor nits regarding clarity - feel free to ignore.

@JonCrowther JonCrowther force-pushed the namespaced-rule-field branch from 6f7ee6c to fc8f0c0 Compare October 19, 2023 14:25
pjbgf
pjbgf previously approved these changes Oct 20, 2023
Copy link
Contributor

@MbolotSuse MbolotSuse left a comment

Choose a reason for hiding this comment

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

Couple of comments on missing uses of safeConcatName, as well as some efficiency improvements.

Copy link
Contributor

@tomleb tomleb left a comment

Choose a reason for hiding this comment

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

Some comments

@JonCrowther
Copy link
Contributor Author

New commit changes:

  • Added functionality for handling deleting/creating namespaces in the NamespacedRules field
    • Added an enqueuer to enqueue a GR when a namespace is modified
    • If namespace doesn't exist, warn the user but don't re-enqueue the reconcile
    • If namespace is terminating, don't attempt to create Roles/RoleBindings
    • Tested this manually (as well as unit tests). If the namespace gets created the Roles/RoleBindings get created too.
  • Improved the efficiency of purging invalid Roles/RoleBindings by using maps
  • Added and improved comments
  • Reduced nested ifs by using continues
  • Improved unit tests
  • Used safeConcatName more consistently throughout and used indexers in the enqueuers to get GR/GRBs based on the new safeConcatName versions of the label

@JonCrowther JonCrowther force-pushed the namespaced-rule-field branch from eb0fb87 to 006f500 Compare October 30, 2023 21:51
tomleb
tomleb previously approved these changes Oct 31, 2023
Copy link
Contributor

@MbolotSuse MbolotSuse left a comment

Choose a reason for hiding this comment

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

A couple of nits, but nothing that I think needs to be fixed for this to go in. I'm ok to approve the PR once the CI passes.

Comment on lines 200 to 208
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I highly recommend not creating tests cases like this which rely on call order to function. This highly couples your test case to the internal implementation of the underlying code, and can create flaky tests which fail when a specific order occurs.

In this case, I would recommend pre-computing the name of each role that might be retrieved, and then return a specific response for the specific roles which are being called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So in this specific test case I could get rid of the counter since I'm trying to get into the error path. However, I kept a similar pattern for the test at line 224. I've added more comments to explain the reason, and changed the counter to be modified based on when Create gets called, not just on consecutive Get calls.

I considered removing the test at 224, but I think it's important functionality to test. The difficulty is that the Get function gets called with the same input twice, but the expected behaviour changes depending on when it happens. I personally think modifying the counter to indicate before and after Create makes it less flaky, but if you feel it shouldn't exist I won't argue much.

tomleb
tomleb previously approved these changes Nov 13, 2023
Copy link
Contributor

@tomleb tomleb left a comment

Choose a reason for hiding this comment

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

No changes since last approval so LGTM. Just added a nit.

tomleb
tomleb previously approved these changes Nov 14, 2023
@JonCrowther JonCrowther force-pushed the namespaced-rule-field branch from 3284ace to 81b1df3 Compare January 8, 2024 20:00
@JonCrowther JonCrowther changed the base branch from release/v2.8 to release/v2.9 January 8, 2024 20:00
@JonCrowther
Copy link
Contributor Author

Rebased and pointed to release/v2.9

@JonCrowther JonCrowther requested a review from tomleb January 8, 2024 20:02
Copy link
Contributor

@MbolotSuse MbolotSuse left a comment

Choose a reason for hiding this comment

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

LGTM - don't see any issue due to rebase changes.

@JonCrowther JonCrowther merged commit 7c3215d into rancher:release/v2.9 Jan 10, 2024
@JonCrowther JonCrowther deleted the namespaced-rule-field branch January 10, 2024 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants