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. By default, this behavior is enabled by the runtime feature envoy.reloadable_features.enable_dns_cache_circuit_breakers. If this runtime feature is disabled, cluster circuit breakers will be used even when setting the configuration of DNS cache circuit breakers.

  1. admin:
  2. access_log_path: /tmp/admin_access.log
  3. address:
  4. socket_address:
  5. protocol: TCP
  6. address: 127.0.0.1
  7. port_value: 9901
  8. static_resources:
  9. listeners:
  10. - name: listener_0
  11. address:
  12. socket_address:
  13. protocol: TCP
  14. address: 0.0.0.0
  15. port_value: 10000
  16. filter_chains:
  17. - filters:
  18. - name: envoy.filters.network.http_connection_manager
  19. typed_config:
  20. "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
  21. stat_prefix: ingress_http
  22. route_config:
  23. name: local_route
  24. virtual_hosts:
  25. - name: local_service
  26. domains: ["*"]
  27. routes:
  28. - match:
  29. prefix: "/force-host-rewrite"
  30. route:
  31. cluster: dynamic_forward_proxy_cluster
  32. typed_per_filter_config:
  33. envoy.filters.http.dynamic_forward_proxy:
  34. "@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.PerRouteConfig
  35. host_rewrite_literal: www.example.org
  36. - match:
  37. prefix: "/"
  38. route:
  39. cluster: dynamic_forward_proxy_cluster
  40. http_filters:
  41. - name: envoy.filters.http.dynamic_forward_proxy
  42. typed_config:
  43. "@type": type.googleapis.com/envoy.config.filter.http.dynamic_forward_proxy.v2alpha.FilterConfig
  44. dns_cache_config:
  45. name: dynamic_forward_proxy_cache_config
  46. dns_lookup_family: V4_ONLY
  47. - name: envoy.filters.http.router
  48. typed_config:
  49. "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  50. clusters:
  51. - name: dynamic_forward_proxy_cluster
  52. connect_timeout: 1s
  53. lb_policy: CLUSTER_PROVIDED
  54. cluster_type:
  55. name: envoy.clusters.dynamic_forward_proxy
  56. typed_config:
  57. "@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
  58. dns_cache_config:
  59. name: dynamic_forward_proxy_cache_config
  60. dns_lookup_family: V4_ONLY
  61. transport_socket:
  62. name: envoy.transport_sockets.tls
  63. typed_config:
  64. "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
  65. common_tls_context:
  66. validation_context:
  67. 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.

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