Skip to content

Conversation

yuval-k
Copy link
Contributor

@yuval-k yuval-k commented May 21, 2025

Description

Handle attachment edge cases, and allow policies to target section names.

Change Type

/kind feature

Changelog

Allow TrafficPolicy to targetRef using section name.

Additional Notes

Behavior after this PR:

  • Route policies never attach to the envoy-listener (i.e. filters on the listener are disabled; so that without a per-filter route config they do nothing
  • Route Policies that target ref a gateway will go on the route configuration
  • Route policies that target a section will go on:
    • for http - on the virtual host
    • for https - on the route configuration

Main implication is that HCM plugins can't attach to http plain text listeners by section name, because the http filter chain is shared. (But does work on tls).
Option to address this is to remove section name from the http listener policy.

Additional changes

  • Updated traffic policy to place filters on the specific filter chain.
  • Made getTargetingPolicies to not return policies without a section name when a section name is requested. instead we use envoy's hierarchy to get the same data plane behaviour.

updated outputs to what i think is the correct output (not current output)
current failing:
- for section name http1, the config needs to be disabled on the listener and enabled on the virtualHost.
- section-name-gw-extauth should not be present on tls2 filter chain

Signed-off-by: Yuval Kohavi <[email protected]>
@github-actions github-actions bot added do-not-merge/kind-invalid Indicates a PR lacks a `kind/foo` label and requires one. release-note kind/feature Categorizes issue or PR as related to a new feature. and removed do-not-merge/kind-invalid Indicates a PR lacks a `kind/foo` label and requires one. labels May 21, 2025
yuval-k added 3 commits May 21, 2025 19:16
Signed-off-by: Yuval Kohavi <[email protected]>
Signed-off-by: Yuval Kohavi <[email protected]>
Signed-off-by: Yuval Kohavi <[email protected]>
@yuval-k yuval-k marked this pull request as ready for review May 22, 2025 00:03
@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 00:03
Copy link
Contributor

@Copilot Copilot AI left a comment

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 adds edge-case tests for ext-auth policies and enhances policy targeting by introducing section names, updating how filters are attached per filter chain.

  • Add a new test entry for TrafficPolicy edge cases in gateway translator tests
  • Extend data structures and logic to carry and match SectionName for policy attachments
  • Refactor trafficPolicyPluginGwPass to track per-filter-chain state and disable/enable filters accordingly

Reviewed Changes

Copilot reviewed 55 out of 55 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/kgateway/translator/gateway/gateway_translator_test.go Added table entry for TrafficPolicy edge cases
internal/kgateway/setup/testdata/standard/*.yaml Updated expected YAML to include disabled: true and typedPerFilterConfig per chain
internal/kgateway/query/httproute.go Extended UniqueRouteName to accept an optional ruleName
internal/kgateway/krtcollections/policy.go Incorporated SectionName in targetRefs indexing and lookup
internal/kgateway/extensions2/pluginutils/policy.go Propagate SectionName into IR conversion
internal/kgateway/extensions2/plugins/trafficpolicy/traffic_policy_plugin.go Refactored to use maps keyed by filter-chain and track per-chain provider state
internal/kgateway/extensions2/plugins/trafficpolicy/extauth_policy_test.go Updated tests to supply FilterChainName context
install/helm/kgateway-crds/templates/*.yaml Added sectionName field in CRD schemas
api/v1alpha1/*.go Added SectionName to API types and updated deep copy methods
api/applyconfiguration/*.go Added SectionName in apply configurations
Comments suppressed due to low confidence (3)

internal/kgateway/extensions2/plugins/trafficpolicy/traffic_policy_plugin.go:261

  • [nitpick] The name ProviderNeededMap is generic. Consider renaming it to something more descriptive, e.g. FilterChainProviderMap, to clarify its purpose.
type ProviderNeededMap struct {

internal/kgateway/extensions2/plugins/trafficpolicy/traffic_policy_plugin.go:507

  • [nitpick] The plugin name returned is routepolicies but this extension now handles a broader traffic policy. Consider updating it to trafficpolicies to reflect its intent and avoid confusion.
func (p *TrafficPolicy) Name() string {

internal/kgateway/query/httproute.go:103

  • The signature of UniqueRouteName now takes an extra ruleName argument. Consider adding unit tests for when ruleName is non-empty to cover the new branch.
func (r *RouteInfo) UniqueRouteName(ruleIdx, matchIdx int, ruleName string) string {

yuval-k added 2 commits May 21, 2025 20:28
yaml updates

Signed-off-by: Yuval Kohavi <[email protected]>
Signed-off-by: Yuval Kohavi <[email protected]>
@yuval-k yuval-k added the work in progress Indicates that a PR should not merge because it is a work in progress label May 22, 2025
@yuval-k
Copy link
Contributor Author

yuval-k commented May 22, 2025

i noticed some multi listener tests are flakey due to ordering; i'll fix that; but otherwise ready for review

Signed-off-by: Yuval Kohavi <[email protected]>
@yuval-k yuval-k removed the work in progress Indicates that a PR should not merge because it is a work in progress label May 22, 2025
Copy link
Contributor

@lgadban lgadban left a comment

Choose a reason for hiding this comment

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

code review is WIP but can you we change the PR title to reflect there are actual functional changes (i.e. it's not just tests) and also i think the PR description is slightly out of order or unintentional

@yuval-k yuval-k changed the title Add ext-auth edge cases test case feat: support section name in policies, and add tests for all attachment types. May 22, 2025
Comment on lines 41 to 44
attachedPoliciesSlice := []ir.AttachedPolicies{
h.gw.AttachedHttpPolicies,
h.attachedPolicies,
}
Copy link
Contributor

@shashankram shashankram May 22, 2025

Choose a reason for hiding this comment

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

Could you pre-merge the policies per GK here so that it is easier to invoke a Merge() on them within the loop

	attachedPolicies := ir.AttachedPolicies{
		Policies: map[schema.GroupKind][]ir.PolicyAtt{},
	}
       attachedHttpPolicies.Append(h.gw.AttachedHttpPolicies, h.attachedPolicies)

// TODO: user error - they attached a non http policy
continue
}
for _, pol := range pols {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to MergePolicies when pass.MergePolicies != nil?

yuval-k added 6 commits May 22, 2025 10:49
Signed-off-by: Yuval Kohavi <[email protected]>
Signed-off-by: Yuval Kohavi <[email protected]>
Signed-off-by: Yuval Kohavi <[email protected]>
…is if we like these merge semantics

Signed-off-by: Yuval Kohavi <[email protected]>
Signed-off-by: Yuval Kohavi <[email protected]>
@yuval-k yuval-k enabled auto-merge May 22, 2025 16:47
@yuval-k yuval-k added this pull request to the merge queue May 22, 2025
Signed-off-by: Yuval Kohavi <[email protected]>
@yuval-k yuval-k removed this pull request from the merge queue due to a manual request May 22, 2025
@yuval-k yuval-k added this pull request to the merge queue May 22, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 22, 2025
@lgadban lgadban linked an issue May 22, 2025 that may be closed by this pull request
@yuval-k yuval-k added this pull request to the merge queue May 22, 2025
Merged via the queue into main with commit 65aa255 May 22, 2025
20 checks passed
@yuval-k yuval-k deleted the yuval-k/ext-auth-edge-cases branch May 22, 2025 19:15
MayorFaj pushed a commit to MayorFaj/kgateway that referenced this pull request May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support sectionName with TrafficPolicy
3 participants