Dynamic forward proxy

The following is a complete configuration that configures both the dynamic forward proxy HTTP filter as well as the dynamic forward proxy cluster. Both filter and cluster must be configured together and point to the same DNS cache parameters for Envoy to operate as an HTTP dynamic forward proxy.

This filter supports host rewrite via the virtual host’s typed_per_filter_config or the route’s typed_per_filter_config. This can be used to rewrite the host header with the provided value before DNS lookup, thus allowing to route traffic to the rewritten host when forwarding. See the example below within the configured routes.

Note

Configuring a transport_socket with name envoy.transport_sockets.tls on the cluster with trusted_ca certificates instructs Envoy to use TLS when connecting to upstream hosts and verify the certificate chain. Additionally, Envoy will automatically perform SAN verification for the resolved host name as well as specify the host name via SNI.

Dynamic forward proxy uses circuit breakers built in to the DNS cache with the configuration of DNS cache circuit breakers.

  1. admin:
  2. address:
  3. socket_address:
  4. protocol: TCP
  5. address: 127.0.0.1
  6. port_value: 9901
  7. static_resources:
  8. listeners:
  9. - name: listener_0
  10. address:
  11. socket_address:
  12. protocol: TCP
  13. address: 0.0.0.0
  14. port_value: 10000
  15. filter_chains:
  16. - filters:
  17. - name: envoy.filters.network.http_connection_manager
  18. typed_config:
  19. "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
  20. stat_prefix: ingress_http
  21. route_config:
  22. name: local_route
  23. virtual_hosts:
  24. - name: local_service
  25. domains: ["*"]
  26. routes:
  27. - match:
  28. prefix: "/force-host-rewrite"
  29. route:
  30. cluster: dynamic_forward_proxy_cluster
  31. typed_per_filter_config:
  32. envoy.filters.http.dynamic_forward_proxy:
  33. "@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.PerRouteConfig
  34. host_rewrite_literal: www.example.org
  35. - match:
  36. prefix: "/"
  37. route:
  38. cluster: dynamic_forward_proxy_cluster
  39. http_filters:
  40. - name: envoy.filters.http.dynamic_forward_proxy
  41. typed_config:
  42. "@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.FilterConfig
  43. dns_cache_config:
  44. name: dynamic_forward_proxy_cache_config
  45. dns_lookup_family: V4_ONLY
  46. typed_dns_resolver_config:
  47. name: envoy.network.dns_resolver.cares
  48. typed_config:
  49. "@type": type.googleapis.com/envoy.extensions.network.dns_resolver.cares.v3.CaresDnsResolverConfig
  50. resolvers:
  51. - socket_address:
  52. address: "8.8.8.8"
  53. port_value: 53
  54. dns_resolver_options:
  55. use_tcp_for_dns_lookups: true
  56. no_default_search_domain: true
  57. - name: envoy.filters.http.router
  58. typed_config:
  59. "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  60. clusters:
  61. - name: dynamic_forward_proxy_cluster
  62. lb_policy: CLUSTER_PROVIDED
  63. cluster_type:
  64. name: envoy.clusters.dynamic_forward_proxy
  65. typed_config:
  66. "@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
  67. dns_cache_config:
  68. name: dynamic_forward_proxy_cache_config
  69. dns_lookup_family: V4_ONLY
  70. typed_dns_resolver_config:
  71. name: envoy.network.dns_resolver.cares
  72. typed_config:
  73. "@type": type.googleapis.com/envoy.extensions.network.dns_resolver.cares.v3.CaresDnsResolverConfig
  74. resolvers:
  75. - socket_address:
  76. address: "8.8.8.8"
  77. port_value: 53
  78. dns_resolver_options:
  79. use_tcp_for_dns_lookups: true
  80. no_default_search_domain: true
  81. transport_socket:
  82. name: envoy.transport_sockets.tls
  83. typed_config:
  84. "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
  85. common_tls_context:
  86. validation_context:
  87. trusted_ca: {filename: /etc/ssl/certs/ca-certificates.crt}

Above example is using typed config CaresDnsResolverConfig. To use AppleDnsResolverConfig (iOS/macOS only), follow below example:

  1. typed_dns_resolver_config:
  2. name: envoy.network.dns_resolver.apple
  3. typed_config:
  4. "@type": type.googleapis.com/envoy.extensions.network.dns_resolver.apple.v3.AppleDnsResolverConfig

Statistics

The dynamic forward proxy DNS cache outputs statistics in the dns_cache.<dns_cache_name>.* namespace.

Name

Type

Description

dns_query_attempt

Counter

Number of DNS query attempts.

dns_query_success

Counter

Number of DNS query successes.

dns_query_failure

Counter

Number of DNS query failures.

dns_query_timeout

Counter

Number of DNS query timeouts.

host_address_changed

Counter

Number of DNS queries that resulted in a host address change.

host_added

Counter

Number of hosts that have been added to the cache.

host_removed

Counter

Number of hosts that have been removed from the cache.

num_hosts

Gauge

Number of hosts that are currently in the cache.

dns_rq_pending_overflow

Counter

Number of dns pending request overflow.

The dynamic forward proxy DNS cache circuit breakers outputs statistics in the dns_cache.<dns_cache_name>.circuit_breakers* namespace.

Name

Type

Description

rq_pending_open

Gauge

Whether the requests circuit breaker is closed (0) or open (1)

rq_pending_remaining

Gauge

Number of remaining requests until the circuit breaker opens