Skip to content

Disallow repeaded CORS filters by CEL - #4639

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
DamianSawicki:forbid-multiple-CORS-filters
Mar 6, 2026
Merged

k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
DamianSawicki:forbid-multiple-CORS-filters

Conversation

@DamianSawicki

@DamianSawicki DamianSawicki commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

The CEL validation rule present for other filter types has been missing for CORS.

Which issue(s) this PR fixes:

Does this PR introduce a user-facing change?:

It is disallowed to have repeated `filters` of `type` `CORS`.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. labels Mar 5, 2026
@k8s-ci-robot
k8s-ci-robot requested a review from rikatz March 5, 2026 11:53
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 5, 2026
@k8s-ci-robot
k8s-ci-robot requested a review from robscott March 5, 2026 11:53
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 5, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Hi @DamianSawicki. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@DamianSawicki
DamianSawicki force-pushed the forbid-multiple-CORS-filters branch from a03f365 to f9e7244 Compare March 5, 2026 11:54
@DamianSawicki
DamianSawicki marked this pull request as ready for review March 5, 2026 11:54
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 5, 2026
@DamianSawicki

Copy link
Copy Markdown
Contributor Author

/cc @snorwin

@k8s-ci-robot
k8s-ci-robot requested a review from snorwin March 5, 2026 11:55
@rikatz

rikatz commented Mar 5, 2026

Copy link
Copy Markdown
Member

/ok-to-test
/cherry-pick release-1.5

good catch!

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@rikatz: once the present PR merges, I will cherry-pick it on top of release-1.5 in a new PR and assign it to you.

Details

In response to this:

/ok-to-test
/cherry-pick release-1.5

good catch!

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.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 5, 2026
Comment thread apis/v1/httproute_types.go Outdated
// +kubebuilder:validation:XValidation:message="ResponseHeaderModifier filter cannot be repeated",rule="self.filter(f, f.type == 'ResponseHeaderModifier').size() <= 1"
// +kubebuilder:validation:XValidation:message="RequestRedirect filter cannot be repeated",rule="self.filter(f, f.type == 'RequestRedirect').size() <= 1"
// +kubebuilder:validation:XValidation:message="URLRewrite filter cannot be repeated",rule="self.filter(f, f.type == 'URLRewrite').size() <= 1"
// +kubebuilder:validation:XValidation:message="CORS filter cannot be repeated",rule="self.filter(f, f.type == 'CORS').size() <= 1"

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.

one thing: CEL validation on CRD is prone to alphabetical order, so you should move this above on line 253 before RequestHeaderModifier

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interesting! Haven't checked the entire file, but the tests containing my changes were passing in my IDE. Will fix!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Out of curiosity, why the following order is correct? Is the alphabetical order based on rule rather than message?

	// +kubebuilder:validation:XValidation:message="May specify either httpRouteFilterRequestRedirect or httpRouteFilterRequestRewrite, but not both",rule="!(self.exists(f, f.type == 'RequestRedirect') && self.exists(f, f.type == 'URLRewrite'))"
	// +kubebuilder:validation:XValidation:message="CORS filter cannot be repeated",rule="self.filter(f, f.type == 'CORS').size() <= 1"
	// +kubebuilder:validation:XValidation:message="RequestHeaderModifier filter cannot be repeated",rule="self.filter(f, f.type == 'RequestHeaderModifier').size() <= 1"

good catch!

It's Norwin's :)

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.

that's a good question, no idea

@DamianSawicki
DamianSawicki force-pushed the forbid-multiple-CORS-filters branch from f9e7244 to c7cc81a Compare March 5, 2026 13:55
This is in line with how we disallow other repeated filters.

Signed-off-by: Damian Sawicki <dsawicki@google.com>
@DamianSawicki
DamianSawicki force-pushed the forbid-multiple-CORS-filters branch from c7cc81a to 30cec8f Compare March 5, 2026 16:37
@rikatz

rikatz commented Mar 5, 2026

Copy link
Copy Markdown
Member

/retest

@robscott

robscott commented Mar 6, 2026

Copy link
Copy Markdown
Member

@DamianSawicki thanks for fixing this! Can you add a release note to the PR since it is technically an API change?

/approve

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DamianSawicki, robscott

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 6, 2026
@youngnick

Copy link
Copy Markdown
Contributor

/lgtm

Thanks for this @DamianSawicki!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 6, 2026
@k8s-ci-robot
k8s-ci-robot merged commit b5a9312 into kubernetes-sigs:main Mar 6, 2026
8 checks passed
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@rikatz: new pull request created: #4645

Details

In response to this:

/ok-to-test
/cherry-pick release-1.5

good catch!

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.

@robscott robscott added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Mar 6, 2026
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. release-note-none Denotes a PR that doesn't merit a release note. labels Mar 6, 2026
danehans pushed a commit to danehans/gateway-api that referenced this pull request Mar 10, 2026
This is in line with how we disallow other repeated filters.

Signed-off-by: Damian Sawicki <dsawicki@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants