Skip to content

Replace webhook validations with CEL validation - #475

Closed
erikgb wants to merge 1 commit into
cert-manager:mainfrom
erikgb:more-api-validation
Closed

erikgb wants to merge 1 commit into
cert-manager:mainfrom
erikgb:more-api-validation

Conversation

@erikgb

@erikgb erikgb commented Nov 16, 2024 •

Copy link
Copy Markdown
Member

I want to see if it's possible to remove the trust-manager validating webhook, as it will eliminate the requirement to pre-install cert-manager. But it doesn't seem possible, at least not with the current Bundle API, to fully replace the webhook validations with CEL api-server validation. We might get a bit further after redesigning the target structure ref. #242, but the label selectors require a webhook to be validated AFAIK.

I personally think the CEL validations are more compact and fairly easy to read, at least the common union validations. The additional formats validation CEL expression is probably a bit over the line, so I am open to reverting it. But I wanted to see how far I could get with CEL, and I even got assistance from Jordan Liggit himself! 🦄

Jordan suggested optional fields to reduce the complexity, but I decided to avoid them for now - since that will require Kubernetes version >= 1.29 to work. We can simplify later on.

It would be super nice to replace our validating webhook with CRD CEL validations completely, but that seems currently impossible. The remaining validations done by the validating webhook include:

  • Label selector validations. This might be added to declarative validations in the future, but sadly not available now, but added to the CEL wishlist.
  • Source vs target key validations. Probably possible to do with CEL, but I don't think the additional complexity is worth it if we cannot fully remove the validating webhook.

Please let me know what you think!

/cc @juliocamarero @SgtCoDFish @inteon

@cert-manager-prow cert-manager-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 16, 2024
@erikgb
erikgb force-pushed the more-api-validation branch 2 times, most recently from 3749249 to c7c15cb Compare November 16, 2024 10:25
@cert-manager-prow cert-manager-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 16, 2024
@erikgb
erikgb force-pushed the more-api-validation branch 5 times, most recently from 78f63d5 to 3741f38 Compare November 16, 2024 13:33
@cert-manager-prow cert-manager-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 16, 2024
@erikgb
erikgb force-pushed the more-api-validation branch 3 times, most recently from d9853ff to 17a72ed Compare November 17, 2024 09:39
@cert-manager-prow cert-manager-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2024
@erikgb
erikgb force-pushed the more-api-validation branch from 17a72ed to ec915d4 Compare November 22, 2024 21:08
@cert-manager-prow cert-manager-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2024
@erikgb
erikgb force-pushed the more-api-validation branch from ec915d4 to 2224375 Compare November 22, 2024 21:12
@erikgb erikgb changed the title WIP: Make more use of api-server validation Replace webhook validations with CEL validation Nov 22, 2024
@cert-manager-prow cert-manager-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 22, 2024
@erikgb
erikgb force-pushed the more-api-validation branch from 2224375 to 60e3819 Compare November 22, 2024 21:18

@juliocamarero juliocamarero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. I wasn't aware of the CEL validations, but they seem very expressive and easy to use, I like this approach 👍

@SgtCoDFish SgtCoDFish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seeing the amount of code this removes is super cool 🚀 I've got a few questions to help me understand better!

Comment thread docs/api/api.md Resolved
// data to.
// +kubebuilder:validation:XValidation:rule="[has(self.configMap), has(self.secret)].exists(x,x)", message="must define at least one target configMap/secret"
// +kubebuilder:validation:XValidation:rule="!has(self.additionalFormats) || ![has(self.additionalFormats.jks), has(self.additionalFormats.pkcs12)].all(x,x) || self.additionalFormats.jks.key != self.additionalFormats.pkcs12.key", message="additional format keys must be unique"
// +kubebuilder:validation:XValidation:rule="!has(self.additionalFormats) || !((has(self.configMap) ? [self.configMap.key] : []) + (has(self.secret) ? [self.secret.key] : [])).exists(k,(has(self.additionalFormats.jks) && self.additionalFormats.jks.key == k) || (has(self.additionalFormats.pkcs12) && self.additionalFormats.pkcs12.key == k))", message="additional format keys must be different from configMap/secret keys"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

question: Is a +kubebuilder comment the only way of specifying these validation rules? (I'm unfamiliar generally with this CEL validation stuff)

This CEL code is super important to our UX but it's really difficult to read, understand and test it when it's embedded in a comment like this - seems like a sharp edge.

This isn't a blocker or anything, but it seems a shame if this is the only way today!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, it should be possible to hack the expression directly into the CRDs, but that is not something I would do. 😆 The expressions are mainly complex because the API is suboptimal. After #486, I think the expressions could become really simple.

Thanks for reviewing @SgtCoDFish (and @juliocamarero)! But I think the best option here is to put this PR back into draft-mode and wait for a conclusion on #486.

@erikgb
erikgb marked this pull request as draft November 25, 2024 16:54
@erikgb
erikgb force-pushed the more-api-validation branch from 2af5468 to 77d7646 Compare February 27, 2025 18:07
@erikgb

erikgb commented Feb 27, 2025

Copy link
Copy Markdown
Member Author

/remove-lifecycle stale

@cert-manager-prow cert-manager-prow Bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 27, 2025
@cert-manager-prow cert-manager-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 11, 2025
@erikgb
erikgb force-pushed the more-api-validation branch from 77d7646 to c1f4cac Compare March 11, 2025 20:07
@cert-manager-prow cert-manager-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 11, 2025
@erikgb

erikgb commented Mar 11, 2025

Copy link
Copy Markdown
Member Author

/test all

@erikgb
erikgb force-pushed the more-api-validation branch from c1f4cac to 9a61a64 Compare March 11, 2025 21:41
@cert-manager-prow cert-manager-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 11, 2025
@erikgb erikgb changed the title WIP: Replace webhook validations with CEL validation Replace webhook validations with CEL validation Mar 11, 2025
@erikgb
erikgb marked this pull request as ready for review March 11, 2025 21:50
@cert-manager-prow cert-manager-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 11, 2025
@erikgb
erikgb requested a review from SgtCoDFish March 11, 2025 21:50
@erikgb
erikgb force-pushed the more-api-validation branch from 9a61a64 to 4723461 Compare March 11, 2025 21:53
@erikgb

erikgb commented Mar 11, 2025

Copy link
Copy Markdown
Member Author

/test pull-trust-manager-test

@cert-manager-prow cert-manager-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 23, 2025
@erikgb
erikgb force-pushed the more-api-validation branch from 4723461 to dd692e0 Compare April 23, 2025 22:03
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: juliocamarero
Once this PR has been reviewed and has the lgtm label, please assign joshvanl for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 23, 2025
@cert-manager-prow cert-manager-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 21, 2025
@cert-manager-prow

Copy link
Copy Markdown
Contributor

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@erikgb

erikgb commented Jul 23, 2025

Copy link
Copy Markdown
Member Author

CEL validations are great, but it seems like we should introduce them when the API is improved. Closing in favor of #664.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants