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: adding flag to validate rego for templates #3026

Merged
merged 7 commits into from
Oct 4, 2023

Conversation

JaydipGabani
Copy link
Contributor

What this PR does / why we need it: Introducing flag to validate rego in constraint template.

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes #3008

Special notes for your reviewer:
I am not erroring out if experimental-enable-k8s-native-validation and validate-template-rego both are enabled at the same time as we discussed. Instead, the behavior is if validate-template-rego is enabled then any templates with cel will be rejected with the error "invalid rego", but the templates that exist in the cluster already with cel will still work (feels like less breaking change with this approach). Additionally, updates on cel templates will throw an "invalid rego" error as well. I do not have any issue with erroring out, so let me know if this is not the desired approach and I will make changes accordingly to error out if both are enabled at the same time.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Sep 27, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (5c99159) 52.49% compared to head (c95da90) 52.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3026      +/-   ##
==========================================
- Coverage   52.49%   52.41%   -0.08%     
==========================================
  Files         134      134              
  Lines       11937    11948      +11     
==========================================
- Hits         6266     6263       -3     
- Misses       5179     5192      +13     
- Partials      492      493       +1     
Flag Coverage Δ
unittests 52.41% <0.00%> (-0.08%) ⬇️

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

Files Coverage Δ
pkg/webhook/policy.go 33.46% <0.00%> (-0.77%) ⬇️

... and 3 files with indirect coverage changes

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

Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

Should we also update the instructions in the VAP demo readme?

pkg/webhook/policy.go Outdated Show resolved Hide resolved
@ritazh
Copy link
Member

ritazh commented Sep 28, 2023

I am not erroring out if experimental-enable-k8s-native-validation and validate-template-rego both are enabled at the same time as we discussed.

IMO it’s better to fail early when both flags are used especially because the new flag is enabled by default so the GK/cluster operator can make the decision whether or not they need this new flag enabled if they have enabled the vap flag in their environment already. Getting the error when a vap policy is used seems too late and requires extra work for the policy owner to work with the GK/cluster operator to update the flags.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for doing this!

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
pkg/webhook/policy.go Outdated Show resolved Hide resolved
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

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

LGTM

@sozercan sozercan merged commit 976ae01 into open-policy-agent:master Oct 4, 2023
16 checks passed
JaydipGabani added a commit to JaydipGabani/gatekeeper that referenced this pull request Oct 4, 2023
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Co-authored-by: Sertaç Özercan <852750+sozercan@users.noreply.github.com>
(cherry picked from commit 976ae01)
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
JaydipGabani added a commit that referenced this pull request Oct 4, 2023
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Co-authored-by: Sertaç Özercan <852750+sozercan@users.noreply.github.com>
Mattes83 pushed a commit to Mattes83/gatekeeper that referenced this pull request Oct 25, 2023
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Co-authored-by: Sertaç Özercan <852750+sozercan@users.noreply.github.com>
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.

Admission validation of constraint template rego
5 participants