kubernetes-sigs / kubernetes-sigs/gateway-api

Semantics of url rewrite prefix replace - clarifications required

Open
#3,592 15 comments 5 reactions 1 assignee Claimed by @snorwin View on GitHub
triage/needs-alignment
Dominant language
Go
Stars
3k
Forks
789
Avg merge
2d 15h
Merged PRs (30d)
45

Description

This is a followup to a surprisingly long thread on [slack](https://kubernetes.slack.com/archives/CR0H13KGA/p1738253555742969).

Our spec has a very [detailed table](https://github.com/kubernetes-sigs/gateway-api/blob/5dd3155c9069144bc7c79e413ac92ac4dae14251/apis/v1/httproute_types.go#L1105-L1119) of expectations for `ReplacePrefixMatch` field. However it does not cover the case where the `Prefix Match`(not the replacement) is "/".

Adding the spec table here for convenience:

```
// Request Path | Prefix Match | Replace Prefix | Modified Path
// -------------|--------------|----------------|----------
// /foo/bar | /foo | /xyz | /xyz/bar
// /foo/bar | /foo | /xyz/ | /xyz/bar
// /foo/bar | /foo/ | /xyz | /xyz/bar
// /foo/bar | /foo/ | /xyz/ | /xyz/bar
// /foo | /foo | /xyz | /xyz
// /foo/ | /foo | /xyz | /xyz/
// /foo/bar | /foo | | /bar
// /foo/ | /foo | | /
// /foo | /foo | | /
// /foo/ | /foo | / | /
// /foo | /foo | / | /
```

The ambiguity mostly comes down to the case where *Prefix Match* is "/". Below are a few examples:

```
// Request Path | Prefix Match | Replace Prefix | Modified Path
// -------------|--------------|----------------|----------
// /bar | / | /xyz | /xyz/bar (AND NOT "/xyzbar")
// /bar | / | /xyz/ | /xyz/bar (AND NOT "/xyz//bar")
// / | / | /xyz | /xyz (AND NOT "/xyz/")
// /bar | / | | /bar (And NOT "bar")
// / | / | | / (AND NOT "")
// / | / | / | /
```

_AND NOT is a language I used to reflect the proposed standardization. You can also be read it as OR if you have a different opinion._

Although there is no easy way in envoy to achieve this behavior (other non-envoy implementations, please shout if this is easily possible with your proxies), @howardjohn came up with a regex that makes this possible (ref https://github.com/istio/istio/pull/54939/files#diff-a0e8831b6aefb0ef9b2cd269fcd726b26fd1104120950952b5217a7b104ba153R1668-R1669)

Hoping this thread would result in a change to our spec to explicitly iron it out.

/cc @mikemorris @arkodg @robscott @howardjohn @kflynn

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.