Skip to content

feat(xds): support SNI based dynamic forward proxy for TLSRoute - #9184

Merged
zhaohuabing merged 4 commits into
envoyproxy:mainfrom
andreademurtas:feat/8787-sni-dynamic-forward-proxy
Jul 25, 2026
Merged

zhaohuabing merged 4 commits into
envoyproxy:mainfrom
andreademurtas:feat/8787-sni-dynamic-forward-proxy

Conversation

@andreademurtas

Copy link
Copy Markdown
Contributor

What type of PR is this?

feat(xds)

What this PR does / why we need it:

Envoy supports SNI based dynamic forward proxy through the combination of the tls_inspector listener filter, the sni_dynamic_forward_proxy network filter and the dynamic forward proxy cluster. Until now this could not be configured with Envoy Gateway because a Backend of type DynamicResolver could only be used by an HTTPRoute, not by a TLSRoute.

This PR allows a DynamicResolver Backend to be referenced by a TLSRoute, so Envoy Gateway can act as an SNI based dynamic forward proxy. The upstream host is resolved from the TLS SNI of the incoming connection and the raw TLS bytes are forwarded unchanged (passthrough).

Example:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TLSRoute
metadata:
  name: sni-dynamic-forward-proxy
spec:
  parentRefs:
    - name: eg
  hostnames:
    - "foo.example.com"
  rules:
    - backendRefs:
        - group: gateway.envoyproxy.io
          kind: Backend
          name: backend-dynamic-resolver
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
  name: backend-dynamic-resolver
spec:
  type: DynamicResolver

Implementation details:

  • Add the envoy.filters.network.sni_dynamic_forward_proxy network filter to the TCP filter chain of dynamic resolver routes, sharing the same DNS cache as the dynamic forward proxy cluster. The upstream port is fixed at 443, the conventional port for SNI based forwarding.
  • Ensure the tls_inspector listener filter is present so the SNI is available to the filter.
  • Deny loopback SNIs (for example localhost, 127.0.0.1, ::1) with a network RBAC filter to mitigate SSRF against the proxy's own loopback interface, mirroring the loopback protection already applied to the HTTP dynamic forward proxy.
  • Reject a dynamic resolver combined with multiple backendRefs on a TLSRoute, consistent with the existing behavior for HTTPRoute.

No API changes are included.

Testing:

  • Gateway API translation golden tests for the happy path and for the rejected multi-backendRef case (internal/gatewayapi/testdata/tlsroute-dynamic-resolver*.yaml).
  • xDS translation golden tests asserting the generated listener (tls_inspector + loopback RBAC + sni_dynamic_forward_proxy + tcp_proxy) and the dynamic forward proxy cluster with a matching DNS cache (internal/xds/translator/testdata/.../tls-route-dynamic-resolver.*).

Which issue(s) this PR fixes:

Fixes #8787

Release Notes: Yes

Allow a Backend of type DynamicResolver to be referenced by a TLSRoute so
Envoy Gateway can act as an SNI based dynamic forward proxy. The upstream
host is resolved from the TLS SNI of the incoming connection and the raw TLS
bytes are forwarded unchanged (passthrough).

- Add the envoy.filters.network.sni_dynamic_forward_proxy network filter to
  the TCP filter chain of dynamic resolver routes, sharing the same DNS cache
  as the dynamic forward proxy cluster (fixed upstream port 443).
- Ensure the tls_inspector listener filter is present so the SNI is available.
- Deny loopback SNIs with a network RBAC filter to mitigate SSRF, mirroring
  the loopback protection of the HTTP dynamic forward proxy.
- Reject a dynamic resolver combined with multiple backendRefs on a TLSRoute.

Fixes envoyproxy#8787

Signed-off-by: Andrea De Murtas <[email protected]>
@andreademurtas
andreademurtas requested a review from a team as a code owner June 6, 2026 02:03
@netlify

netlify Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit 909c040
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6a52cb0a385d0900084e67fb
😎 Deploy Preview https://deploy-preview-9184--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ef38b568c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/xds/translator/listener.go Resolved
@codecov

codecov Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.37%. Comparing base (76bd888) to head (909c040).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/xds/translator/listener.go 50.00% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9184      +/-   ##
==========================================
+ Coverage   75.29%   75.37%   +0.08%     
==========================================
  Files         252      253       +1     
  Lines       41564    41642      +78     
==========================================
+ Hits        31295    31389      +94     
+ Misses       8142     8123      -19     
- Partials     2127     2130       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

A dynamic resolver backend forwards the connection based on the SNI and
requires TLS passthrough. When the parent listener terminates TLS, Envoy
consumes the downstream handshake before tcp_proxy and would forward the
decrypted stream to the SNI host on port 443, breaking the intended
passthrough forwarding.

Reject a dynamic resolver backend on a TLS terminate listener during
translation (ResolvedRefs=False) and gate the SNI dynamic forward proxy
filter to passthrough routes only.

Addresses review feedback on envoyproxy#8787.

Signed-off-by: Andrea De Murtas <[email protected]>
@arkodg arkodg added this to the v1.9.0-rc.1 Release milestone Jun 8, 2026
@arkodg
arkodg requested review from guydc and zhaohuabing June 8, 2026 02:02
@zhaohuabing

Copy link
Copy Markdown
Member

@andreademurtas, thanks for the contribution! The PR looks good.

Could you please add an e2e test covering TLSRoute with DFP backends?

Add an end-to-end test verifying that a TLSRoute referencing a DynamicResolver
backend forwards based on the SNI. A dedicated TLS passthrough backend serves a
self-signed certificate whose SAN matches its in-cluster FQDN, so the SNI used
to route also resolves the upstream and is validated by the client.

Signed-off-by: Andrea De Murtas <[email protected]>
@andreademurtas

Copy link
Copy Markdown
Contributor Author

Thanks @zhaohuabing! Added in d4fb58f: a new e2e test (TLSRouteDynamicResolverBackend) routing a TLSRoute to a DynamicResolver backend over TLS passthrough. A dedicated TLS backend serves a self-signed cert whose SAN matches its in-cluster FQDN, so the SNI used to route also resolves the upstream and is validated by the client.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions!

@github-actions github-actions Bot added the stale label Jul 10, 2026

@arkodg arkodg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

@arkodg
arkodg requested review from a team July 12, 2026 02:13
@github-actions github-actions Bot removed the stale label Jul 12, 2026

@zhaohuabing zhaohuabing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

zhaohuabing

This comment was marked as duplicate.

@zhaohuabing
zhaohuabing merged commit fb89033 into envoyproxy:main Jul 25, 2026
65 of 67 checks passed
arkodg pushed a commit that referenced this pull request Jul 26, 2026
…9582)

The tls-secret-1 added in #9184 for
tlsroute-dynamic-resolver-with-tls-terminate.in.yaml carries a tls.key
that does not match its tls.crt, so the secret fails validation:

  No valid secrets exist: envoy-gateway/tls-secret-1 must contain a
  matching tls.crt and tls.key: tls: private key does not match public key.

As a result the listener is never programmed, it is dropped from both
infraIR and xdsIR, and the TLSRoute reports ResolvedRefs=True instead of
the intended "Dynamic resolver backend is only supported with TLS
passthrough listeners" error. The test therefore no longer exercises the
dynamic resolver + TLS terminate path it was written for, and gen-check
fails on main because the committed .out.yaml does not match what the
translator now produces.

Replace tls.key with the key that actually matches tls.crt, the same one
used by the other 24 testdata files sharing this certificate. The
committed .out.yaml is correct as-is and is left unchanged.

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
muwaqar-cflt added a commit to muwaqar/gateway that referenced this pull request Jul 27, 2026
…envoyproxy#9184/envoyproxy#9030 SDS changes

main's new TLSRoute dynamic-resolver support referenced a destSettings
variable that doesn't exist on this branch, which renamed it to
allDs/backendClusterRefs earlier in this branch's own history. git's 3-way
merge combined the two without a textual conflict, silently producing
code that failed to compile. Adapt the check to use allDs (a dynamic
resolver is never merge-eligible, so it can only appear there) while
counting both allDs and backendClusterRefs for the single-destination
requirement.

Signed-off-by: Muhammad Waqar <[email protected]>
muwaqar-cflt added a commit to muwaqar/gateway that referenced this pull request Jul 29, 2026
…envoyproxy#9184/envoyproxy#9030 SDS changes

main's new TLSRoute dynamic-resolver support referenced a destSettings
variable that doesn't exist on this branch, which renamed it to
allDs/backendClusterRefs earlier in this branch's own history. git's 3-way
merge combined the two without a textual conflict, silently producing
code that failed to compile. Adapt the check to use allDs (a dynamic
resolver is never merge-eligible, so it can only appear there) while
counting both allDs and backendClusterRefs for the single-destination
requirement.

Signed-off-by: Muhammad Waqar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SNI based dynamic forward proxy support

3 participants