-
Notifications
You must be signed in to change notification settings - Fork 686
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
Gateway API: support HTTPURLRewriteFilter (extended/experimental) #4300
Comments
Thanks for filing this. If I wanted to have the ability to do Path Rewriting (or mainly, the ability to strip the matched prefix match before sending to the downstream), would you recommend trying out the HTTPProxy CRD type you have? That may be a decent middleground for me now, even though I really like the separation provided by the new gateways spec between Gateway and Routes. |
Yes, HTTPProxy is definitely able to do path rewrites. Note that you can approximate the Gateway/Route separation by using a root HTTPProxy that simply lists the FQDN and then includes child HTTPProxies (which can't have an FQDN set). See https://projectcontour.io/docs/v1.19.1/config/inclusion-delegation/ for more info there. The Gateway/Route split is newer and better designed (we took what we learned from HTTPProxy and pushed it upstream), but HTTPProxy will get you most of the way there until we can catch up. |
Is there a way to make the root HTTPProxy automatically pick up child HTTPProxies without modifying the root HTTPProxy with an include? |
Not out of the box, no, you'd need to explicitly add it to the root HTTPProxy. I believe folks have written additional controllers to implement this kind of behavior but can't recall off the top of my head where they are. |
This property (having the root HTTPProxy need to explicitly include children) was actually designed to force an interaction - this was designed originally for multi-tenant clusters with a central infra team owning the root HTTPProxies, where the central infra team wanted to know where it was used. The current setup in the Gateway API for Gateway/Route attachment is the opposite, the child (HTTPRoute) requests attachment to the parent (mostly Gateway), and the parent may have additional criteria than just "accept everything in the same namespace". This is a long way of saying sorry, we made a mistake with this design that we can't fix without a version bump of HTTPProxy. I'm reluctant to do that, because Gateway API has a fixed version of the same idea, I would rather push engineering effort into bringing Gateway API into parity with HTTPProxy's functionality. We discussed this issue previously in #2206. |
So I wouldn't say this was a mistake, just that they way it implemented. The right team who should have ownership of that path is given full access to it. With GatewayAPI, there's no such way to make sure the resource who should own the path, gets it. GatewayAPI works on a first-come-first-serve resolution, so as long as you claim the resource first, you get it. The same would happen if you had 2 resources and one is accepted and the other isn't (since the first got there, first). If you deleted the first, the second would get the resource. Then if you recreated the first, you'd be out of luck until the 2nd was deleted. |
I started doing some work on this - primarily just trying to write a working, non-supported test like we do have for the |
@mmalecki let us know if you would like to have this issue assigned, we would definitely take a PR |
@sunjayBhatia yes, please. I poked around the source code, and think I should be able to get it done. |
I was able to get part-way there, but ran into an issue that has me a bit stumped: Envoy appears to be replacing the entire path, as opposed to just the prefix. For example, with a prefix |
@mmalecki what was the path you are matching on for the route(s) you are testing? The Envoy config field we end up using will replace whatever is matched with the specified prefix. So if you have set up a generic prefix match for |
This seems to be how the Gateway API words it as well:
From here If we wanted to have a different path matching logic (e.g. a generic prefix path match like |
Here's also an example of path matching/rewriting in practice: https://github.com/projectcontour/contour/blob/main/test/e2e/httpproxy/path_rewrite_test.go Could add an example for the generic match case as well |
@mmalecki contour v1.21 is coming up, just checking in if you are still working on this and need anything from us? |
My apologies, @sunjayBhatia, I had to step away from this for a little while due to some other priorities. I indeed use Oddly enough, I'm not using apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: kuard
namespace: projectcontour
spec:
hostnames:
- local.projectcontour.io
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: contour
rules:
- backendRefs:
- group: ""
kind: Service
name: kuard
port: 80
weight: 1
filters:
- type: URLRewrite
urlRewrite:
path:
substitution: /substitution/
type: ReplacePrefixMatch
matches:
- path:
type: PathPrefix
value: /prefix I then
But
when the URL should be (My cluster is your typical "getting started with Contour" kind of a kind cluster. My branch is here.) |
Quick thought, I wonder if the fact that internally we're generating a regex match for Gateway API because we need to do "path segement prefix matching" rather than "string prefix matching" is messing this up. Will look some more next week but that seems likely. Also ref. #4442 |
Ah, this being related to a potential different method of matching that "eats up" the part after prefix was one of my suspicions. I'll also take a look if there's anything I can do here. |
Hm, I think I may have a grip on how to approach this alongside #4442, since Envoy's |
Whew, I was indeed able to get this going by using |
I think since this depends on #4442 (I don't see a way to make this happen with RegExp-based matching), which is pending Envoy 1.22, we should change the milestone on this issue to 1.22. One thing I'm at a loss about here is how to make |
Apologies for letting this slip through the cracks. I'm still interested. I've rebased my old |
No problem, thanks @mmalecki! |
hey @mmalecki, just checking in again to see if you'd be able to proceed with a PR here. If not, perhaps we can use your work as a starting point and give you co-author credit. |
I would definitely like to include this; looks like @mmalecki has some work started here but if he's unavailable to complete it we should be able to move it forward and give him co-author credit on it. |
I'm going to grab this issue and try to get it done for the upcoming 1.24 release. |
Fixes projectcontour#4300. Signed-off-by: Steve Kriss <[email protected]>
Adds support for the HTTPURLRewrite filter, which enables path rewriting and Host header rewriting. Fixes #4300. Signed-off-by: Steve Kriss <[email protected]> Co-authored-by: Maciej Małecki <[email protected]>
Adds support for the HTTPURLRewrite filter, which enables path rewriting and Host header rewriting. Fixes projectcontour#4300. Signed-off-by: Steve Kriss <[email protected]> Co-authored-by: Maciej Małecki <[email protected]> Signed-off-by: yy <[email protected]>
Adds support for the HTTPURLRewrite filter, which enables path rewriting and Host header rewriting. Fixes projectcontour#4300. Signed-off-by: Steve Kriss <[email protected]> Co-authored-by: Maciej Małecki <[email protected]> Signed-off-by: yy <[email protected]>
Adds support for the HTTPURLRewrite filter, which enables path rewriting and Host header rewriting. Fixes projectcontour#4300. Signed-off-by: Steve Kriss <[email protected]> Co-authored-by: Maciej Małecki <[email protected]>
Add support for the Gateway API HTTPURLRewriteFilter. This is currently extended support/experimental, but seems worth adding.
The text was updated successfully, but these errors were encountered: