envoyproxy/envoy

Mirrored request with host rewrite has wrong Host header

Open

#9.326 aberto em 12 de dez. de 2019

Ver no GitHub
 (13 comments) (0 reactions) (0 assignees)C++ (5.373 forks)batch import
area/httpbughelp wanted

Métricas do repositório

Stars
 (27.997 stars)
Métricas de merge de PR
 (Mesclagem média 8d) (378 fundiu PRs em 30d)

Description

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 including a full log of execution

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

Mock server logs 2 requests

# 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    | 	  }, {
....
# 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...

curl localhost:5000/any/host_rewrite

Mock server logs 2 requests

# 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    | 	  }, {
# 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 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!

Guia do colaborador