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

feat: introduce group policies #814

Merged
merged 1 commit into from
Jul 16, 2024
Merged

Conversation

flavio
Copy link
Member

@flavio flavio commented Jul 8, 2024

Allow multiple Kubewarden policies to be grouped together using an evaluation expression.

This PR poses the bases required to implement https://github.com/kubewarden/rfc/blob/main/rfc/0020-policy-group.md

Part of kubewarden/kubewarden-controller#798

@flavio flavio requested a review from a team as a code owner July 8, 2024 12:45
@flavio flavio self-assigned this Jul 8, 2024
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
@flavio
Copy link
Member Author

flavio commented Jul 9, 2024

@fabriziosestito thanks for the review, I've addressed all the feedback you gave

@flavio flavio force-pushed the feat-group-policy branch from 71caebf to 9d638c1 Compare July 9, 2024 11:33
Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 76.31579% with 72 lines in your changes missing coverage. Please review.

Project coverage is 58.45%. Comparing base (d401e67) to head (f5e8b1a).

Files Patch % Lines
src/evaluation/evaluation_environment.rs 68.31% 64 Missing ⚠️
src/lib.rs 44.44% 5 Missing ⚠️
src/api/service.rs 94.11% 1 Missing ⚠️
src/config.rs 97.50% 1 Missing ⚠️
src/policy_downloader.rs 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #814      +/-   ##
==========================================
+ Coverage   54.90%   58.45%   +3.54%     
==========================================
  Files          16       17       +1     
  Lines         765      994     +229     
==========================================
+ Hits          420      581     +161     
- Misses        345      413      +68     
Flag Coverage Δ
integration-tests 50.55% <66.99%> (+2.71%) ⬆️
unit-tests 34.60% <44.55%> (+2.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/evaluation.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@fabriziosestito fabriziosestito left a comment

Choose a reason for hiding this comment

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

LGTM, just one typo to fix.

Also, the latest commit is not a conventional commit.

@flavio
Copy link
Member Author

flavio commented Jul 10, 2024

@fabriziosestito I've addressed your comment. As for the commit format, I plan to squash all of them into a single commit. I'm not doing semantic git commits right now

@flavio
Copy link
Member Author

flavio commented Jul 10, 2024

I think the current code is doing pretty good. I've implemented all the missing TODOs except for these ones:

  • When validating the policy group expression, ensure the returned value is a boolean. The check is not working right now, see the commented unit test. This is not a huge deal, since we will do some validation also on the GroupPolicy CRD. There we will use CEL, which allows us to write this kind of check.
  • Validate the policy.yml file: error when we find something that is not covered by our spec

src/config.rs Outdated Show resolved Hide resolved
@flavio
Copy link
Member Author

flavio commented Jul 10, 2024

Another update:

Validate policies configuration file

  • Be strict during deserialization: error when something unknown is found
  • Validate policy names: ensure they do not contain the / symbol

Copy link
Contributor

@fabriziosestito fabriziosestito left a comment

Choose a reason for hiding this comment

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

:shipit:

@flavio
Copy link
Member Author

flavio commented Jul 11, 2024

This is really the last change I'm going to make to this PR. With 31b6539 I've introduced a dedicated Rust type to identify policies. We're no longer using strings.

@flavio flavio force-pushed the feat-group-policy branch from 89891ea to 31b6539 Compare July 11, 2024 09:03
@flavio flavio requested a review from fabriziosestito July 11, 2024 09:04
Copy link
Contributor

@fabriziosestito fabriziosestito left a comment

Choose a reason for hiding this comment

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

LGTM @flavio love the latest commit

@jvanz
Copy link
Member

jvanz commented Jul 11, 2024

:shipit:

Copy link
Member

@viccuad viccuad left a comment

Choose a reason for hiding this comment

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

LGTM!

@flavio flavio force-pushed the feat-group-policy branch 2 times, most recently from 7a13d6d to e3d3568 Compare July 12, 2024 10:18
@flavio
Copy link
Member Author

flavio commented Jul 15, 2024

Last round of cleanups:

  • Rename PolicyId to PolicyID
  • Config: policy group policies are now stored inside of a key named policies instead of members
  • EvaluationEnvironment: introduce builder patter, remove duplication between policies and group policies

src/api/service.rs Show resolved Hide resolved
Copy link
Member

@viccuad viccuad left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@flavio flavio force-pushed the feat-group-policy branch from 94841fe to b2300e6 Compare July 15, 2024 17:01
Allow multiple Kubewarden policies to be grouped together using an
evaluation expression.

This implents the RFC https://github.com/kubewarden/rfc/blob/main/rfc/0020-policy-group.md

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
Co-authored-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
@flavio flavio force-pushed the feat-group-policy branch from b2300e6 to f5e8b1a Compare July 15, 2024 17:02
@flavio flavio merged commit 1677586 into kubewarden:main Jul 16, 2024
11 checks passed
@flavio flavio deleted the feat-group-policy branch July 16, 2024 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants