Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS L7 ELB HTTP -> HTTPS redirection #1571

Closed
KyleMartin901 opened this issue May 28, 2019 · 5 comments
Closed

AWS L7 ELB HTTP -> HTTPS redirection #1571

KyleMartin901 opened this issue May 28, 2019 · 5 comments
Assignees

Comments

@KyleMartin901
Copy link

Describe the bug

When using AWS L7 ELB to terminate TLS it gets stuck in a 301 redirect loop. When we set x_forwarded_proto_redirect: true we end up getting stuck in a redirect loop, if we set x_forwarded_proto_redirect: false both http and https work correctly.

To Reproduce

Config for gateway and example app presuming you already have the RBAC and Service accounts setup for ambassador

---
apiVersion: v1
kind: Namespace
metadata:
  name: ambassador-nginx
---
apiVersion: v1
kind: Service
metadata:
  name: ambassador-nginx
  namespace: ambassador-nginx
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "{{ tls certificate ARN }}"
    service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443"
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "http"
    service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"
    service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"
    external-dns.alpha.kubernetes.io/hostname: >-
          {{ nginx-hello.example.com }}
    getambassador.io/config: |
      ---
      apiVersion: ambassador/v1
      kind:  Module
      name:  ambassador
      config:
        ambassador_id: ambassador-nginx
        use_proxy_proto: false
        use_remote_address: false
        x_forwarded_proto_redirect: true
spec:
  externalTrafficPolicy: Cluster
  type: LoadBalancer
  ports:
  - name: http
    port: 80
    targetPort: 8080
  - name: https
    port: 443
    targetPort: 8080
  selector:
    service: ambassador
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ambassador-nginx
  namespace: ambassador-nginx
spec:
  selector:
    matchLabels:
      app: ambassador-nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: ambassador-nginx
    spec:
      containers:
      - name: ambassador-nginx
        image: quay.io/datawire/ambassador:0.70.1
        env:
        - name: AMBASSADOR_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: AMBASSADOR_ID
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        ports:
        - name: http
          containerPort: 8080
        - name: https
          containerPort: 8443
        - name: admin
          containerPort: 8877
        securityContext:
          runAsUser: 8888
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-hello
  namespace: ambassador-nginx
spec:
  selector:
    matchLabels:
      run: nginx-hello
  replicas: 1
  template:
    metadata:
      labels:
        run: nginx-hello
    spec:
      containers:
      - name: nginx-hello
        image: nginxdemos/hello
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-hello
  namespace: ambassador-nginx
  labels:
    run: nginx-hello
  annotations:
    getambassador.io/config: |
      ---
      apiVersion: ambassador/v1
      kind:  Mapping
      name:  nginx-hello_ambassador-nginx_mapping
      prefix: /
      host: {{ nginx-hello.example.com }}
      service: nginx-hello.ambassador-nginx:80
      ambassador_id: ambassador-nginx
spec:
  ports:
  - port: 80
    protocol: TCP
    name: http
  selector:
    run: nginx-hello

Expected behavior
When you visit http://{{ nginx-hello.example.com }} you will be redirected to https://{{ nginx-hello.example.com }}

Versions (please complete the following information):

  • Ambassador: 0.61.1
  • Kubernetes environment: EKS
  • Version: v1.11.8-eks-7c34c0

Additional context
Ambassador debug output

[2019-05-28 06:50:58.919][92][debug][http] [source/common/http/conn_manager_impl.cc:580] [C4421][S15381452206514635184] request headers complete (end_stream=true):
':authority', 'nginx-hello.example.com'
':path', '/'
':method', 'GET'
'accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'
'accept-encoding', 'gzip, deflate, br'
'accept-language', 'en-GB,en-US;q=0.9,en;q=0.8'
'cache-control', 'max-age=0'
'cookie', 'refresh=0'
'upgrade-insecure-requests', '1'
'user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
'x-forwarded-for', '65.203.17.146'
'x-forwarded-port', '443'
'x-forwarded-proto', 'https'
'connection', 'keep-alive'

[2019-05-28 06:50:58.919][92][debug][http] [source/common/http/conn_manager_impl.cc:1037] [C4421][S15381452206514635184] request end stream
[2019-05-28 06:50:58.919][92][debug][http] [source/common/http/conn_manager_impl.cc:1278] [C4421][S15381452206514635184] encoding headers via codec (end_stream=true):
':status', '301'
'location', 'https://nginx-hello.example.com/'
'date', 'Tue, 28 May 2019 06:50:58 GMT'
'server', 'envoy'

[2019-05-28 06:50:58.921][95][debug][main] [source/server/connection_handler_impl.cc:257] [C4700] new connection
[2019-05-28 06:50:59.194][95][debug][http] [source/common/http/conn_manager_impl.cc:243] [C4424] new stream
[2019-05-28 06:50:59.194][95][debug][http] [source/common/http/conn_manager_impl.cc:580] [C4424][S11732994775546273527] request headers complete (end_stream=true):
':authority', 'nginx-hello.example.com'
':path', '/'
':method', 'GET'
'accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'
'accept-encoding', 'gzip, deflate, br'
'accept-language', 'en-GB,en-US;q=0.9,en;q=0.8'
'cache-control', 'max-age=0'
'cookie', 'refresh=0'
'upgrade-insecure-requests', '1'
'user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
'x-forwarded-for', '65.203.17.146'
'x-forwarded-port', '443'
'x-forwarded-proto', 'https'
'connection', 'keep-alive'

[2019-05-28 06:50:59.194][95][debug][http] [source/common/http/conn_manager_impl.cc:1037] [C4424][S11732994775546273527] request end stream
[2019-05-28 06:50:59.194][95][debug][http] [source/common/http/conn_manager_impl.cc:1278] [C4424][S11732994775546273527] encoding headers via codec (end_stream=true):
':status', '301'
'location', 'https://nginx-hello.example.com/'
'date', 'Tue, 28 May 2019 06:50:58 GMT'
'server', 'envoy'

[2019-05-28 06:50:59.196][95][debug][main] [source/server/connection_handler_impl.cc:257] [C4701] new connection
[2019-05-28 06:50:59.308][81][debug][main] [source/server/connection_handler_impl.cc:257] [C4702] new connection
[2019-05-28 06:50:59.308][81][debug][http] [source/common/http/conn_manager_impl.cc:243] [C4702] new stream
[2019-05-28 06:50:59.308][81][debug][http] [source/common/http/conn_manager_impl.cc:580] [C4702][S10597010048053133075] request headers complete (end_stream=true):
':authority', '127.0.0.1:8001'
':path', '/logging'
':method', 'POST'
'user-agent', 'python-requests/2.20.1'
'accept-encoding', 'gzip, deflate'
'accept', '*/*'
'connection', 'keep-alive'
'content-length', '0'

[2019-05-28 06:50:59.308][81][debug][http] [source/common/http/conn_manager_impl.cc:1037] [C4702][S10597010048053133075] request end stream
[2019-05-28 06:50:59.308][81][debug][admin] [source/server/http/admin.cc:1068] [C4702][S10597010048053133075] request complete: path: /logging
[2019-05-28 06:50:59.308][81][debug][http] [source/common/http/conn_manager_impl.cc:1278] [C4702][S10597010048053133075] encoding headers via codec (end_stream=false):
':status', '200'
'content-type', 'text/plain; charset=UTF-8'
'cache-control', 'no-cache, max-age=0'
'x-content-type-options', 'nosniff'
'date', 'Tue, 28 May 2019 06:50:59 GMT'
'server', 'envoy'

[2019-05-28 06:50:59.309][81][debug][connection] [source/common/network/connection_impl.cc:502] [C4702] remote close
[2019-05-28 06:50:59.309][81][debug][connection] [source/common/network/connection_impl.cc:183] [C4702] closing socket: 0
[2019-05-28 06:50:59.309][81][debug][main] [source/server/connection_handler_impl.cc:68] [C4702] adding to cleanup list
[2019-05-28 06:50:59.311][81][debug][main] [source/server/connection_handler_impl.cc:257] [C4703] new connection
[2019-05-28 06:50:59.311][81][debug][http] [source/common/http/conn_manager_impl.cc:243] [C4703] new stream
[2019-05-28 06:50:59.311][81][debug][http] [source/common/http/conn_manager_impl.cc:580] [C4703][S4294166464280849593] request headers complete (end_stream=true):
':authority', '127.0.0.1:8001'
':path', '/stats'
':method', 'GET'
'user-agent', 'python-requests/2.20.1'
'accept-encoding', 'gzip, deflate'
'accept', '*/*'
'connection', 'keep-alive'

[2019-05-28 06:50:59.311][81][debug][http] [source/common/http/conn_manager_impl.cc:1037] [C4703][S4294166464280849593] request end stream
[2019-05-28 06:50:59.311][81][debug][admin] [source/server/http/admin.cc:1068] [C4703][S4294166464280849593] request complete: path: /stats
[2019-05-28 06:50:59.315][81][debug][http] [source/common/http/conn_manager_impl.cc:1278] [C4703][S4294166464280849593] encoding headers via codec (end_stream=false):
':status', '200'
'content-type', 'text/plain; charset=UTF-8'
'cache-control', 'no-cache, max-age=0'
'x-content-type-options', 'nosniff'
'date', 'Tue, 28 May 2019 06:50:59 GMT'
'server', 'envoy'

[2019-05-28 06:50:59.316][81][debug][connection] [source/common/network/connection_impl.cc:502] [C4703] remote close
[2019-05-28 06:50:59.316][81][debug][connection] [source/common/network/connection_impl.cc:183] [C4703] closing socket: 0
[2019-05-28 06:50:59.316][81][debug][main] [source/server/connection_handler_impl.cc:68] [C4703] adding to cleanup list
[2019-05-28 06:50:59.386][81][debug][upstream] [source/common/network/dns_impl.cc:158] Setting DNS resolution timer for 5000 milliseconds
[2019-05-28 06:50:59.386][81][debug][upstream] [source/common/network/dns_impl.cc:158] Setting DNS resolution timer for 5000 milliseconds
[2019-05-28 06:50:59.387][81][debug][upstream] [source/common/network/dns_impl.cc:158] Setting DNS resolution timer for 5000 milliseconds
[2019-05-28 06:50:59.470][95][debug][http] [source/common/http/conn_manager_impl.cc:243] [C4631] new stream
[2019-05-28 06:50:59.470][95][debug][http] [source/common/http/conn_manager_impl.cc:580] [C4631][S6829643634668549348] request headers complete (end_stream=true):
':authority', 'nginx-hello.example.com'
':path', '/'
':method', 'GET'
'accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'
'accept-encoding', 'gzip, deflate, br'
'accept-language', 'en-GB,en-US;q=0.9,en;q=0.8'
'cache-control', 'max-age=0'
'cookie', 'refresh=0'
'upgrade-insecure-requests', '1'
'user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
'x-forwarded-for', '65.203.17.146'
'x-forwarded-port', '443'
'x-forwarded-proto', 'https'
'connection', 'keep-alive'

[2019-05-28 06:50:59.470][95][debug][http] [source/common/http/conn_manager_impl.cc:1037] [C4631][S6829643634668549348] request end stream
[2019-05-28 06:50:59.470][95][debug][http] [source/common/http/conn_manager_impl.cc:1278] [C4631][S6829643634668549348] encoding headers via codec (end_stream=true):
':status', '301'
'location', 'https://nginx-hello.example.com/'
'date', 'Tue, 28 May 2019 06:50:59 GMT'
'server', 'envoy'

chrome-output.txt

@iNoahNothing
Copy link
Contributor

@kflynn This is the behavior I was seeing earlier. Once you set x_forwarded_proto_redirect: true ambassador seems to be completely overriding the normal listener with the redirect listener:

Before setting x_forwarded_proto_redirect: true

{
    "@type": "/envoy.config.bootstrap.v2.Bootstrap",
    "static_resources": {
        "clusters": [
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "http2_protocol_options": {},
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_127_0_0_1_8501",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "127.0.0.1",
                                                "port_value": 8501,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_127_0_0_1_8501",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_127_0_0_1_8877",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "127.0.0.1",
                                                "port_value": 8877,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_127_0_0_1_8877",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_NoTaReAlSeRvIcE",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "notarealservice",
                                                "port_value": 80,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_NoTaReAlSeRvIcE",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "http2_protocol_options": {},
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_extauth_127_0_0_1_8500",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "127.0.0.1",
                                                "port_value": 8500,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_extauth_127_0_0_1_8500",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_httpbin_org_80",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "httpbin.org",
                                                "port_value": 80,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_httpbin_org_80",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_qotm",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "qotm",
                                                "port_value": 80,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_qotm",
                "type": "STRICT_DNS"
            }
        ],
        "listeners": [
            {
                "address": {
                    "socket_address": {
                        "address": "0.0.0.0",
                        "port_value": 8080,
                        "protocol": "TCP"
                    }
                },
                "filter_chains": [
                    {
                        "filters": [
                            {
                                "config": {
                                    "access_log": [
                                        {
                                            "config": {
                                                "format": "ACCESS [%START_TIME%] \"%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%\" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% \"%REQ(X-FORWARDED-FOR)%\" \"%REQ(USER-AGENT)%\" \"%REQ(X-REQUEST-ID)%\" \"%REQ(:AUTHORITY)%\" \"%UPSTREAM_HOST%\"\n",
                                                "path": "/dev/fd/1"
                                            },
                                            "name": "envoy.file_access_log"
                                        }
                                    ],
                                    "http_filters": [
                                        {
                                            "config": {},
                                            "name": "envoy.grpc_web"
                                        },
                                        {
                                            "config": {
                                                "grpc_service": {
                                                    "envoy_grpc": {
                                                        "cluster_name": "cluster_extauth_127_0_0_1_8500"
                                                    },
                                                    "timeout": "5.000s"
                                                },
                                                "use_alpha": true
                                            },
                                            "name": "envoy.ext_authz"
                                        },
                                        {
                                            "config": {
                                                "domain": "ambassador",
                                                "rate_limit_service": {
                                                    "grpc_service": {
                                                        "envoy_grpc": {
                                                            "cluster_name": "cluster_127_0_0_1_8501"
                                                        }
                                                    }
                                                },
                                                "request_type": "both",
                                                "timeout": "0.020s"
                                            },
                                            "name": "envoy.rate_limit"
                                        },
                                        {
                                            "name": "envoy.cors"
                                        },
                                        {
                                            "name": "envoy.router"
                                        }
                                    ],
                                    "http_protocol_options": {
                                        "accept_http_10": false
                                    },
                                    "normalize_path": true,
                                    "route_config": {
                                        "virtual_hosts": [
                                            {
                                                "domains": [
                                                    "*"
                                                ],
                                                "name": "backend",
                                                "routes": [
                                                    {
                                                        "match": {
                                                            "case_sensitive": true,
                                                            "prefix": "/ambassador/v0/check_ready"
                                                        },
                                                        "route": {
                                                            "prefix_rewrite": "/ambassador/v0/check_ready",
                                                            "priority": null,
                                                            "rate_limits": [
                                                                {
                                                                    "actions": [
                                                                        {
                                                                            "request_headers": {
                                                                                "descriptor_key": "x_limited_user",
                                                                                "header_name": "x-limited-user"
                                                                            }
                                                                        }
                                                                    ],
                                                                    "stage": 0
                                                                }
                                                            ],
                                                            "timeout": "10.000s",
                                                            "weighted_clusters": {
                                                                "clusters": [
                                                                    {
                                                                        "name": "cluster_127_0_0_1_8877",
                                                                        "weight": 100
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "case_sensitive": true,
                                                            "prefix": "/ambassador/v0/check_alive"
                                                        },
                                                        "route": {
                                                            "prefix_rewrite": "/ambassador/v0/check_alive",
                                                            "priority": null,
                                                            "rate_limits": [
                                                                {
                                                                    "actions": [
                                                                        {
                                                                            "request_headers": {
                                                                                "descriptor_key": "x_limited_user",
                                                                                "header_name": "x-limited-user"
                                                                            }
                                                                        }
                                                                    ],
                                                                    "stage": 0
                                                                }
                                                            ],
                                                            "timeout": "10.000s",
                                                            "weighted_clusters": {
                                                                "clusters": [
                                                                    {
                                                                        "name": "cluster_127_0_0_1_8877",
                                                                        "weight": 100
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "case_sensitive": true,
                                                            "prefix": "/httpbin-limited/"
                                                        },
                                                        "route": {
                                                            "host_rewrite": "httpbin.org",
                                                            "prefix_rewrite": "/",
                                                            "priority": null,
                                                            "rate_limits": [
                                                                {
                                                                    "actions": [
                                                                        {
                                                                            "request_headers": {
                                                                                "descriptor_key": "x_limited_user",
                                                                                "header_name": "x-limited-user"
                                                                            }
                                                                        }
                                                                    ],
                                                                    "stage": 0
                                                                }
                                                            ],
                                                            "timeout": "3.000s",
                                                            "weighted_clusters": {
                                                                "clusters": [
                                                                    {
                                                                        "name": "cluster_httpbin_org_80",
                                                                        "weight": 100
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "case_sensitive": true,
                                                            "prefix": "/ambassador/v0/"
                                                        },
                                                        "route": {
                                                            "prefix_rewrite": "/ambassador/v0/",
                                                            "priority": null,
                                                            "rate_limits": [
                                                                {
                                                                    "actions": [
                                                                        {
                                                                            "request_headers": {
                                                                                "descriptor_key": "x_limited_user",
                                                                                "header_name": "x-limited-user"
                                                                            }
                                                                        }
                                                                    ],
                                                                    "stage": 0
                                                                }
                                                            ],
                                                            "timeout": "10.000s",
                                                            "weighted_clusters": {
                                                                "clusters": [
                                                                    {
                                                                        "name": "cluster_127_0_0_1_8877",
                                                                        "weight": 100
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "case_sensitive": true,
                                                            "prefix": "/qotm/open/"
                                                        },
                                                        "route": {
                                                            "prefix_rewrite": "/",
                                                            "priority": null,
                                                            "rate_limits": [
                                                                {
                                                                    "actions": [
                                                                        {
                                                                            "request_headers": {
                                                                                "descriptor_key": "x_limited_user",
                                                                                "header_name": "x-limited-user"
                                                                            }
                                                                        }
                                                                    ],
                                                                    "stage": 0
                                                                }
                                                            ],
                                                            "timeout": "3.000s",
                                                            "weighted_clusters": {
                                                                "clusters": [
                                                                    {
                                                                        "name": "cluster_qotm",
                                                                        "weight": 100
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "case_sensitive": true,
                                                            "prefix": "/httpbin/"
                                                        },
                                                        "route": {
                                                            "host_rewrite": "httpbin.org",
                                                            "prefix_rewrite": "/",
                                                            "priority": null,
                                                            "rate_limits": [
                                                                {
                                                                    "actions": [
                                                                        {
                                                                            "request_headers": {
                                                                                "descriptor_key": "x_limited_user",
                                                                                "header_name": "x-limited-user"
                                                                            }
                                                                        },
                                                                        {
                                                                            "remote_address": {}
                                                                        }
                                                                    ],
                                                                    "stage": 0
                                                                }
                                                            ],
                                                            "timeout": "3.000s",
                                                            "weighted_clusters": {
                                                                "clusters": [
                                                                    {
                                                                        "name": "cluster_httpbin_org_80",
                                                                        "weight": 100
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "case_sensitive": true,
                                                            "prefix": "/callback"
                                                        },
                                                        "route": {
                                                            "prefix_rewrite": "/",
                                                            "priority": null,
                                                            "rate_limits": [
                                                                {
                                                                    "actions": [
                                                                        {
                                                                            "request_headers": {
                                                                                "descriptor_key": "x_limited_user",
                                                                                "header_name": "x-limited-user"
                                                                            }
                                                                        }
                                                                    ],
                                                                    "stage": 0
                                                                }
                                                            ],
                                                            "timeout": "3.000s",
                                                            "weighted_clusters": {
                                                                "clusters": [
                                                                    {
                                                                        "name": "cluster_NoTaReAlSeRvIcE",
                                                                        "weight": 100
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    "server_name": "envoy",
                                    "stat_prefix": "ingress_http",
                                    "use_remote_address": true,
                                    "xff_num_trusted_hops": 0
                                },
                                "name": "envoy.http_connection_manager"
                            }
                        ],
                        "use_proxy_proto": true
                    }
                ],
                "name": "ambassador-listener-8080"
            }
        ]
    }
}

After setting x_forwarded_proto_redirect: true

{
    "@type": "/envoy.config.bootstrap.v2.Bootstrap",
    "static_resources": {
        "clusters": [
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "http2_protocol_options": {},
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_127_0_0_1_8501",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "127.0.0.1",
                                                "port_value": 8501,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_127_0_0_1_8501",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_127_0_0_1_8877",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "127.0.0.1",
                                                "port_value": 8877,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_127_0_0_1_8877",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_NoTaReAlSeRvIcE",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "notarealservice",
                                                "port_value": 80,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_NoTaReAlSeRvIcE",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "http2_protocol_options": {},
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_extauth_127_0_0_1_8500",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "127.0.0.1",
                                                "port_value": 8500,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_extauth_127_0_0_1_8500",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_httpbin_org_80",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "httpbin.org",
                                                "port_value": 80,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_httpbin_org_80",
                "type": "STRICT_DNS"
            },
            {
                "connect_timeout": "3.000s",
                "dns_lookup_family": "V4_ONLY",
                "lb_policy": "ROUND_ROBIN",
                "load_assignment": {
                    "cluster_name": "cluster_qotm",
                    "endpoints": [
                        {
                            "lb_endpoints": [
                                {
                                    "endpoint": {
                                        "address": {
                                            "socket_address": {
                                                "address": "qotm",
                                                "port_value": 80,
                                                "protocol": "TCP"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                "name": "cluster_qotm",
                "type": "STRICT_DNS"
            }
        ],
        "listeners": [
            {
                "address": {
                    "socket_address": {
                        "address": "0.0.0.0",
                        "port_value": "8443",
                        "protocol": "TCP"
                    }
                },
                "filter_chains": [
                    {
                        "filters": [
                            {
                                "config": {
                                    "access_log": null,
                                    "http_filters": [
                                        {
                                            "name": "envoy.router"
                                        }
                                    ],
                                    "http_protocol_options": {
                                        "accept_http_10": false
                                    },
                                    "normalize_path": true,
                                    "route_config": {
                                        "virtual_hosts": [
                                            {
                                                "domains": [
                                                    "*"
                                                ],
                                                "name": "backend",
                                                "require_tls": "EXTERNAL_ONLY",
                                                "routes": [
                                                    {
                                                        "match": {
                                                            "prefix": "/"
                                                        },
                                                        "redirect": {
                                                            "https_redirect": true,
                                                            "path_redirect": "/"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    "server_name": "envoy",
                                    "stat_prefix": "ingress_http",
                                    "use_remote_address": true,
                                    "xff_num_trusted_hops": 0
                                },
                                "name": "envoy.http_connection_manager"
                            }
                        ],
                        "use_proxy_proto": true
                    }
                ],
                "name": "redirect_listener"
            }
        ]
    }
}

@phillycheeze
Copy link

Also seeing the same issue. Using a lower version of ambassador in the meantime.

@atarynin
Copy link

atarynin commented Jun 6, 2019

The same issue in the 0.70.1 version

@kflynn kflynn added this to the sagrada-familia milestone Jun 6, 2019
@concaf concaf self-assigned this Jun 10, 2019
@KyleMartin901
Copy link
Author

KyleMartin901 commented Jun 11, 2019

@containscafeine I have discovered where the issue maybe.

If you look at https://github.com/datawire/ambassador/blob/030d897cafa65e592eb3438b391310b6d900986d/ambassador/ambassador/envoy/v2/v2listener.py#L452 you can see you set a default route for a listner is

self.routes: List[dict] = [ {
    'match': {
        'prefix': '/',
    },
    'redirect': {
        'https_redirect': True
    }
} ]

This default route is an infinite redirect loop as the envoy setting redirect -> https_redirect: True just does a redirect that only swaps the scheme to https ending in an infinite loop of redirection to same URL with https as it isn't checking if the url is already https before swapping the scheme to https.

The next issue is that if you set require TLS that is the only route that gets added to the listener found in the if statement https://github.com/datawire/ambassador/blob/master/ambassador/ambassador/envoy/v2/v2listener.py#L477 so you will never get any routes to the services you require or have described in the anotations only the default route with the redirect loop. I would of thought that you would still build the routes in the else statement and remove the self.require_tls = None that wroutes are still built as desired and then just set the require_tls on the virtual host like you do https://github.com/datawire/ambassador/blob/master/ambassador/ambassador/envoy/v2/v2listener.py#L566

I wasn't sure if there was another reason why this config is setup this way as it is a redirect listener and didn't know the impact of changing these settings would have so hope this comment makes sense and is okay.

I have added two envoy configs that were generated using the initial configuration of this issue one with x_forwarded_proto set to false x_forwarded_proto_redirect.false.envoy.json.txt and then one when x_forwarded_proto was set to true
x_forwarded_proto_redirect.true.envoy.json.txt and you can see it only uses the default route rather then just adding the "require_tls": "EXTERNAL_ONLY", to the virtual host.

KyleMartin901 added a commit to KyleMartin901/emissary that referenced this issue Jun 12, 2019
This commit removes a bug where when you set the ambassador module
config x_forwarded_proto_redirect to true it would generate a
configuration that caused an infinite redirect loop.

The main cause of this issue was that the if you set the
x_forwarded_proto_redirect to true it would only create an envoy
listner with the default route rather than still appending the
desired custom routes specified in the Kubernetes services annotations.

The default route now doesn't contain a redirect that does a
[https_redirect](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route.proto#route-redirectaction)
due to it causing an infinite loop of redirects as it
would substitue the scheme portion of the URL for https and redirect to
that URL even if that scheme was already https.

Removed the check for the `listener.redirect_listener` before building
the routes so the routes would always be built and defult route would be
overwriten if routes have been defined wether or not
`listener.redirect_listener` had been set or not. Added a condition to
set the `self.require_tls = None` only if `listener.redirect_listener`
had not be set.

This change now means that Ambassador will add the `"require_tls":
"EXTERNAL_ONLY"` configuration to the envoy virtal host if the
Ambassador module `x_forwarded_proto_redirect` is set to true forcing
all external requests to the gateway to use https.

Corrects issue: emissary-ingress#1571
@kflynn kflynn modified the milestones: sagrada-familia, santa-cruz Jun 12, 2019
concaf pushed a commit that referenced this issue Jun 13, 2019
This commit removes a bug where when you set the ambassador module
config x_forwarded_proto_redirect to true it would generate a
configuration that caused an infinite redirect loop.

The main cause of this issue was that the if you set the
x_forwarded_proto_redirect to true it would only create an envoy
listner with the default route rather than still appending the
desired custom routes specified in the Kubernetes services annotations.

The default route now doesn't contain a redirect that does a
[https_redirect](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route.proto#route-redirectaction)
due to it causing an infinite loop of redirects as it
would substitue the scheme portion of the URL for https and redirect to
that URL even if that scheme was already https.

Removed the check for the `listener.redirect_listener` before building
the routes so the routes would always be built and defult route would be
overwriten if routes have been defined wether or not
`listener.redirect_listener` had been set or not. Added a condition to
set the `self.require_tls = None` only if `listener.redirect_listener`
had not be set.

This change now means that Ambassador will add the `"require_tls":
"EXTERNAL_ONLY"` configuration to the envoy virtal host if the
Ambassador module `x_forwarded_proto_redirect` is set to true forcing
all external requests to the gateway to use https.

Corrects issue: #1571
concaf pushed a commit that referenced this issue Jun 13, 2019
This commit removes a bug where when you set the ambassador module
config x_forwarded_proto_redirect to true it would generate a
configuration that caused an infinite redirect loop.

The main cause of this issue was that the if you set the
x_forwarded_proto_redirect to true it would only create an envoy
listner with the default route rather than still appending the
desired custom routes specified in the Kubernetes services annotations.

The default route now doesn't contain a redirect that does a
[https_redirect](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route.proto#route-redirectaction)
due to it causing an infinite loop of redirects as it
would substitue the scheme portion of the URL for https and redirect to
that URL even if that scheme was already https.

Removed the check for the `listener.redirect_listener` before building
the routes so the routes would always be built and defult route would be
overwriten if routes have been defined wether or not
`listener.redirect_listener` had been set or not. Added a condition to
set the `self.require_tls = None` only if `listener.redirect_listener`
had not be set.

This change now means that Ambassador will add the `"require_tls":
"EXTERNAL_ONLY"` configuration to the envoy virtal host if the
Ambassador module `x_forwarded_proto_redirect` is set to true forcing
all external requests to the gateway to use https.

Corrects issue: #1571
@richarddli
Copy link
Contributor

Fixed in 0.72

LukeShu pushed a commit that referenced this issue Sep 29, 2020
This commit replaces the current JSON-based communication between the
`edgectl` client and daemon processes with a gRPC based API. The
API description and the files generated from it lives in the package
`internal/pkg/edgectl/rpc`.

The commit also separates the files belonging to the client and daemon
into two corresponding packages. The client package contains all code
pertaining to CLI and presentation details and daemon no longer produces
anything directly intended for the user (aside from logging to the
logfile).

Closes #1571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants