Envoy: [Help wanted] 308 Permanent Redirect example

Created on 26 Sep 2019  Â·  10Comments  Â·  Source: envoyproxy/envoy

308 Permanent Redirect example

_Description:_
I'm trying to set up Envoy to redirect the traffic to a specific location based in a header location parameter (308 Permanent Redirect)

_Question_
Do you have an example of this configuration?

question stale

Most helpful comment

this example redirects everything to www.google.com

admin:
  access_log_path: /dev/null
  address:
    socket_address:
      address: 127.0.0.1
      port_value: 9901

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address:
          address: 127.0.0.1
          port_value: 8000
      filter_chains:
      - filters:
        - name: envoy.http_connection_manager
          typed_config:
            "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
            stat_prefix: ingress_http
            codec_type: AUTO
            route_config:
              name: local_route
              virtual_hosts:
              - name: local_service
                domains: ["*"]
                routes:
                - match:
                    prefix: "/"
                  redirect:
                    host_redirect: www.google.com
                    response_code: PERMANENT_REDIRECT
            http_filters:
            - name: envoy.router

curl output:

➜  ~ curl -svo /dev/null localhost:8000/foobar 2>&1 | grep "< "
< HTTP/1.1 308 Permanent Redirect
< location: http://www.google.com/foobar
< date: Fri, 04 Oct 2019 19:51:14 GMT
< server: envoy
< content-length: 0
<
➜  ~

All 10 comments

this example redirects everything to www.google.com

admin:
  access_log_path: /dev/null
  address:
    socket_address:
      address: 127.0.0.1
      port_value: 9901

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address:
          address: 127.0.0.1
          port_value: 8000
      filter_chains:
      - filters:
        - name: envoy.http_connection_manager
          typed_config:
            "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
            stat_prefix: ingress_http
            codec_type: AUTO
            route_config:
              name: local_route
              virtual_hosts:
              - name: local_service
                domains: ["*"]
                routes:
                - match:
                    prefix: "/"
                  redirect:
                    host_redirect: www.google.com
                    response_code: PERMANENT_REDIRECT
            http_filters:
            - name: envoy.router

curl output:

➜  ~ curl -svo /dev/null localhost:8000/foobar 2>&1 | grep "< "
< HTTP/1.1 308 Permanent Redirect
< location: http://www.google.com/foobar
< date: Fri, 04 Oct 2019 19:51:14 GMT
< server: envoy
< content-length: 0
<
➜  ~

Hi @derekargueta !
Thanks for your example, works perfect but, I'm thinking in an example as internal redirect like Envoy behavior for the 302 code.

Is this possible for 308 and 307 codes?
Does Envoy have a cache behavior to store the first permanent redirection and avoid a second request to the same backend?

@mmorejon not sure on cache behaviour but 307 possible. Documentation at https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route.proto.html?highlight=permanent_redirect#enum-route-redirectaction-redirectresponsecode

@derekargueta, @moderation , I think we are talking different situations.
Your link belongs to an Envoy configuration with the ability to respond a 307 and 308 code to the client, but this isn't my case.
I need that Envoy as a proxy, detects a 308 or a 307 code from the backend and send the new request automatically based on the location header. The client just need the final respond from the second request.
Take a look at the diagram.
image
Thanks in advance!

Oh I see, you want Envoy to follow the Location header, not the client. Like the -L flag on curl. Envoy does not have this feature to my knowledge, it will return the response to the client.

Exactly, like -L flag on curl.
Is it possible simulate this behavior with Lua filter during the response phase?

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

unstale

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings