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

chore: adding generateVAP field, removing annotations for vap #3398

Merged
merged 29 commits into from
Jul 23, 2024

Conversation

JaydipGabani
Copy link
Contributor

What this PR does / why we need it:
Removing use-vap annotation in favor of using generateVAP field on template to generate VAP and VAPB.

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 #

Special notes for your reviewer:

@JaydipGabani JaydipGabani requested a review from a team as a code owner May 23, 2024 18:04
@JaydipGabani JaydipGabani reopened this May 23, 2024
@JaydipGabani JaydipGabani marked this pull request as draft May 23, 2024 18:36
@JaydipGabani JaydipGabani force-pushed the vap-field branch 2 times, most recently from 019c8a7 to 08a60a1 Compare July 1, 2024 22:48
@JaydipGabani JaydipGabani marked this pull request as ready for review July 1, 2024 22:48
@ritazh ritazh added this to the v3.17.0 milestone Jul 3, 2024
@JaydipGabani JaydipGabani requested a review from ritazh July 8, 2024 18:48
Signed-off-by: Jaydip Gabani <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 12 lines in your changes missing coverage. Please review.

Project coverage is 48.02%. Comparing base (3350319) to head (e19c2de).
Report is 168 commits behind head on master.

Files with missing lines Patch % Lines
pkg/controller/constraint/constraint_controller.go 46.66% 8 Missing ⚠️
...onstrainttemplate/constrainttemplate_controller.go 66.66% 2 Missing and 2 partials ⚠️

❗ There is a different number of reports uploaded between BASE (3350319) and HEAD (e19c2de). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (3350319) HEAD (e19c2de)
unittests 2 1
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3398      +/-   ##
==========================================
- Coverage   54.49%   48.02%   -6.48%     
==========================================
  Files         134      219      +85     
  Lines       12329    14844    +2515     
==========================================
+ Hits         6719     7129     +410     
- Misses       5116     6907    +1791     
- Partials      494      808     +314     
Flag Coverage Δ
unittests 48.02% <55.55%> (-6.48%) ⬇️

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.

@JaydipGabani JaydipGabani requested a review from maxsmythe July 8, 2024 19:21
@JaydipGabani JaydipGabani requested a review from sozercan July 10, 2024 21:58
Copy link
Member

@sozercan sozercan left a comment

Choose a reason for hiding this comment

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

a few minor comments, otherwise LGTM

@JaydipGabani JaydipGabani requested a review from ritazh July 11, 2024 16:38
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

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.

Nits other than the question about checking the template before generating a binding for a constraint.

return reconcile.Result{}, err
}

generateVAPB := *DefaultGenerateVAPB && HasVAPCel(ct)
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we were going to get rid of the condition of only generating the binding if the constraint template had VAP CEL?

Link to relevant chat thread: https://openpolicyagent.slack.com/archives/GQK16NZEJ/p1719537610076419?thread_ts=1719532061.611639&cid=GQK16NZEJ

The thread mentions potentially adding a warning if we are creating a binding for a template that does not have a VAP implementation.

IIRC we are able to do this b/c users should be able to use scopedEnforcementActions if they need to modify behavior more granularly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This condition was added so that we do not generate VAPB for constraints that have templates only with Rego code. Which makes sense, these will be lingering VAPB unless ommited through scopedEA. We can still add the warning saying this tamplate does not have VAPB created because of missing VAP implementation after we determine the shcema of the warning.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am skeptical. I suspect we are trying to be too clever here and that we will shoot ourselves in the foot. Particularly if users want to leverage fail-closed. I suppose the behavior could be customized further down the line with flags.

What happens when users specify "only use VAP" using scopedEA for a rego-only template? We continue to fail to create the binding and add a warning?

Looks like we are already triggering re-reconciles of all constraints when templates get updated, which is good:

func (r *ReconcileConstraintTemplate) triggerConstraintEvents(ctx context.Context, ct *v1beta1.ConstraintTemplate, status *statusv1beta1.ConstraintTemplatePodStatus) error {
gvk := makeGvk(ct.Spec.CRD.Spec.Names.Kind)
logger.Info("list gvk objects", "gvk", gvk)
cstrObjs, err := r.listObjects(ctx, gvk)
if err != nil {
logger.Error(err, "get all constraints listObjects")
updateErr := &v1beta1.CreateCRDError{Code: ErrUpdateCode, Message: err.Error()}
status.Status.Errors = append(status.Status.Errors, updateErr)
err := r.reportErrorOnCTStatus(ctx, ErrUpdateCode, "Could not list all constraint objects", status, err)
return err
}
logger.Info("list gvk objects", "cstrObjs", cstrObjs)
for _, cstr := range cstrObjs {
c := cstr
logger.Info("triggering cstrEvent")
r.cstrEvents <- event.GenericEvent{Object: &c}
}
return nil

If none of these concerns are blocking, SGTM

Copy link
Contributor Author

@JaydipGabani JaydipGabani Jul 18, 2024

Choose a reason for hiding this comment

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

Particularly if users want to leverage fail-closed.

@maxsmythe what do you mean by this? can you elaborate?

What happens when users specify "only use VAP" using scopedEA for a rego-only template? We continue to fail to create the binding and add a warning?

I think yes 🤔. There wouldn't be any enforcement through in-tree VAP anyways in this situation given VAP won't be there even if we end up creating VAPB otherwise. We should follow up with VAP warning and error message schema for constraint status after this PR. In this situation GK would enforce rego with constraint.

I really do not have strong objection against creating VAPB for all constraints though.

@ritazh @sozercan do you have any thoughts on this?

Copy link
Member

@ritazh ritazh Jul 18, 2024

Choose a reason for hiding this comment

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

Particularly if users want to leverage fail-closed.

Are you referring to when user wants to use vap and vapb to enforce but the CT only has rego, GK should fail instead of warn and let GK webhook handle it? If so, then I agree if user specified scopedEA in the constraint to use VAP but CT doesnt have CEL, then we should report error in the constraint status. However, if there is no constraint level scopedEA provided, we should not generate vapb for all constraints that do not have CEL in the CT.

Creating VAPB when there is no corresponding VAP due to lack of CEL seems unnecessary. not sure what value there is by having a dangling VAPB without a corresponding VAP.

return reconcile.Result{Requeue: true}, nil
}
}
if constraint.HasVAPCel(ct) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this function should probably live next to the VAP driver once we move it from frameworks into G8r.

@JaydipGabani JaydipGabani requested a review from maxsmythe July 16, 2024 01:02
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

- `VAP_DEFAULT`: generate unless label `gatekeeper.sh/use-vap: no` is added to policy explicitly
Gatekeeper is configured to generate K8s Validating Admission Policy (VAP) resources for all constraint templates globally if `--default-create-vap-for-templates=true` flag is set. This flag defaults to `false` at this time to not generate VAP resources by default.

If you would like to override this flag's behavior for any constraint templates, you can set generateVAP explicitly on per constraint template level.
Copy link
Contributor

Choose a reason for hiding this comment

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

Qq, is there a way to override on the constraint level still or only constraint template @JaydipGabani

Copy link
Contributor Author

Choose a reason for hiding this comment

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

--default-create-vapb-for-constraints if the flag for enabling generation of VAPB for constraint. However, to override that flag we are introducing VAP as an enforcement Point and a field in constraint called scopedEnforcementActions to override --default-create-vapb-for-constraints. Here is complete opt-in/opt-out of VAP and VAPB generation behavior - VAP-user-flow. Let me know if you have any more questions.

@JaydipGabani
Copy link
Contributor Author

JaydipGabani commented Jul 22, 2024

Looking into CI failures.

@JaydipGabani JaydipGabani merged commit 3fd0bb4 into open-policy-agent:master Jul 23, 2024
22 checks passed
@JaydipGabani JaydipGabani deleted the vap-field branch July 23, 2024 23:51
Ankurk99 pushed a commit to Ankurk99/gatekeeper that referenced this pull request Aug 1, 2024
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.

6 participants