Skip to content

fix(gatewayapi): prefer sectioned BackendTLSPolicy over wildcard for same target#9068

Open
AlecDiraimondo wants to merge 5 commits into
envoyproxy:mainfrom
AlecDiraimondo:fix/backendtlspolicy-sectioned-precedence
Open

fix(gatewayapi): prefer sectioned BackendTLSPolicy over wildcard for same target#9068
AlecDiraimondo wants to merge 5 commits into
envoyproxy:mainfrom
AlecDiraimondo:fix/backendtlspolicy-sectioned-precedence

Conversation

@AlecDiraimondo
Copy link
Copy Markdown

@AlecDiraimondo AlecDiraimondo commented May 22, 2026

What this PR does / why we need it

This PR makes getBackendTLSPolicy prefer policies with an explicit sectionName match before falling back to wildcard matches. The pattern mirrors the specificity ordering SecurityPolicy implements, for example.

Currently, when two BackendTLSPolicies target the same backend — one with sectionName set, one without — the wildcard policy wins whenever it sorts earlier, since policies are iterated in creationTimestamp order with no specificity preference. The sectioned policy is silently dropped: never selected by the translator, no status written.

The Gateway API BackendTLSPolicy spec states precedence checks should happen at matching sectionName and target. This is slightly up for interpretation, but honoring the more specific match seems to be the more idiomatic approach.

The existing conformity test for gatewayAPI passes https://github.com/kubernetes-sigs/gateway-api/blob/3e4ef89ce6d9a21202275739566d7c649211620c/conformance/tests/backendtlspolicy-conflict-resolution.go#L117-L152 due to the sectioned backendTLSPolicy being created first

The included testdata case (backendtlspolicy-wildcard-older-than-sectioned) demonstrates this case, and the golden config shows the corrected behavior:

  • policy-sectioned.status.ancestors now populates with Accepted: True (was null).
  • Port-8080 route's sni flips from wildcard.example.comsectioned.example.com.
  • Port-8081 route unchanged (wildcard still applies where no sectioned policy claims).

Which issue(s) this PR fixes

Fixes #9035

@AlecDiraimondo AlecDiraimondo requested a review from a team as a code owner May 22, 2026 17:23
@netlify
Copy link
Copy Markdown

netlify Bot commented May 22, 2026

Deploy Preview for cerulean-figolla-1f9435 ready!

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

Copy link
Copy Markdown

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

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: e23c272bf6

ℹ️ 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/gatewayapi/backendtlspolicy.go
…Policy

Signed-off-by: AlecDiraimondo <50001153+AlecDiraimondo@users.noreply.github.com>
…same target

When two BackendTLSPolicies target the same backend — one with sectionName
set, one without — the wildcard wins whenever it sorts earlier, since
policies are iterated in creationTimestamp order with no specificity
preference. The sectioned policy is silently dropped: never selected by
the translator, no status written.

Make getBackendTLSPolicy prefer policies with an explicit sectionName
match before falling back to wildcard matches. Matches the specificity
ordering SecurityPolicy already implements.

Refs envoyproxy#9035

Signed-off-by: AlecDiraimondo <50001153+AlecDiraimondo@users.noreply.github.com>
@AlecDiraimondo AlecDiraimondo force-pushed the fix/backendtlspolicy-sectioned-precedence branch from 1ff61c0 to e5cfd08 Compare May 22, 2026 20:33
@zirain
Copy link
Copy Markdown
Member

zirain commented May 23, 2026

@codex

@chatgpt-codex-connector
Copy link
Copy Markdown

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

ℹ️ 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".

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.76%. Comparing base (42eba71) to head (b40c2f2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9068   +/-   ##
=======================================
  Coverage   74.76%   74.76%           
=======================================
  Files         252      252           
  Lines       40571    40584   +13     
=======================================
+ Hits        30333    30344   +11     
  Misses       8167     8167           
- Partials     2071     2073    +2     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Member

@zirain zirain left a comment

Choose a reason for hiding this comment

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

Can you add a release notes for this?

Signed-off-by: AlecDiraimondo <50001153+AlecDiraimondo@users.noreply.github.com>
zirain
zirain previously approved these changes May 24, 2026
Signed-off-by: Alec Diraimondo <drayalec@gmail.com>
@AlecDiraimondo
Copy link
Copy Markdown
Author

@zirain sorry had to rebase and dismiss review. Also how do I rerun the ci-checks? Was unable to find the button

Copy link
Copy Markdown
Member

@rudrakhp rudrakhp left a comment

Choose a reason for hiding this comment

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

Minor comments

}

// stricter variant: only matches when sectionName is set and equal
func backendTLSTargetSectionMatched(policy *gwapiv1.BackendTLSPolicy, target gwapiv1.LocalPolicyTargetReferenceWithSectionName, backendNamespace string) bool {
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.

See backendTLSTargetMatched if we can dedup this

) *gwapiv1.BackendTLSPolicy {
// SectionName is port number for EG Backend object
target := t.getTargetBackendReference(backendRef, backendNamespace)
for _, policy := range policies {
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.

can we return early if target.SectionName == nil?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BackendTLSPolicy lookup does not prefer sectionName-specific match over wildcard

3 participants