envoyproxy / envoyproxy/envoy

Mirrored request with host rewrite has wrong Host header

Offen
#9,326 13 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area/http bug help wanted
Vorherrschende Sprache
C++
Sterne
28.9k
Forks
5.6k
Ø Merge
1 T. 22 Std.
Gemergte PRs (30 T.)
430

Beschreibung

*Description*:
I'm currently trying to use `request_mirror_policy` in a route that is also using `auto_host_rewrite`.
The problem are the `host/:authority` headers in the mirrored request is giving me weird results...

*Repro steps*:
I created a simplified version of my setup in this [gist](https://gist.github.com/Brunomachadob/33c53e0c3557283eb2e802cc2699fc39) including a full log of execution

```bash
docker-compose up --build
```
```bash
curl localhost:5000/any/host_rewrite
```

Mock server logs 2 requests
```bash
# The actual request
mockserver_1 | {
mockserver_1 | "method" : "GET",
mockserver_1 | "path" : "/any/host_rewrite",
mockserver_1 | "headers" : [ {
mockserver_1 | "name" : "host",
mockserver_1 | "values" : [ "api" ] # successfully rewritten
mockserver_1 | }, {
....
```
```bash
# The mirror request
mockserver_1 | {
mockserver_1 | "method" : "GET",
mockserver_1 | "path" : "/any/host_rewrite",
mockserver_1 | "headers" : [ {
mockserver_1 | "name" : "host",
mockserver_1 | "values" : [ "localhost-shadow:5000" ] # Why localhost?
mockserver_1 | }, {
....
```

Calling again...

```bash
curl localhost:5000/any/host_rewrite
```

Mock server logs 2 requests
```bash
# The actual request
mockserver_1 | {
mockserver_1 | "method" : "GET",
mockserver_1 | "path" : "/any/host_rewrite",
mockserver_1 | "headers" : [ {
mockserver_1 | "name" : "host",
mockserver_1 | "values" : [ "api" ] # successfully rewritten
mockserver_1 | }, {
```
```bash
# The mirrored request
mockserver_1 | {
mockserver_1 | "method" : "GET",
mockserver_1 | "path" : "/any/host_rewrite",
mockserver_1 | "headers" : [ {
mockserver_1 | "name" : "host",
mockserver_1 | "values" : [ "api-shadow" ] # successfully rewritten
```

From now on it's always successfully rewritten, until I restart the containers and the same thing happen. Maybe this is some caching problem in the host resolution?

*Tested versions*
`envoyproxy/envoy:v1.10.0`
`envoyproxy/envoy-dev:daeb9850dbcd78da21a2e8ff9854564830cefb19 # 1.13.0-dev`

*Additional question*
As you can see in my `envoy.yaml` I want to mirror the request to another cluster with another domain (I'm migrating one feature from a monolith to a microservice).

So in my case the real request is going to `api`, and the mirror request is going to another cluster called `api-mirror`. In this case, shouldn't the request mirror get the `host=api-mirror-shadow`?

The [documentation](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route.proto#envoy-api-msg-route-routeaction-requestmirrorpolicy) is not really clear (at least to me) which cluster is going to be used when rewriting, the mirror cluster or the original one?

Thanks for the help!

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.