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. dns_resolution_config:
  47. resolvers:
  48. - socket_address:
  49. address: "8.8.8.8"
  50. port_value: 53
  51. dns_resolver_options:
  52. use_tcp_for_dns_lookups: true
  53. no_default_search_domain: true
  54. - name: envoy.filters.http.router
  55. typed_config:
  56. "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  57. clusters:
  58. - name: dynamic_forward_proxy_cluster
  59. lb_policy: CLUSTER_PROVIDED
  60. cluster_type:
  61. name: envoy.clusters.dynamic_forward_proxy
  62. typed_config:
  63. "@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
  64. dns_cache_config:
  65. name: dynamic_forward_proxy_cache_config
  66. dns_lookup_family: V4_ONLY
  67. dns_resolution_config:
  68. resolvers:
  69. - socket_address:
  70. address: "8.8.8.8"
  71. port_value: 53
  72. dns_resolver_options:
  73. use_tcp_for_dns_lookups: true
  74. no_default_search_domain: true
  75. transport_socket:
  76. name: envoy.transport_sockets.tls
  77. typed_config:
  78. "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
  79. common_tls_context:
  80. validation_context:
  81. trusted_ca: {filename: /etc/ssl/certs/ca-certificates.crt}

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