Skip to content

feat: policy field owner#8538

Open
kkk777-7 wants to merge 4 commits intoenvoyproxy:mainfrom
kkk777-7:fix-merge-policy-ref
Open

feat: policy field owner#8538
kkk777-7 wants to merge 4 commits intoenvoyproxy:mainfrom
kkk777-7:fix-merge-policy-ref

Conversation

@kkk777-7
Copy link
Copy Markdown
Member

@kkk777-7 kkk777-7 commented Mar 17, 2026

What this PR does / why we need it:
follow up #7918

introduce PolicyFieldOwners to fixes below issues when parent/route Policy merge

  • handle LocalObjectReference/BackendRef correctly
  • handle IR Config name correctly

Which issue(s) this PR fixes:

Fixes #

Release Notes: No

Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 17, 2026

Deploy Preview for cerulean-figolla-1f9435 ready!

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

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 87.02290% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.21%. Comparing base (efa9021) to head (d1df896).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
internal/gatewayapi/securitypolicy.go 86.40% 8 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8538      +/-   ##
==========================================
+ Coverage   74.16%   74.21%   +0.04%     
==========================================
  Files         242      242              
  Lines       37624    37708      +84     
==========================================
+ Hits        27903    27984      +81     
+ Misses       7773     7771       -2     
- Partials     1948     1953       +5     

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

- port: 9001
name: http
protocol: TCP
referenceGrants:
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 PR fixes unnecessary refGrant.

Gateway Policy (ns/envoy-gateway) has extAuth setting and auth-service exist in envoy-gateway.

Previously, during the merge, it was treated as spec of route policy, which meant that references from different namespaces.

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.

Nice!

type: Opaque
data:
.htpasswd: dXNlcjE6e1NIQX15LzJzWUFqNXlyUUlONFRMMFlkUGRtR05LcGM9
- apiVersion: v1
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 PR fixes unnecessary secret in Route ns.

@kkk777-7 kkk777-7 force-pushed the fix-merge-policy-ref branch from 233556d to 3a7dc97 Compare March 17, 2026 16:54
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
@kkk777-7 kkk777-7 force-pushed the fix-merge-policy-ref branch from 3a7dc97 to c9abe3a Compare March 17, 2026 17:06
prefix: /foo
security:
basicAuth:
name: securitypolicy/envoy-gateway/policy-for-gateway
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.

merge policy can resolve parent policy's auth ref and generate IR name correctly.

grpc:
authority: grpc-backend.envoy-gateway:9000
destination:
metadata:
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.

merge policy can resolve parent policy's ext auth backendRef and generate IR name correctly.

cookieSuffix: 811c9dc5
hmacSecret: '[redacted]'
logoutPath: /logout
name: securitypolicy/envoy-gateway/policy-for-gateway
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.

merge policy can resolve parent policy's oidc refs and generate IR name correctly.

Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
@kkk777-7 kkk777-7 marked this pull request as ready for review March 18, 2026 06:36
@kkk777-7 kkk777-7 requested a review from a team as a code owner March 18, 2026 06:36
@kkk777-7 kkk777-7 added this to the v1.8.0-rc.1 Release milestone Mar 18, 2026

if contextExtensions, err = t.buildContextExtensions(policy.Spec.ExtAuth.ContextExtensions, policy.Namespace); err != nil {
ownerPolicy := resolvePolicyFieldOwner(fieldOwners, spFieldExtAuthContextExtensions, policy)
if contextExtensions, err = t.buildContextExtensions(policy.Spec.ExtAuth.ContextExtensions, ownerPolicy.Namespace); err != nil {
Copy link
Copy Markdown
Member

@zhaohuabing zhaohuabing Mar 19, 2026

Choose a reason for hiding this comment

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

We'll need a per-entry owner map for ContextExtensions. It may contain ContextExtension valueRefs from different namespaces after merging.

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.

thanks for comment :)

Yes, while checking the CRD markers, I initially thought the same thing as your comment.
https://github.com/envoyproxy/gateway/blob/main/api/v1alpha1/ext_auth_types.go#L73-L78

But, while adding SecurityPolicy to tests for the policy merge function, I confirmed that ContextExtensions is merged by replacing the entire array.
(add test file utils/testdata/securitypolicy_all in this PR)

Let me know if I missing sometheing. Or is the entire-array replacement a separate issue?

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.

On second thought, full-array replacement might be the correct behavior, since this is part of ExtAuth.

cc @maxbrunet

@arkodg arkodg requested a review from rudrakhp March 19, 2026 07:04
routePolicy *egv1a1.SecurityPolicy,
parentPolicy *egv1a1.SecurityPolicy,
) PolicyFieldOwners[*egv1a1.SecurityPolicy] {
// Route policy owners are applied last so they override parent owners when both define the same field key.
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.

Isn't it possible that some of the resources under a path that is a list might belong to route while some others might belong to parent? For example if Spec.JWT.Providers are merged from both route and parent who will be the owner of this field?

Copy link
Copy Markdown
Member Author

@kkk777-7 kkk777-7 Mar 19, 2026

Choose a reason for hiding this comment

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

thanks, that’s a good point.

I had the same concern, so I checked how merging behaves in SP (utils/testdata/securitypolicy_all in this PR).
I confirmed that all list fields are merged by replacing the entire array.

If we will add any list field that is not merged via full-array replacement, we would need a per-entry ownership map.

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.

Full-array replacement within an auth method seems the right default for me. Merging inner properties across different levels is error-prone, as the fields are often interrelated and shouldn’t be merged implicitly.

@zhaohuabing zhaohuabing requested a review from a team March 24, 2026 02:09
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.

3 participants