-
Notifications
You must be signed in to change notification settings - Fork 647
feat(api): add addIfAbsent header action in ClientTrafficPolicy #7978
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
Conversation
**What type of PR is this?** Feature - adds new API field and functionality **What this PR does / why we need it**: This PR adds support for the `addIfAbsent` header action in `HTTPHeaderFilter`, which adds headers only if they don't already exist. This maps to Envoy's [`ADD_IF_ABSENT`](https://www.envoyproxy.io/docs/envoy/v1.36.2/api-v3/config/core/v3/base.proto#enum-config-core-v3-headervalueoption-headerappendaction) action. **Use Case:** Set default headers (e.g., `Content-Security-Policy`, `X-Frame-Options`) at the gateway level that can be overridden by backend responses. Unlike `add` which appends to existing headers, or `set` which overwrites them, `addIfAbsent` is a no-op if the header is already present. **Changes:** - Added `AddIfAbsent` field to `HTTPHeaderFilter` in `api/v1alpha1/shared_types.go` - Added `AddIfAbsent` field to IR `AddHeader` struct in `internal/ir/xds.go` - Updated `translateHeaderModifier()` in `internal/gatewayapi/clienttrafficpolicy.go` - Updated `buildXdsAddedHeaders()` in `internal/xds/translator/route.go` - Updated `buildHeaderMutationRules()` in `internal/xds/translator/header_mutation.go` - Added documentation in `site/content/en/latest/tasks/traffic/http-response-headers.md` - Added testdata files for Gateway API and XDS translator tests **Example usage:** ```yaml apiVersion: gateway.envoyproxy.io/v1alpha1 kind: ClientTrafficPolicy metadata: name: default-headers spec: targetRef: group: gateway.networking.k8s.io kind: Gateway name: eg headers: lateResponseHeaders: addIfAbsent: - name: "content-security-policy" value: "default-src 'self'" ``` Which issue(s) this PR fixes: Fixes envoyproxy#7656 Release Notes: Yes Signed-off-by: Michal Skalski <[email protected]>
✅ Deploy Preview for cerulean-figolla-1f9435 canceled.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7978 +/- ##
==========================================
+ Coverage 72.81% 72.83% +0.01%
==========================================
Files 237 237
Lines 35475 35505 +30
==========================================
+ Hits 25832 25859 +27
- Misses 7801 7805 +4
+ Partials 1842 1841 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Michal Skalski <[email protected]>
Signed-off-by: Michal Skalski <[email protected]>
Signed-off-by: Michal Skalski <[email protected]>
|
/retest |
| port: 10080 | ||
| hostnames: | ||
| - "*" | ||
| headers: |
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.
can we also add an example for earlyRequestHeaders
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.
added in 7c234f2
| namespace: envoy-gateway | ||
| name: target-gateway-1 | ||
| spec: | ||
| headers: |
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.
can we also add an example for earlyRequestHeaders
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.
added in 7c234f2
|
hey PR looks great, added a minor comment to add 1 more test case to make sure this also works for |
Signed-off-by: Michal Skalski <[email protected]>
|
can you add release notes for this? |
arkodg
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.
LGTM thanks
Added in release-notes/current.yaml:29. Happy to adjust the wording if needed. |
|
/retest |
my bad, I missed it. |
|
Thanks @michalskalski, this is going to be really useful! |
What type of PR is this?
Feature - adds new API field and functionality
What this PR does / why we need it:
This PR adds support for the
addIfAbsentheader action inHTTPHeaderFilter, which adds headers only if they don't already exist. This maps to Envoy'sADD_IF_ABSENTaction.Use Case:
Set default headers (e.g.,
Content-Security-Policy,X-Frame-Options) at the gateway level that can be overridden by backend responses. Unlikeaddwhich appends to existing headers, orsetwhich overwrites them,addIfAbsentis a no-op if the header is already present.Changes:
AddIfAbsentfield toHTTPHeaderFilterinapi/v1alpha1/shared_types.goAddIfAbsentfield to IRAddHeaderstruct ininternal/ir/xds.gotranslateHeaderModifier()ininternal/gatewayapi/clienttrafficpolicy.gobuildXdsAddedHeaders()ininternal/xds/translator/route.gobuildHeaderMutationRules()ininternal/xds/translator/header_mutation.gosite/content/en/latest/tasks/traffic/http-response-headers.mdExample usage:
Which issue(s) this PR fixes:
Fixes #7656
Release Notes: Yes