Skip to content

Conversation

shashankram
Copy link
Contributor

@shashankram shashankram commented Aug 6, 2025

Description

Adds a disable field to the policies to allow disabling policies attached to Gateway/Listener at the route level as a form of opt-out mechanism.

  • ExtAuth uses the existing global_disable/ext_auth filter, though this change updates the metadata key and value for consistency.

  • ExtProc is configured using a composite filter that conditionally enables the actual ExtProc filter based on the absence of the global_disable/ext_proc filter. This allows the route plugin to simply add the global disable filter to the filter config instead of complex post-processing of routes that would be otherwise required (because vhost plugin runs after route plugin).

  • CORS implements disable capability using using the fractional filter_enabled setting to disable it for all requests on the route.

  • Buffer is disabled using BufferPerRoute.Disabled.

Change Type

/kind breaking_change
/kind new_feature

Changelog

Adds disable field to extAuth, extProc, cors, buffer policies to allow
disabling the policies per-route.

Breaking change: extAuth.enablement has been removed in favor of
extAuth.disable.

Additional Notes

Resolves #11892
Also fixes e2e test flakes that were not using the correct assertion API.

@Copilot Copilot AI review requested due to automatic review settings August 6, 2025 18:13
@github-actions github-actions bot added kind/breaking_change kind/feature Categorizes issue or PR as related to a new feature. release-note labels Aug 6, 2025
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 implements per-route disable functionality for extAuth, extProc, buffer, and cors policies, allowing routes to opt-out of policies attached at the Gateway/Listener level. The implementation adds a disable field to these policies and includes a breaking change that removes the extAuth.enablement field in favor of extAuth.disable.

  • Added disable field to extAuth, extProc, buffer, and cors policies
  • Implemented per-route opt-out mechanism using various Envoy filter strategies
  • Updated API validation to require exactly one of extensionRef or disable fields

Reviewed Changes

Copilot reviewed 57 out of 58 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/kubernetes/testutils/assertions/curl.go Refactored assertion methods from public to private and improved variable declaration
test/kubernetes/e2e/features/rate_limit/suite.go Updated test to use eventual assertions instead of immediate ones
test/kubernetes/e2e/features/local_rate_limit/suite.go Updated test to use eventual assertions instead of immediate ones
test/kubernetes/e2e/features/extproc/testdata/gateway-targetref.yaml Added test route with extproc disable policy
test/kubernetes/e2e/features/extproc/suite.go Enhanced test suite with disable functionality testing
test/kubernetes/e2e/features/extauth/testdata/ Updated test files to use new disable field instead of enablement
test/kubernetes/e2e/features/cors/testdata/ Added CORS disable test configuration
test/kubernetes/e2e/features/cors/suite.go Added test assertions for CORS disable functionality
pkg/pluginsdk/ir/iface.go Cleaned up interface method ordering
pkg/plugins/gwextbase/base.go Refactored disable filter utility function
internal/kgateway/utils/cors.go Updated CORS policy creation to support disable functionality
internal/kgateway/utils/any.go Added MustMessageToAny utility function
internal/kgateway/translator/gateway/testutils/ Updated test outputs and inputs for new disable functionality
internal/kgateway/krtcollections/builtin.go Updated CORS IR conversion for new disable parameter
internal/kgateway/extensions2/plugins/trafficpolicy/ Implemented disable functionality across all policy types
install/helm/kgateway-crds/ Updated CRD with new disable fields and validation
design/10683.md Updated design document to reflect API changes
api/v1alpha1/ Updated API types with disable fields and removed enablement field


// Disable the CORS filter.
// +optional
Disable *PolicyDisable `json:"disable,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

should we make it so you cannot set any other fields if you use disable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can, just annoying to do so because every field in the inlined type is optional. Since we inline the upstream API, we need to keep the CEL rules in sync with API changes to the upstream type. I don't feel strongly to make them mutually exclusive even though that is the desired behavior

Copy link
Contributor

Choose a reason for hiding this comment

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

how about this: has(self.disabled) ? self.size() == 1 : true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't apply size() to objects, only list, map, string, bytes are supported

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

object == map I thought

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not and the playground doesn't account for that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tested:

The CustomResourceDefinition "trafficpolicies.gateway.kgateway.dev" is invalid: spec.validation.openAPIV3Schema.properties[spec].properties[cors].x-kubernetes-validations[0].rule: Invalid value: apiextensions.ValidationRule{Rule:"has(self.disable) ? self.size() == 1 : true", Message:"policy fields cannot be set when disabled", MessageExpression:"", Reason:(*apiextensions.FieldValueErrorReason)(nil), FieldPath:"", OptionalOldSelf:(*bool)(nil)}: compilation failed: ERROR: <input>:1:30: found no matching overload for 'size' applied to 'selfType185128119.()'
 | has(self.disable) ? self.size() == 1 : true

@shashankram shashankram force-pushed the filter-disable branch 3 times, most recently from 930c9e4 to 4fd5171 Compare August 7, 2025 14:34
 Description
Adds a `disable` field to the policies to allow disabling
policies attached to Gateway/Listener at the route level as
a form of opt-out mechanism.

- ExtAuth uses the existing global_disable/ext_auth filter,
  though this change updates the metadata key and value
  for consistency.

- ExtProc is configured using a composite filter that conditionally
  enables the actual ExtProc filter based on the absence of the
  global_disable/ext_proc filter. This allows the route plugin
  to simply add the global disable filter to the filter config instead
  of complex post-processing of routes that would be otherwise
  required (vhost plugin runs after route plugin).

- CORS implements disable capability using using the fractional
  filter_enabled setting to disable it for all requests on the route.

- Buffer is disabled using BufferPerRoute.Disabled.

 Change Type

```
/kind breaking_change
/kind new_feature
```

 Changelog

```release-note
Adds disable field to extAuth, extProc, cors, buffer policies to allow
disabling the policies per-route.

Breaking change: extAuth.enablement has been removed in favor of
extAuth.disable.
```

 Additional Notes
Resolves 11892

Signed-off-by: Shashank Ram <[email protected]>
Signed-off-by: Shashank Ram <[email protected]>
@shashankram shashankram added this pull request to the merge queue Aug 7, 2025
Merged via the queue into kgateway-dev:main with commit a22d1e5 Aug 7, 2025
23 checks passed
@shashankram shashankram deleted the filter-disable branch August 7, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/breaking_change 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.

Formalize policy disable API for different filters

4 participants