-
Notifications
You must be signed in to change notification settings - Fork 630
early header mutations #12992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
early header mutations #12992
Conversation
Signed-off-by: Yuval Kohavi <[email protected]>
Signed-off-by: Yuval Kohavi <[email protected]>
…mutations Signed-off-by: Yuval Kohavi <[email protected]>
There was a problem hiding this 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 support for early request header modification to the HTTPListenerPolicy resource, enabling header mutations to be applied before route selection occurs. This feature is particularly useful for security scenarios, such as ensuring that authentication headers cannot be spoofed by clients and are only added by authorized systems like ExternalAuth.
Key Changes
- Added
earlyRequestHeaderModifierfield toHTTPListenerPolicyAPI that accepts standard Gateway APIHTTPHeaderFilterspec (add/set/remove operations) - Introduced shared
ConvertMutationsutility function to eliminate code duplication between listener and route-level header mutation logic - Configured Envoy's
earlyHeaderMutationExtensionsin the HttpConnectionManager to apply mutations before routing
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
api/v1alpha1/http_listener_policy_types.go |
Added EarlyRequestHeaderModifier field to API spec |
install/helm/kgateway-crds/templates/gateway.kgateway.dev_httplistenerpolicies.yaml |
Added CRD schema for early request header modifier field |
api/v1alpha1/zz_generated.deepcopy.go |
Generated deepcopy code for new field |
internal/kgateway/extensions2/pluginutils/headers.go |
New shared utility to convert Gateway API header filters to Envoy mutations |
internal/kgateway/extensions2/plugins/trafficpolicy/header_modifiers.go |
Refactored to use shared conversion utility |
internal/kgateway/extensions2/plugins/httplistenerpolicy/httplistener_plugin.go |
Implemented early header mutation support in plugin |
internal/kgateway/extensions2/plugins/httplistenerpolicy/merge.go |
Added merge logic for early header mutation extensions |
test/e2e/features/http_listener_policy/types.go |
Added manifest path for E2E test |
test/e2e/features/http_listener_policy/suite.go |
Added E2E test verifying route matching with early-added headers |
test/e2e/features/http_listener_policy/testdata/http-listener-policy-early-header-route-match.yaml |
Test manifest with route that requires header added by policy |
internal/kgateway/translator/gateway/gateway_translator_test.go |
Added translator test case for early header mutations |
internal/kgateway/translator/gateway/testutils/inputs/httplistenerpolicy/early-header-mutation.yaml |
Input test data with add/set/remove operations |
internal/kgateway/translator/gateway/testutils/outputs/httplistenerpolicy/early-header-mutation.yaml |
Expected Envoy configuration output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // EarlyRequestHeaderModifier defines header modifications to be applied early in the request processing, | ||
| // before route selection. | ||
| // For example, if you use ExternalAuthz to add a header, you may want to remove it here, to make |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation mentions "ExternalAuthz" but the correct term appears to be "ExternalAuth" based on the comment. Consider using consistent terminology.
| // For example, if you use ExternalAuthz to add a header, you may want to remove it here, to make | |
| // For example, if you use ExternalAuth to add a header, you may want to remove it here, to make |
Signed-off-by: Yuval Kohavi <[email protected]>
internal/kgateway/extensions2/plugins/httplistenerpolicy/httplistener_plugin.go
Show resolved
Hide resolved
9579eea to
325adc1
Compare
Signed-off-by: Yuval Kohavi <[email protected]>
325adc1 to
a06c617
Compare
lgadban
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of relatively minor things.
Would be nice to have a better API name but I can't really come up with anything.
LGTM otherwise though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's borderline nit, but given the primary usecase we care about is sanitizing headers, would prefer a test that removes a header from the incoming request
| // For example, if you use ExternalAuthz to add a header, you may want to remove it here, to make | ||
| // sure it did not come from the client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // For example, if you use ExternalAuthz to add a header, you may want to remove it here, to make | |
| // sure it did not come from the client. | |
| // For example, if your external auth service adds a header, you should sanitize that header by removing it here, | |
| // to make sure it did not come from the client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really just trying to get 'sanitize' somewhere in here.
Signed-off-by: Yuval Kohavi <[email protected]>
Signed-off-by: Yuval Kohavi <[email protected]> Signed-off-by: John Howard <[email protected]>
Fixes #12940
Description
Early header mutations
Change Type
Changelog