E53B httproute: introduce RequestRedirect filter by hbagdi · Pull Request #683 · kubernetes-sigs/gateway-api · GitHub
[go: up one dir, main page]

Skip to content

Conversation

hbagdi
Copy link
Contributor
@hbagdi hbagdi commented May 25, 2021
edited
Loading

What type of PR is this?

/kind feature
What this PR does / why we need it:

Introduces a new filter for configurable redirects.

Which issue(s) this PR fixes:

Fixes #200 (funny :)

Does this PR introduce a user-facing change?:

HTTP redirects are now supported with the addition of new `RequestRedirect` filter.

This draft PR is to get the conversation started on what we would like to see here.
I opted to do a filter to not further add to the surface of the API and a filter seemed like a good place to add this functionality.

One use case that this proposal doesn't solve:

  • Gateway owner wants to perform HTTP->HTTPS on all reque FBC8 sts. Could this be a property of GatewayClass?

Would love to hear more thoughts here.
/cc @robscott @bowei @jpeach @danehans
/hold

@k8s-ci-robot k8s-ci-robot requested review from bowei, danehans and jpeach May 25, 2021 18:56
@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot requested a review from robscott May 25, 2021 18:56
@k8s-ci-robot k8s-ci-robot added 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/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 25, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hbagdi

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 25, 2021
// header in the response.
AutoHTTPS bool `json:"auto_https,omitempty"`
// TODO if defaulting is possible here (not sure about defaulting in filter), default this?
// What status codes should be allowed? 301,302,307,308?
Copy link
Contributor

Choose a reason for hiding this comment

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

If we have bounded ones one option we should consider is status code number vs an enum? like MOVED_PERMANENTLY, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern with enum is it is one more piece of configuration that the user needs to learn and remember.
We could prevent errors via validation here if that is the concern.

Copy link
Member

Choose a reason for hiding this comment

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

Agree that I think numbers will likely be easier to understand here.


// HTTPRequestRedirect defines configuration for the RequestRedirect filter.
type HTTPRequestRedirect struct {
// AutoHTTPS if set to true redirects any incoming HTTP requests to HTTPS.
Copy link
Contributor

Choose a reason for hiding this comment

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

Gateway owner wants to perform HTTP->HTTPS on all requests. Could this be a property of GatewayClass?

Would it be possible to define a route for * and set auto_https?

Copy link
Contributor

Choose a reason for hiding this comment

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

Even better if our use case also supports ACME where we probably want to redirect eveything but /.wellknown/acme

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even better if our use case also supports ACME where we probably want to redirect eveything but /.wellknown/acme

Solid point!

Would it be possible to define a route for * and set auto_https?

Gateway admin can but it has limitations. The most specific route matches a request and if that doesn't have the filter defined, then HTTP requests will be accepted.

Copy link
Member

Choose a reason for hiding this comment

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

But in that case you could have a listener on 80 that only selected the auto redirect route and a listener on 443 that selected all the other routes? This seems like it could become a common pattern.

RedirectStatusCode *int `json:"redirect_status_code,omitempty"`
// Location denotes the value of location header.
// +optional
Location *string `json:"location,omitempty"`
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 a bit concerned with having the raw header here, rather than something a bit more abstract, like

    redirect:
      uri: /v1/bookRatings
      authority: newratings.default.svc.cluster.local

The reason is that I can no longer make it generic - I cannot just say redirect /v1 to /v2, I need to now also include http vs https, so now the route is aware of the TLS layer which is leaking from Gateway

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it makes sense to have arbitrary headers here (and do proxies support that)? If so, you can use the same name list structure as the other parts of the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to now also include http vs https

IME this is not an issue and users want to be as explicit as possible. But you do make a good point that the user now has to be aware of authority as well, which could be abstracted away in Gateway for some use cases. I'll update.

@hbagdi hbagdi force-pushed the feat/configurable-redirects branch from dc784d0 to 3619b0a Compare June 22, 2021 17:39
@hbagdi hbagdi marked this pull request as ready for review June 22, 2021 17:40
@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 Jun 22, 2021
@hbagdi
Copy link
Contributor Author
hbagdi commented Jun 22, 2021

Outstanding questions:

  1. Should we have the StatusCode field? If yes, what should be the conformance level for this? The support seems to be available for in-cluster implementations, do could providers support it?
  2. Should path-munging be a feature of this filter? Paths are harder to generalize. Some users want to redirect with path substitution, meaning, /v1/foo/bar should be redirected to /v2/foo/bar, while in some cases, it is a more targeted redirect where /foo/bar has to be redirected to /foobar. The substitution part can get complex with a bunch of corner cases. Should we keep that out of scope for now and come back to it later?

@hbagdi
Copy link
Contributor Author
hbagdi commented Jun 22, 2021

@robscott
Copy link
Member
  1. Should we have the StatusCode field? If yes, what should be the conformance level for this? The support seems to be available for in-cluster implementations, do could providers support it?

It looks like 301 and 302 are fairly broadly supported, but it trails off quickly after that. (See GCP, AWS, and Azure docs). Maybe 301 and 302 values would be considered core and the rest would be extended?

  1. Should path-munging be a feature of this filter? Paths are harder to generalize. Some users want to redirect with path substitution, meaning, /v1/foo/bar should be redirected to /v2/foo/bar, while in some cases, it is a more targeted redirect where /foo/bar has to be redirected to /foobar. The substitution part can get complex with a bunch of corner cases. Should we keep that out of scope for now and come back to it later?

I think we should consider this out of scope for now.

@hbagdi
Copy link
Contributor Author
hbagdi commented Jun 23, 2021

Maybe 301 and 302 values would be considered core and the rest would be extended?

Having a conformance at that level would be very confusing for our users. How about we start with only 301 and 302 and have that included as core conformance?

Also, I'm assuming this filter would be under core conformance,. Thoughts?

@robscott
Copy link
Member

@hbagdi Agree with both of those - makes sense to start with just 301 and 302 and consider the filter a core feature.

@hbagdi hbagdi force-pushed the feat/configurable-redirects branch from 3619b0a to 309e53c Compare June 23, 2021 18:13
@hbagdi
Copy link
Contributor Author
hbagdi commented Jun 23, 2021

Updated the PR to take into account (I think) all the discussions we have had so far.

@robscott
Copy link
Member

Thanks for the work on this @hbagdi! This mostly LGTM, just a couple requests:

  1. Can you add a release note to the PR?
  2. Can you add an example with this PR? (Maybe http -> https redirect)

< 5B9E a title="httproute: introduce RequestRedirect filter" data-pjax="true" class="Link--secondary markdown-title" href="/kubernetes-sigs/gateway-api/pull/683/commits/84f15d0a046e3dd2b62658f50d3c8c71a49e2c6f">httproute: introduce RequestRedirect filter
@hbagdi hbagdi force-pushed the feat/configurable-redirects branch from 309e53c to 84f15d0 Compare June 29, 2021 16:09
@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 29, 2021
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 29, 2021
@hbagdi
Copy link
Contributor Author
hbagdi commented Jun 29, 2021

@robscott @jpeach Addressed all comments, PTAL.

hbagdi added a commit to hbagdi/service-apis that referenced this pull request Jun 29, 2021
This was found while working on kubernetes-sigs#683.
This was assumed to be fixed with kubernetes-sigs#670 but as it turns out we have two
kubectl apply in our shell script.
bowei pushed a commit to bowei/service-apis that referenced this pull request Jul 1, 2021
This was found while working on kubernetes-sigs#683.
This was assumed to be fixed with kubernetes-sigs#670 but as it turns out we have two
kubectl apply in our shell script.
@jpeach
Copy link
Contributor
jpeach commented Jul 1, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 1, 2021
@hbagdi
Copy link
Contributor Author
hbagdi commented Jul 2, 2021

I had put in a hold when this was a draft. Removing it now (which will merge this in).
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 2, 2021
@k8s-ci-robot k8s-ci-robot merged commit e4536a0 into kubernetes-sigs:master Jul 2, 2021
// +optional
// +kubebuilder:default=302
// +kubebuilder:validation=301;302
StatusCode *int `json:"redirect_status_code,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to bring this up after the merge, but should the json tag be lower camel-case?

Suggested change
StatusCode *int `json:"redirect_status_code,omitempty"`
StatusCode *int `json:"statusCode,omitempty"`

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/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for configurable HTTP redirects
6 participants
0