Skip to content

feat: support listenerset policy attach in security policy - #9270

Merged
kkk777-7 merged 11 commits into
envoyproxy:mainfrom
kkk777-7:feat-stp-ls-attach
Jul 3, 2026
Merged

kkk777-7 merged 11 commits into
envoyproxy:mainfrom
kkk777-7:feat-stp-ls-attach

Conversation

@kkk777-7

@kkk777-7 kkk777-7 commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

What this PR does / why we need it:

Support policy attachment for ListenerSet.

This PR includes:

  • Policy attachment to ListenerSet and ListenerSet sections
  • Route policy attachment when a route has a ListenerSet parent
  • Route override/merge logic that accounts for ListenerSet scopes

currently, don't support mergeType for ListenerSet. only support for xRoute.

Which issue(s) this PR fixes:

Fixes #8092 (needs follow up PRs for another policies)

Release Notes: Yes

@netlify

netlify Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

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

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

@kkk777-7 kkk777-7 changed the title Feat stp ls attach feat: support listenerset policy attach in security policy Jun 22, 2026
@codecov

codecov Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.11111% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.32%. Comparing base (f8f0370) to head (90e00bd).

Files with missing lines Patch % Lines
internal/gatewayapi/securitypolicy.go 89.21% 20 Missing and 13 partials ⚠️
internal/gatewayapi/helpers.go 96.51% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9270      +/-   ##
==========================================
+ Coverage   75.19%   75.32%   +0.13%     
==========================================
  Files         252      252              
  Lines       41093    41434     +341     
==========================================
+ Hits        30900    31212     +312     
- Misses       8090     8110      +20     
- Partials     2103     2112       +9     

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

@kkk777-7
kkk777-7 force-pushed the feat-stp-ls-attach branch from 116c8a3 to fc7411a Compare June 22, 2026 13:43
kkk777-7 added 3 commits June 23, 2026 11:23
Signed-off-by: kkk777-7 <[email protected]>
Signed-off-by: kkk777-7 <[email protected]>
@kkk777-7
kkk777-7 force-pushed the feat-stp-ls-attach branch from 0dee788 to 47f3548 Compare June 23, 2026 02:24
Signed-off-by: kkk777-7 <[email protected]>
@kkk777-7
kkk777-7 marked this pull request as ready for review June 23, 2026 03:57
@kkk777-7
kkk777-7 requested a review from a team as a code owner June 23, 2026 03:57
@kkk777-7

Copy link
Copy Markdown
Member Author

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

ℹ️ 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 release-notes/current.yaml Resolved
overrides.RegisterListenerSet(parentNN, parentGwNN)

// Register section name to Gateway index for efficient lookup when retrieving overridden and merged targets
if _, ok := gatewayRouteMap.SectionIndex[mapKey.NamespacedName]; !ok {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this building map logic moves policyGraph's Add method.

// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, ref.group == 'gateway.networking.k8s.io') : true ", message="this policy can only have a targetRefs[*].group of gateway.networking.k8s.io"
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, ref.kind in ['Gateway', 'HTTPRoute', 'GRPCRoute', 'TCPRoute']) : true ", message="this policy can only have a targetRefs[*].kind of Gateway/HTTPRoute/GRPCRoute/TCPRoute"
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, ref.kind in ['Gateway', 'ListenerSet', 'HTTPRoute', 'GRPCRoute', 'TCPRoute']) : true ", message="this policy can only have a targetRefs[*].kind of Gateway/ListenerSet/HTTPRoute/GRPCRoute/TCPRoute"
// +kubebuilder:validation:XValidation:rule="!has(self.mergeType) || ((!has(self.targetRef) || self.targetRef.kind in ['HTTPRoute', 'GRPCRoute', 'TCPRoute']) && (!has(self.targetRefs) || self.targetRefs.all(ref, ref.kind in ['HTTPRoute', 'GRPCRoute', 'TCPRoute'])) && (!has(self.targetSelectors) || self.targetSelectors.all(sel, sel.kind in ['HTTPRoute', 'GRPCRoute', 'TCPRoute'])))", message="mergeType can only be used with xRoute targets"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Add cel validation for mergeType.
Users who had set mergeType on a Policy targeting a Gateway will no longer be able to configure it. However, since we had already documented that mergeType is intended only for Route targets, I think this validation can be added without issue.

Signed-off-by: kkk777-7 <[email protected]>
@kkk777-7

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: e0e5363dbe

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

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

Adds first-class ListenerSet targeting support to SecurityPolicy, including precedence/override semantics and route policy behavior when routes attach via ListenerSet. This extends the policy-attachment surface area in internal/gatewayapi and tightens admission validation around mergeType.

Changes:

  • Allow SecurityPolicy targetRef(s) to reference ListenerSet (and sectionName within a ListenerSet) and implement attachment/override logic in the Gateway API translator.
  • Extend route policy processing to correctly resolve parents/ancestors and merge behavior when a route is attached through a ListenerSet.
  • Add/refresh CEL validation tests, e2e coverage, docs, generated CRDs/helm outputs, and release notes for the new targeting and stricter mergeType constraints.

Reviewed changes

Copilot reviewed 28 out of 30 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml Updates rendered CRD output to allow ListenerSet targets and adds mergeType xRoute-only validation.
test/helm/gateway-crds-helm/e2e.out.yaml Same CRD output updates for e2e helm snapshot.
test/helm/gateway-crds-helm/all.out.yaml Same CRD output updates for combined helm snapshot.
test/e2e/tests/utils.go Adds an e2e helper to wait for Overridden=True on SecurityPolicy ancestors.
test/e2e/tests/securitypolicy_listenerset.go New e2e conformance test covering ListenerSet-targeted policies and ListenerSet-attached routes.
test/e2e/testdata/securitypolicy-listenerset.yaml New e2e manifests exercising ListenerSet policy attachment, route attachment, and merge behavior.
test/cel-validation/securitypolicy_test.go Extends CEL admission tests for ListenerSet targets and mergeType xRoute-only restrictions.
site/content/en/latest/concepts/gateway_api_extensions/security-policy.md Documents ListenerSet targeting semantics, precedence, and merge hierarchy with ListenerSets.
site/content/en/latest/api/extension_types.md Updates generated API reference to list ListenerSet as a supported target and reflects mergeType constraints.
release-notes/current.yaml Adds breaking-change note for stricter mergeType validation and a new-feature note for ListenerSet targets.
internal/gatewayapi/validate.go Adds validation for ListenerSet listener sectionName existence.
internal/gatewayapi/testdata/tcproute-securitypolicy-with-authorization-client-cidr.out.yaml Updates expected status message formatting to include fully-qualified “gateway listeners” wording.
internal/gatewayapi/testdata/securitypolicy-route-listenerset.out.yaml New golden output covering route policy status/IR when route attaches via ListenerSet.
internal/gatewayapi/testdata/securitypolicy-route-listenerset.in.yaml New input for the ListenerSet-attached-route SecurityPolicy scenario.
internal/gatewayapi/testdata/securitypolicy-override-replace.out.yaml Updates expected overridden message formatting (“gateway listeners: ...”).
internal/gatewayapi/testdata/securitypolicy-listenerset.out.yaml New golden output covering ListenerSet-targeted policies.
internal/gatewayapi/testdata/securitypolicy-listenerset.in.yaml New input for ListenerSet-targeted SecurityPolicy tests.
internal/gatewayapi/testdata/securitypolicy-listenerset-same-name-listeners.out.yaml New golden output for same-name listener disambiguation across Gateway vs ListenerSet.
internal/gatewayapi/testdata/securitypolicy-listenerset-same-name-listeners.in.yaml New input for same-name listener disambiguation scenario.
internal/gatewayapi/testdata/securitypolicy-listenerset-merge.out.yaml New golden output for merge behavior when routes attach through ListenerSets.
internal/gatewayapi/testdata/securitypolicy-listenerset-merge.in.yaml New input for ListenerSet-aware merge behavior.
internal/gatewayapi/testdata/securitypolicy-listenerset-invalid.out.yaml New golden output for invalid/conflicting ListenerSet SecurityPolicy targeting cases.
internal/gatewayapi/testdata/securitypolicy-listenerset-invalid.in.yaml New input for invalid/conflicting ListenerSet targeting cases.
internal/gatewayapi/securitypolicy.go Implements ListenerSet policy targeting, route-parent resolution via ListenerSet, and override/merge tracking via scope graph.
internal/gatewayapi/securitypolicy_test.go Updates unit tests to use new ListenerSet-aware route processing signature.
internal/gatewayapi/helpers.go Introduces ListenerSet policy target context, policy-scope graph helpers, and ListenerSet targeting predicates.
internal/gatewayapi/helpers_test.go Adds unit coverage for the new policy-scope graph traversal behavior.
charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_securitypolicies.yaml Updates generated CRD to allow ListenerSet and enforce mergeType xRoute-only usage.
charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_securitypolicies.yaml Same CRD updates for the CRDs helm chart template.
api/v1alpha1/securitypolicy_types.go Updates API type docs/validations to include ListenerSet targets and mergeType xRoute-only validation.

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

Comment thread api/v1alpha1/securitypolicy_types.go Resolved
Comment thread internal/gatewayapi/securitypolicy.go Resolved
Comment thread internal/gatewayapi/securitypolicy.go Resolved
@kkk777-7

Copy link
Copy Markdown
Member Author

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

ℹ️ 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 release-notes/current.yaml Resolved
Signed-off-by: kkk777-7 <[email protected]>
zhaohuabing
zhaohuabing previously approved these changes Jun 29, 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. Love the clean solution!

@zhaohuabing zhaohuabing added this to the v1.9.0-rc.1 Release milestone Jun 29, 2026
@zhaohuabing
zhaohuabing requested a review from a team July 1, 2026 13:32
zirain
zirain previously approved these changes Jul 2, 2026
@kkk777-7
kkk777-7 dismissed stale reviews from zirain and zhaohuabing via 90e00bd July 2, 2026 14:52
@zirain

zirain commented Jul 2, 2026

Copy link
Copy Markdown
Member

/retest

@kkk777-7
kkk777-7 merged commit 2af650c into envoyproxy:main Jul 3, 2026
109 of 119 checks passed
@kkk777-7
kkk777-7 deleted the feat-stp-ls-attach branch July 3, 2026 02:58
EmileGoto added a commit to EmileGoto/gateway that referenced this pull request Jul 3, 2026
…dant test

The *p.Kind == resource.KindListenerSet block in processSecurityPolicyForRoute
now uses the same early-continue guard pattern as processBackendTrafficPolicyForRoute
and processEnvoyExtensionPolicyForRoute:
  - check parentRefCtx == nil → continue
  - check GetGateway() == nil → TargetNotFound + continue
  - append to parentRefCtxs

The securitypolicy-with-merge-listenerset-route test fixtures are removed:
PR envoyproxy#9270 already covers StrategicMerge with ListenerSet-attached routes via the
securitypolicy-listenerset-merge test (7 policy scenarios).

Signed-off-by: Emile <[email protected]>
@johnvox

johnvox commented Jul 3, 2026

Copy link
Copy Markdown

May fix #9409

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 ListenerSet as TargetRefs for xPolicies

5 participants