envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
25.04k stars 4.82k forks source link

Dynamic forward proxy - host www.google.com:80 not found #37200

Closed yoav-sentinel closed 2 hours ago

yoav-sentinel commented 3 hours ago

Title: Dynamic forward proxy host not found

Description: My use case is to use an external processor to decide the actual request routing (and set a target header for example), and then use the dynamic forward proxy to forward the request with host_rewrite_header (instead of using defined cluster per upstream due to huge amount of upstreams).

I've simplified envoy configuration and removed the external processor, to just validate the dynamic forward proxy works:

admin:
  address:
    socket_address:
      protocol: TCP
      address: 0.0.0.0
      port_value: 9901

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address:
          address: 0.0.0.0
          port_value: 10000

      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                access_log:
                  - name: envoy.file_access_log
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
                      path: /dev/stdout
                      json_format:
                        session: "%REQ(X_COOKIE_USER_SESSION)%"
                        oauth_client_id: "%REQ(X_COOKIE_OAUTH_CLIENT_ID)%"
                        os_version: "%REQ(X_COOKIE_OS_VERSION)%"
                        status: "%RESPONSE_CODE%"
                stat_prefix: ingress_http
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: dynamic_forward_proxy
                      domains: [ "*" ]
                      routes:
                        - match:
                            prefix: "/"
                          route:
                            cluster: dynamic_forward_proxy_cluster
                          typed_per_filter_config:
                            envoy.filters.http.dynamic_forward_proxy:
                              "@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.PerRouteConfig
                              host_rewrite_literal: www.google.com:80

                http_filters:
                  - name: envoy.filters.http.dynamic_forward_proxy
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.FilterConfig
                      dns_cache_config:
                        name: dynamic_dns_cache
                        dns_lookup_family: V4_ONLY

                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

  clusters:
    - name: dynamic_forward_proxy_cluster
      lb_policy: CLUSTER_PROVIDED
      cluster_type:
        name: envoy.clusters.dynamic_forward_proxy
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
          dns_cache_config:
            name: dynamic_forward_proxy_cache_config
            dns_lookup_family: V4_ONLY

Though the request: curl -v -k http://localhost:10000

Returns 503 due to: [2024-11-18 09:43:56.029][28][debug][upstream] [source/extensions/clusters/dynamic_forward_proxy/cluster.cc:406] host www.google.com:80 not found

Any idea what is wrong with my configuration / request?

When I'm defining a google_service cluster to www.google.com endpoint on port 80 it works correctly.

yoav-sentinel commented 2 hours ago

Issue was that the dns_cache_config name was different in the cluster vs the filter:

                      dns_cache_config:
                        name: dynamic_dns_cache

vs

          dns_cache_config:
            name: dynamic_forward_proxy_cache_config