kubernetes-sigs / gateway-api

Repository for the next iteration of composite service (e.g. Ingress) and load balancing APIs.
https://gateway-api.sigs.k8s.io
Apache License 2.0
1.85k stars 480 forks source link

Support regex based path rewrites #2177

Open arkodg opened 1 year ago

arkodg commented 1 year ago

What would you like to be added: Tracks support for regex based path substitution mentioned in the GEP https://gateway-api.sigs.k8s.io/geps/gep-726/#future-extension

Why this is needed: Automate path rewrites that have a common pattern e.g.

/auth/v1/{pattern} -> /self-service/{pattern}/browser

/auth/v1/login -> /self-service/login/browser
/auth/v1/recovery -> /self-service/recovery/browser
/auth/v1/settings -> /self-service/settings/browser

Related

shaneutt commented 1 year ago

Sounds like a good one to have:

/triage accepted

However, we don't expect this to be something we need for v1 so we're not necessarily ready for anyone to jump in on this one (unless this is the ONLY thing you want to work on).

plnordquist commented 11 months ago

Something that would also be useful in this same sort of rewrite would be matching parts of the hostname to put in the path. An example of this is mapping a sub-domain to a sub path of a backend application.

Some example nginx configuration:

server_name ~(?<sub>.+)\.example.com
if ( $sub != "" ) {
  rewrite ^/(v1|v2)/(.*) /app/$sub/$1/$2 break;
}
youngnick commented 10 months ago

The biggest reason why this is not done yet is about regular expression compatibility. An GEP that addresses this will need also to address:

Since doing regex path rewrites means supporting a regex path match and then using regex matched details in the rewrite filter, this GEP also covers adding regex match support to the base matches stanza.

Other concerns I'd like to see addressed in this GEP that aren't regex compatibility:

For the last two items, we don't need to answer those in the GEP, but if we aren't going to, we need to explicitly put them in as "reserved for future work", so the discussion doesn't get derailed. The regex flavor discussions has all the hallmarks of one that could be contentious to me, which is concerning.

arkodg commented 1 week ago

Envoy Gateway just added support for this using a filter in v1.2, here's an example