Skip to content

feat(clienttrafficpolicy): support forward_proto_config to infer x-forwarded-proto from PROXY protocol#9469

Open
Aias00 wants to merge 5 commits into
envoyproxy:mainfrom
Aias00:issue-9219-forward-proto-config
Open

feat(clienttrafficpolicy): support forward_proto_config to infer x-forwarded-proto from PROXY protocol#9469
Aias00 wants to merge 5 commits into
envoyproxy:mainfrom
Aias00:issue-9219-forward-proto-config

Conversation

@Aias00

@Aias00 Aias00 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Exposes Envoy's forward_proto_config feature in the Gateway API. When PROXY protocol is enabled on a listener, this infers the x-forwarded-proto header from the PROXY protocol destination port, so the correct scheme (http/https) is set for requests forwarded to backends.

This is useful when a Layer 4 load balancer (such as AWS NLB) terminates TLS and forwards traffic to Envoy over PROXY protocol, where Envoy would otherwise not know whether the original client request was HTTP or HTTPS.

The new field nests under proxyProtocol in ClientTrafficPolicy (since forward_proto_config reads the local address restored by the proxy_protocol listener filter):

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
spec:
  proxyProtocol:
    forwardProtoConfig:
      httpsDestinationPorts: [443, 8443]
      httpDestinationPorts: [80, 8080]
  • httpsDestinationPorts / httpDestinationPorts: lists of destination ports (each in [1, 65535]).
  • At least one of the two lists must be set (enforced via a CEL XValidation).
  • forward_proto_config is an HCM field, so it applies to HTTP listeners only; the TCP listener path carries the config but does not consume it.
  • Requires PROXY protocol to be enabled on the listener (it is, since the field nests under proxyProtocol).

Which issue(s) this PR fixes:
Fixes #9219


PR Checklist

  • Authorship & ownership: I have reviewed every change, understand how and why it works, can explain and maintain it, and take full responsibility for this PR.
  • DCO: All commits are signed off (git commit -s).
  • API agreed first: This PR contains an API change (new optional field under ClientTrafficPolicy.spec.proxyProtocol). The API has not been pre-discussed/agreed in a separate issue — opening this PR to gather API feedback; happy to split the API into its own PR if maintainers prefer.
  • Required checks pass: make generate/CRD regen, make lint (no new issues), and unit/coverage builds pass locally. Note: gen-check's helm-generate and generate-gwapi-manifests steps fail in my sandbox due to blocked chart-repo/curl network access, unrelated to this change; the EG CRD, deepcopy, and API docs were regenerated directly with controller-gen/crd-ref-docs and verified stable.
  • Tests added/updated: Added a translation golden pair (clienttrafficpolicy-proxyprotocol-forwardproto), 3 CEL validation cases (2 valid, 1 rejecting empty config), an xDS translator unit test (TestHCMForwardProtoConfig), and an e2e test asserting x-forwarded-proto: https is inferred from the PROXY protocol destination port.
  • Docs: API docs regenerated (site/content/en/latest/api/extension_types.md).
  • Release notes: Added release-notes/current/new_features/9219-forward-proto-config-clienttrafficpolicy.md.
  • Generated files committed: Ran code generation and committed the result (deepcopy, CRDs, API docs).
  • Scope & compatibility: Backward compatible — purely additive optional field. No breaking changes.
  • Codex review: TODO.
  • Copilot review: TODO.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 10, 2026 03:38
@Aias00
Aias00 requested a review from a team as a code owner July 10, 2026 03:38
@netlify

netlify Bot commented Jul 10, 2026

Copy link
Copy Markdown

Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit 3e41fd1
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6a58b96d1f660100076d1bd7
😎 Deploy Preview https://deploy-preview-9469--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.

Copilot AI 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.

Pull request overview

This PR exposes Envoy HCM’s forward_proto_config through ClientTrafficPolicy.spec.proxyProtocol.forwardProtoConfig, enabling Envoy to infer x-forwarded-proto from the PROXY protocol destination port (useful for L4 LB TLS termination scenarios).

Changes:

  • Add ForwardProtoConfig API type under ProxyProtocolSettings with CEL + per-item port validations; regenerate CRDs and API docs.
  • Translate forwardProtoConfig into IR and then into Envoy HCM ForwardProtoConfig; add unit + golden coverage.
  • Add an e2e conformance-style test and release note fragment for the new feature.

Findings (ordered by severity)

Required fixes

  • internal/gatewayapi/clienttrafficpolicy.go:810-818: buildIRForwardProtoConfig currently allocates slices unconditionally, which converts “unset” lists into empty (non-nil) slices in IR and can lead to unnecessary allocations / less-stable rendered output. Recommend only allocating when the corresponding input list is non-empty, and defensively returning nil if both lists are empty.

Optional follow-ups

  • test/e2e/testdata/forward-proto-config.yaml:113: Minor grammar in an inline comment (“on gateway namespace mode” → “in … mode”).

Reviewed changes

Copilot reviewed 12 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
api/v1alpha1/clienttrafficpolicy_types.go Adds ForwardProtoConfig API type under ProxyProtocolSettings with validations.
api/v1alpha1/zz_generated.deepcopy.go Updates generated deep-copies for the new API type.
charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_clienttrafficpolicies.yaml Regenerated CRD schema for the new field/validations (helm chart copy).
charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_clienttrafficpolicies.yaml Regenerated CRD schema for the new field/validations (crds chart copy).
site/content/en/latest/api/extension_types.md Regenerated API docs including ForwardProtoConfig.
internal/gatewayapi/clienttrafficpolicy.go Translates API forwardProtoConfig into IR.
internal/gatewayapi/testdata/clienttrafficpolicy-proxyprotocol-forwardproto.in.yaml New golden input for proxyProtocol + forwardProtoConfig.
internal/gatewayapi/testdata/clienttrafficpolicy-proxyprotocol-forwardproto.out.yaml New golden output verifying IR translation includes forwardProtoConfig.
internal/ir/xds.go Adds IR representation of ForwardProtoConfig.
internal/ir/zz_generated.deepcopy.go Updates generated deep-copies to properly copy the new nested pointer type.
internal/xds/translator/listener.go Sets Envoy HCM ForwardProtoConfig when configured in IR proxyProtocol.
internal/xds/translator/proxy_protocol_test.go Adds unit test verifying HCM forward proto config is populated as expected.
test/cel-validation/clienttrafficpolicy_test.go Adds CEL validation test cases (valid + invalid empty config).
test/e2e/testdata/forward-proto-config.yaml Adds e2e manifests to exercise forward proto inference behavior.
test/e2e/tests/forward_proto_config.go Adds e2e test asserting backend receives X-Forwarded-Proto: https.
release-notes/current/new_features/9219-forward-proto-config-clienttrafficpolicy.md Release note fragment for the new feature.
Files not reviewed (2)
  • api/v1alpha1/zz_generated.deepcopy.go: Generated file
  • internal/ir/zz_generated.deepcopy.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/gatewayapi/clienttrafficpolicy.go
Comment thread test/e2e/testdata/forward-proto-config.yaml Outdated

@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: 60ed3701a1

ℹ️ 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 test/e2e/testdata/forward-proto-config.yaml Outdated
@Aias00
Aias00 force-pushed the issue-9219-forward-proto-config branch from 60ed370 to f68cad8 Compare July 10, 2026 05:33
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.43%. Comparing base (e51b417) to head (3e41fd1).

Files with missing lines Patch % Lines
internal/gatewayapi/clienttrafficpolicy.go 88.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9469      +/-   ##
==========================================
+ Coverage   75.40%   75.43%   +0.02%     
==========================================
  Files         252      252              
  Lines       41617    41638      +21     
==========================================
+ Hits        31381    31408      +27     
+ Misses       8103     8097       -6     
  Partials     2133     2133              

☔ 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.

@zirain

zirain commented Jul 10, 2026

Copy link
Copy Markdown
Member

@codex review

@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: f68cad8236

ℹ️ 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 test/e2e/testdata/forward-proto-config.yaml
@zirain

zirain commented Jul 15, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 1ff365d1f8

ℹ️ 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 api/v1alpha1/clienttrafficpolicy_types.go Outdated
Aias00 and others added 5 commits July 16, 2026 18:58
…rwarded-proto from PROXY protocol

Add a forwardProtoConfig field to proxyProtocol in ClientTrafficPolicy that
exposes Envoy's HttpConnectionManager.forward_proto_config feature. When PROXY
protocol is enabled on a listener, this infers the x-forwarded-proto header
from the PROXY protocol destination port, so the correct scheme is set for
requests forwarded to backends.

This is useful when a Layer 4 load balancer (such as AWS NLB) terminates TLS
and forwards traffic to Envoy over PROXY protocol, where Envoy would otherwise
not know whether the original client request was HTTP or HTTPS.

The new field nests httpsDestinationPorts and httpDestinationPorts (each a list
of ports in [1, 65535]). At least one of the two lists must be set (enforced via
a CEL XValidation). forward_proto_config is an HCM field, so it applies to HTTP
listeners only.

Closes envoyproxy#9219

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: liuhy <liuhongyu@apache.org>
…nation ports

Add a CEL validation requiring httpsDestinationPorts and
httpDestinationPorts to be disjoint, so a port cannot be mapped to
both http and https. Add a CEL test covering the ambiguous case.

Signed-off-by: liuhy <liuhongyu@apache.org>
The disjoint XValidation added in 1380f1d was regenerated into the
source CRD charts (charts/.../generated/gateway.envoyproxy.io_clienttrafficpolicies.yaml)
but the test/helm/gateway-crds-helm/*.out.yaml snapshots were not
re-rendered, so they still only carried the "at least one port list"
rule. This made CI gen-check fail.

Re-render the snapshots via `make helm-template.gateway-crds-helm` so
all three (all.out.yaml, e2e.out.yaml, envoy-gateway-crds.out.yaml)
now include the "httpsDestinationPorts and httpDestinationPorts must
be disjoint" validation, matching the generated CRDs.

Signed-off-by: liuhy <liuhongyu@apache.org>
Co-authored-by: zirain <zirain2009@gmail.com>
Signed-off-by: aias00 <liuhongyu@apache.org>
Signed-off-by: liuhy <liuhongyu@apache.org>
@zirain
zirain force-pushed the issue-9219-forward-proto-config branch from f86a08f to 3e41fd1 Compare July 16, 2026 10:58

@zirain zirain 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, derfer to other maintainers for the naming.

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.

Support forward_proto_config for K8s Gateway API

3 participants