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

Fix roletemplate.rules validation, added standard k8s checks #328

Conversation

andreas-kupries
Copy link
Contributor

@andreas-kupries andreas-kupries commented Jan 29, 2024

Issue:

See rancher/rancher#40584

Problem

As described in the referenced issue, the roletemplate rules validation performs only a subset of the checks done by k8s on policy roles (besides the rancher-specific checks). In the referenced issue this is noted for apiGroups. The same problem would happen for the resources. The verbs field is ok, because this is checked explicitly.

Solution

The chosen solution calls on k8s functionality performing the entire set of rule checks for us.
The basic ability to do so was added with #309.

The core function for doing so, validateRules, is moved out of globalrole into the common package, to keep DRY.
As part of this unit tests were added. The tests pass.

After this refactor the roletemplate package is simply extended to call on this functionality.

CheckList

  • Test
  • Docs

fix: extended field path with proper index information for validated rule
chore: created unit tests for ValidateRules
note: possible superfluousness of CheckForVerbs
@andreas-kupries andreas-kupries requested a review from a team January 29, 2024 12:09
chore: regenerated main documentation file
pkg/resources/common/validation.go Outdated Show resolved Hide resolved
pkg/resources/common/validation.go Outdated Show resolved Hide resolved
pkg/resources/common/validation_test.go Outdated Show resolved Hide resolved
JonCrowther
JonCrowther previously approved these changes Jan 30, 2024
pmatseykanets
pmatseykanets previously approved these changes Jan 31, 2024
Copy link
Contributor

@pmatseykanets pmatseykanets left a comment

Choose a reason for hiding this comment

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

Q: Do we need/want to make any adjustments to corresponding integration tests?

@andreas-kupries
Copy link
Contributor Author

Q: Do we need/want to make any adjustments to corresponding integration tests?

@pmatseykanets Thank you for pointing me to this.
IMHO yes, and I am willing to do it in this PR, given that the change is not urgent.
IOW I see no need to have a separate PR.
I will move this PR back to In Progress.

@andreas-kupries
Copy link
Contributor Author

Integrations tests extended - role templates, and global roles.

@andreas-kupries andreas-kupries merged commit 9563bda into rancher:release/v0.5 Feb 2, 2024
1 check passed
andreas-kupries added a commit to andreas-kupries/rancher-webhook that referenced this pull request Mar 11, 2024
Proper validation of GlobalRole `rules`,
plus fix (TomL) to make validation not namespaced.
andreas-kupries added a commit that referenced this pull request Apr 3, 2024
…ion-backport

Backport of PRs #328 and #332, plus go module refresh
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.

3 participants