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: add webhook validation of redirect usage #1788

Closed
wants to merge 1 commit into from

Conversation

Xunzhuo
Copy link
Member

@Xunzhuo Xunzhuo commented Mar 8, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

Webhook validation should prevent a HTTPRoute that specifies a redirect filter from specifying a backendRef

Which issue(s) this PR fixes:

Fixes: #1779

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 8, 2023
@k8s-ci-robot k8s-ci-robot requested a review from bowei March 8, 2023 08:19
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 8, 2023
@Xunzhuo
Copy link
Member Author

Xunzhuo commented Mar 8, 2023

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 8, 2023
Signed-off-by: Xunzhuo <mixdeers@gmail.com>
@shaneutt shaneutt added this to the v0.6.2 milestone Mar 8, 2023
@shaneutt shaneutt self-requested a review March 8, 2023 19:11
@robscott
Copy link
Member

robscott commented Mar 9, 2023

Hey @Xunzhuo, thanks for working on this! We really need more information in the PR description to help reviewers understand what the goals are. For example, #1753 has good detail for each section.

As far as the content of the PR, I think we need to have some broader discussion about this before merging. This PR would effectively prevent a case where redirect loop as proposed by @rainest in #1185 is possible. As I see it, we essentially have two options:

  1. Say that redirect loop protection is likely not viable and instead require that both a redirect and backendRef cannot be specified in the same route rule (that's this PR).
  2. Update the spec to define how redirect loop protection would work, enabling a single route rule to express something like "redirect to HTTPS, if already there, forward to backend foo".

My gut tells me that 2 would be pretty challenging and that 1 is the most viable solution at this point, but we need to be very clear that this is a change to the API Spec and include a release note + API Spec update if that's the direction we go.

Since this would be a significant change, I want to hold off until we can discuss this at a community meeting + get some feedback on the high level direction of this PR first.

/hold
/cc @youngnick @rainest @sunjayBhatia @howardjohn

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 9, 2023
@k8s-ci-robot
Copy link
Contributor

@robscott: GitHub didn't allow me to request PR reviews from the following users: rainest.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Hey @Xunzhuo, thanks for working on this! We really need more information in the PR description to help reviewers understand what the goals are. For example, #1753 has good detail for each section.

As far as the content of the PR, I think we need to have some broader discussion about this before merging. This PR would effectively prevent a case where redirect loop as proposed by @rainest in #1185 is possible. As I see it, we essentially have two options:

  1. Say that redirect loop protection is likely not viable and instead require that both a redirect and backendRef cannot be specified in the same route rule (that's this PR).
  2. Update the spec to define how redirect loop protection would work, enabling a single route rule to express something like "redirect to HTTPS, if already there, forward to backend foo".

My gut tells me that 2 would be pretty challenging and that 1 is the most viable solution at this point, but we need to be very clear that this is a change to the API Spec and include a release note + API Spec update if that's the direction we go.

Since this would be a significant change, I want to hold off until we can discuss this at a community meeting + get some feedback on the high level direction of this PR first.

/hold
/cc @youngnick @rainest @sunjayBhatia @howardjohn

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/test-infra repository.

@Xunzhuo
Copy link
Member Author

Xunzhuo commented Mar 9, 2023

Yes @robscott, I am also a bit concerned about this change, since this is a user-facing change. We definitely need more discussion before pushing this forward.

Take this as a draft PR, changes can make after the final approach is out.

@shaneutt shaneutt marked this pull request as draft March 10, 2023 15:23
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 10, 2023
@shaneutt shaneutt modified the milestones: v0.6.2, v0.7.0 Mar 14, 2023
Copy link
Member

@sunjayBhatia sunjayBhatia left a comment

Choose a reason for hiding this comment

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

I may have missed some discussion here from a community meeting, but in Contour we currently ignore backendrefs if you've set a redirect filter so option 1 Rob describes seems fine

we could also specify that infinite redirect protection is recommended but implementation-specific support (or extended if we can write up a nice conformance test)

Copy link
Member

@robscott robscott 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 the work on this @Xunzhuo!

Comment on lines +820 to +827
backendRefs: []gatewayv1a2.HTTPBackendRef{{
BackendRef: gatewayv1a2.BackendRef{
BackendObjectReference: gatewayv1a2.BackendObjectReference{
Name: gatewayv1a2.ObjectName("test"),
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
},
},
}},
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this is repeated a lot, can you move the standard set of backendRefs to a var so there's not quite so much repetition here?

Copy link
Member

Choose a reason for hiding this comment

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

Actually it looks like this isn't modified at all for any of the test cases, maybe just add this to the route populated in t.Run below?

for bi, backendRef := range rule.BackendRefs {
for fi, filter := range backendRef.Filters {
if filter.RequestRedirect != nil {
errs = append(errs, field.Invalid(path.Index(ri).Child("backendRefs").Index(bi).Child("filters").Index(fi), filter.RequestRedirect, "cannot specify backendRef when using redirect filter"))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
errs = append(errs, field.Invalid(path.Index(ri).Child("backendRefs").Index(bi).Child("filters").Index(fi), filter.RequestRedirect, "cannot specify backendRef when using redirect filter"))
errs = append(errs, field.Invalid(path.Index(ri).Child("backendRefs").Index(bi).Child("filters").Index(fi), filter.RequestRedirect, "cannot specify RequestRedirect filter within a backendRef"))

for fi, filter := range rule.Filters {
if filter.RequestRedirect != nil {
if len(rule.BackendRefs) != 0 {
errs = append(errs, field.Invalid(path.Index(ri).Child("filters").Index(fi), filter.RequestRedirect, "cannot specify backendRefs when using redirect filter"))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
errs = append(errs, field.Invalid(path.Index(ri).Child("filters").Index(fi), filter.RequestRedirect, "cannot specify backendRefs when using redirect filter"))
errs = append(errs, field.Invalid(path.Index(ri).Child("filters").Index(fi), filter.RequestRedirect, "cannot specify backendRefs when using RequestRedirect filter"))


return true
return *matches[0].Path.Type == gatewayv1b1.PathMatchPathPrefix
Copy link
Member

Choose a reason for hiding this comment

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

This feels not very safe and also not relevant to the rest of the PR, maybe revert this change?

Comment on lines +1003 to +1008
BackendRef: gatewayv1b1.BackendRef{
BackendObjectReference: gatewayv1b1.BackendObjectReference{
Name: gatewayv1b1.ObjectName("test"),
Port: ptrTo(gatewayv1b1.PortNumber(8080)),
},
},
Copy link
Member

Choose a reason for hiding this comment

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

This also looks like it's repeated a lot, can we use a var for this?

@shaneutt shaneutt modified the milestones: v0.7.0, v0.8.0 Apr 6, 2023
@robscott
Copy link
Member

Hey @Xunzhuo are you still interested in working on this? If so, please reopen the PR. Closing for now because it seems to have gone stale.

@robscott robscott closed this Jun 26, 2023
@robscott robscott removed this from the v0.8.0 milestone Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

HTTP Redirect Example is Invalid
5 participants