networking: add prefix_rewrite and uri_regex_rewrite to HTTPRedirect#3708
networking: add prefix_rewrite and uri_regex_rewrite to HTTPRedirect#3708liamawhite wants to merge 3 commits into
Conversation
Extends HTTPRedirect to support prefix-aware path manipulation on redirect responses, exposing Envoy's existing prefix_rewrite and regex_rewrite capabilities in RedirectAction. Previously, HTTPRedirect.uri replaced the entire path regardless of the route match type. This adds two new mutually-exclusive fields: - prefix_rewrite: replaces the matched route prefix with the given value, enabling /foo/bar -> /baz/bar style redirects - uri_regex_rewrite: rewrites the path using RE2 regex with capture group substitution for complex transformations Both are mutually exclusive with the existing uri field. Validation is enforced in the istio/istio control plane.
|
🤔 🐛 You appear to be fixing a bug in Go code, yet your PR doesn't include updates to any test files. Did you forget to add a test? Courtesy of your friendly test nag. |
|
I'm not sure why we shouldn't do this under the banner of gateway API (/cc @Stevenjin8). The fields will likely exist on VS since that's how we translate, but ideally Gateway API is the scope |
|
Fromt the title though, this is for http redirect, not path rewrites, so they are slightly different things. |
|
IIRC prefix rewrite for redirect exists in the gateway API but Istio implements it using a hack to get round the fact its not in the virtual service API. i.e. Some metadata gets added during translation that allows the gateway API to pass this through to the thing generating the XDS configuration without it existing in the VirtualService API. |
Summary
HTTPRedirect.uriperforms a full path replacement and has no prefix-aware variant. Envoy'sRedirectActionhas supportedprefix_rewriteandregex_rewritefor years, but Istio has never exposed them, making it impossible to perform redirects that preserve the path suffix (e.g.example.com/foo/bar→foo.example.com/bar).This was requested in istio/istio#47500, istio/istio#47777, and istio/istio#52521, all of which were closed as stale.
This PR adds two new fields to
HTTPRedirectinside aoneof path_rewrite_specifier:prefix_rewrite— replaces the matched route prefix, leaving the rest of the path intact. The route must use a prefix URI match.uri_regex_rewrite— RE2 regex rewrite with capture group substitution (reuses the existingRegexRewritemessage).Both are mutually exclusive with the existing
urifield (enforced by validation in istio/istio). The legacyurifield is unchanged.Examples
Strip a prefix and change host (
example.com/foo/bar→foo.example.com/bar):Replace a prefix (
example.com/foo/bar→example.com/baz/bar):Regex rewrite — canonicalize account-scoped paths (
example.com/accounts/12345/orders→example.com/orders/12345):Full path replacement (existing behaviour, unchanged):
Related