support absolute path redirects for location header in route config
- Dominant language
- C++
- Stars
- 28.9k
- Forks
- 5.6k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 437
Description
*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](https://envoyproxy.slack.com/archives/C78M4KW76/p1647617786518219).
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:
```yml
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.
* [Redirect Action](https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto.html?highlight=path_redirect#config-route-v3-redirectaction)
* [Front proxy pattern](https://www.envoyproxy.io/docs/envoy/latest/start/sandboxes/front_proxy)
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.
Contributor guide
Assessment
This issue has not been assessed yet.