Skip to content

Commit 442de3d

Browse files
authored
docs: dynamic resolver backend (#5935)
* docs for dynamic resolver backend Signed-off-by: Huabing (Robin) Zhao <[email protected]> * update docs Signed-off-by: Huabing (Robin) Zhao <[email protected]> * update docs Signed-off-by: Huabing (Robin) Zhao <[email protected]> * delete docs Signed-off-by: Huabing (Robin) Zhao <[email protected]> --------- Signed-off-by: Huabing (Robin) Zhao <[email protected]>
1 parent 756d2ef commit 442de3d

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

site/content/en/latest/tasks/traffic/backend.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ A Backend resource can be used to:
1616
- Expose a Service or Pod that should not be accessible
1717
- Reference a Service or Pod by a Route without appropriate Reference Grants
1818
- Expose the Envoy Proxy localhost (including the Envoy admin endpoint)
19+
- When configured as the `DynamicResolver` type, it can route traffic to any destination, effectively exposing all potential endpoints to clients. This can introduce security risks if not properly managed.
1920

2021
For these reasons, the Backend API is disabled by default in Envoy Gateway configuration. Envoy Gateway admins are advised to follow [upstream recommendations][] and restrict access to the Backend API using K8s RBAC.
2122

@@ -195,6 +196,103 @@ Send a request and view the response:
195196
curl -I -HHost:www.example.com http://${GATEWAY_HOST}/headers
196197
```
197198

199+
### Dynamic Forward Proxy
200+
201+
Envoy Gateway can be configured as a dynamic forward proxy using the [Backend][] API by setting its type to `DynamicResolver`.
202+
This allows Envoy Gateway to act as an HTTP proxy without needing prior knowledge of destination hostnames or IP addresses,
203+
while still maintaining its advanced routing and traffic management capabilities.
204+
205+
Under the hood, Envoy Gateway uses the Envoy [Dynamic Forward Proxy](https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/http/http_proxy)
206+
to implement this feature.
207+
208+
In the following example, we will create a `HTTPRoute` that references a `Backend` resource of type `DynamicResolver`.
209+
This setup allows Envoy Gateway to dynamically resolve the hostname in the request and forward the traffic to the original
210+
destination of the request.
211+
212+
Note: the TLS configuration in the following example is optional. It's only required if you want to use TLS to connect
213+
to the backend service. The example uses the system well-known CA certificate to validate the backend service's certificate.
214+
You can also use a custom CA certificate by specifying the `caCertificate` field in the `tls` section.
215+
216+
{{< tabpane text=true >}}
217+
{{% tab header="Apply from stdin" %}}
218+
219+
```shell
220+
cat <<EOF | kubectl apply -f -
221+
---
222+
apiVersion: gateway.networking.k8s.io/v1
223+
kind: HTTPRoute
224+
metadata:
225+
name: dynamic-forward-proxy
226+
spec:
227+
parentRefs:
228+
- name: eg
229+
rules:
230+
- backendRefs:
231+
- group: gateway.envoyproxy.io
232+
kind: Backend
233+
name: backend-dynamic-resolver
234+
---
235+
apiVersion: gateway.envoyproxy.io/v1alpha1
236+
kind: Backend
237+
metadata:
238+
name: backend-dynamic-resolver
239+
spec:
240+
type: DynamicResolver
241+
tls:
242+
wellKnownCACertificates: System
243+
EOF
244+
```
245+
246+
{{% /tab %}}
247+
{{% tab header="Apply from file" %}}
248+
Save and apply the following resources to your cluster:
249+
250+
```yaml
251+
---
252+
apiVersion: gateway.networking.k8s.io/v1
253+
kind: HTTPRoute
254+
metadata:
255+
name: dynamic-forward-proxy
256+
spec:
257+
parentRefs:
258+
- name: eg
259+
rules:
260+
- backendRefs:
261+
- group: gateway.envoyproxy.io
262+
kind: Backend
263+
name: backend-dynamic-resolver
264+
---
265+
apiVersion: gateway.envoyproxy.io/v1alpha1
266+
kind: Backend
267+
metadata:
268+
name: backend-dynamic-resolver
269+
spec:
270+
type: DynamicResolver
271+
tls:
272+
wellKnownCACertificates: System
273+
```
274+
275+
{{% /tab %}}
276+
{{< /tabpane >}}
277+
278+
Get the Gateway address:
279+
280+
```shell
281+
export GATEWAY_HOST=$(kubectl get gateway/eg -o jsonpath='{.status.addresses[0].value}')
282+
```
283+
284+
Send a request to `gateway.envoyproxy.io` and view the response:
285+
286+
```shell
287+
curl -HHost:gateway.envoyproxy.io http://${GATEWAY_HOST}
288+
```
289+
290+
You can also send a request to any other domain, and Envoy Gateway will resolve the hostname and route the traffic accordingly:
291+
292+
```shell
293+
curl -HHost:httpbin.org http://${GATEWAY_HOST}/get
294+
```
295+
198296
[Backend]: ../../../api/extension_types#backend
199297
[routing to cluster-external backends]: ./../../tasks/traffic/routing-outside-kubernetes.md
200298
[BackendObjectReference]: https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.BackendObjectReference

0 commit comments

Comments
 (0)