envoyproxy/envoy

support absolute path redirects for location header in route config

Open

#20,492 创建于 2022年3月23日

在 GitHub 查看
 (6 评论) (0 反应) (0 负责人)C++ (5,373 fork)batch import
area/docsarea/httparea/routerhelp wanted

仓库指标

Star
 (27,997 star)
PR 合并指标
 (平均合并 8天) (30 天内合并 378 个 PR)

描述

Title: support absolute path redirects for location header in route config

Description:

Describe the desired behavior, what scenario it enables and how it would be used.

I asked a related question on the Slack.

Our users use our application at example.com, and we are using Envoy as a front proxy. It also sits behind Cloudflare and then on a K8S cluster with its own DNS name at prod.example.com.

We need to route our / landing page to /home for historical reasons. We used the following configuration:

          route_config:
            name: routes
            virtual_hosts:
            - name: service_routes
              domains:
              - "*"
              routes:
              # ... other routes
              - name: home redirect
                match:
                  path: "/"
                redirect:
                  path_redirect: "/home"

With this, I found out that Envoy will send a location header with the authority that Envoy resolved: prod.example.com.

I expected that the /home path redirect value would be returned directly. I think Envoy rewrites/upgrades the redirect to match what was incoming in the Host header, http/https.

I can mimic that behavior locally with a Host header, curl -v -H "Host: prod.example.com" http://localhost:5000:

proxy        | [2022-03-23 16:40:10.809][18][debug][conn_handler] [source/server/active_tcp_listener.cc:140] [C18] new connection from 172.24.0.1:62004
proxy        | [2022-03-23 16:40:10.811][18][debug][http] [source/common/http/conn_manager_impl.cc:283] [C18] new stream
proxy        | [2022-03-23 16:40:10.812][18][debug][http] [source/common/http/conn_manager_impl.cc:873] [C18][S17277694458725646929] request headers complete (end_stream=true):
proxy        | ':authority', 'prod.example.com'
proxy        | ':path', '/'
proxy        | ':method', 'GET'
proxy        | 'user-agent', 'curl/7.64.1'
proxy        | 'accept', '*/*'
proxy        |
proxy        | [2022-03-23 16:40:10.812][18][debug][http] [source/common/http/filter_manager.cc:841] [C18][S17277694458725646929] request end stream
proxy        | [2022-03-23 16:40:10.813][18][debug][lua] [source/extensions/filters/common/lua/lua.cc:39] coroutine finished
proxy        | [2022-03-23 16:40:10.813][18][debug][http] [source/common/http/filter_manager.cc:953] [C18][S17277694458725646929] Sending local reply with details direct_response
proxy        | [2022-03-23 16:40:10.813][18][debug][lua] [source/extensions/filters/common/lua/lua.cc:39] coroutine finished
proxy        | [2022-03-23 16:40:10.813][18][debug][http] [source/common/http/conn_manager_impl.cc:1472] [C18][S17277694458725646929] encoding headers via codec (end_stream=true):
proxy        | ':status', '301'
proxy        | 'location', 'http://prod.example.com/home'
proxy        | 'date', 'Wed, 23 Mar 2022 16:40:10 GMT'
proxy        | 'server', 'envoy'
proxy        |
proxy        | [2022-03-23 16:40:10.818][18][debug][connection] [source/common/network/connection_impl.cc:648] [C18] remote close
proxy        | [2022-03-23 16:40:10.818][18][debug][connection] [source/common/network/connection_impl.cc:249] [C18] closing socket: 0
proxy        | [2022-03-23 16:40:10.818][18][debug][conn_handler] [source/server/active_stream_listener_base.cc:120] [C18] adding to cleanup list

If Envoy returned the location header as an absolute path, there would be no inconsistency with http/https and user facing domain names.

I worked around this issue by adding host_redirect: example.com and https_redirect: true to the redirect config.

It would be great having absolute redirects without the rewrite/upgrade supported (returning Location: /home back to the user), or even simple url (https://example.com/home) driven redirects without needing multiple components defined in the config.

[optional Relevant Links:]

Any extra documentation required to understand the issue.

If you have alternative suggestions for approaches or title for this issue, please let me know.

Update

Tweaked the wording on the "worked around" line above.

贡献者指南