Skip to content

Commit 1f4ee0e

Browse files
authored
feat: add annotation to allow to add custom response headers (#9742)
* add custom headers Signed-off-by: Christian Groschupp <[email protected]> * add tests Signed-off-by: Christian Groschupp <[email protected]> * add docs * update copyright * change comments * add e2e test customheaders * add custom headers validation * remove escapeLiteralDollar filter * validate value in custom headers * add regex for header value * fix annotation test * Revert "remove escapeLiteralDollar filter" This reverts commit ab48392b60dee4ce146a4c17e046849f9633c7fb. * add annotationConfig * fix test * fix golangci-lint findings * fix: add missung exp module --------- Signed-off-by: Christian Groschupp <[email protected]>
1 parent d56aacd commit 1f4ee0e

File tree

15 files changed

+537
-4
lines changed

15 files changed

+537
-4
lines changed

docs/user-guide/nginx-configuration/annotations.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ You can add these Kubernetes annotations to specific Ingress objects to customiz
5050
|[nginx.ingress.kubernetes.io/client-body-buffer-size](#client-body-buffer-size)|string|
5151
|[nginx.ingress.kubernetes.io/configuration-snippet](#configuration-snippet)|string|
5252
|[nginx.ingress.kubernetes.io/custom-http-errors](#custom-http-errors)|[]int|
53+
|[nginx.ingress.kubernetes.io/custom-headers](#custom-headers)|string|
5354
|[nginx.ingress.kubernetes.io/default-backend](#default-backend)|string|
5455
|[nginx.ingress.kubernetes.io/enable-cors](#enable-cors)|"true" or "false"|
5556
|[nginx.ingress.kubernetes.io/cors-allow-origin](#enable-cors)|string|
@@ -338,6 +339,22 @@ Example usage:
338339
nginx.ingress.kubernetes.io/custom-http-errors: "404,415"
339340
```
340341

342+
### Custom Headers
343+
This annotation is of the form `nginx.ingress.kubernetes.io/custom-headers: custom-headers-configmap` to specify a configmap name that contains custom headers. This annotation uses `more_set_headers` nginx directive.
344+
345+
Example configmap:
346+
```yaml
347+
apiVersion: v1
348+
data:
349+
Content-Type: application/json
350+
kind: ConfigMap
351+
metadata:
352+
name: custom-headers-configmap
353+
```
354+
355+
!!! attention
356+
First define the allowed response headers in [global-allowed-response-headers](https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/configmap.md#global-allowed-response-headers).
357+
341358
### Default Backend
342359

343360
This annotation is of the form `nginx.ingress.kubernetes.io/default-backend: <svc name>` to specify a custom default backend. This `<svc name>` is a reference to a service inside of the same namespace in which you are applying this annotation. This annotation overrides the global default backend. In case the service has [multiple ports](https://kubernetes.io/docs/concepts/services-networking/service/#multi-port-services), the first one is the one which will receive the backend traffic.

docs/user-guide/nginx-configuration/configmap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ The following table shows a configuration option's name, type, and the default v
209209
|[syslog-host](#syslog-host)| string | "" ||
210210
|[syslog-port](#syslog-port)| int | 514 ||
211211
|[no-tls-redirect-locations](#no-tls-redirect-locations)| string | "/.well-known/acme-challenge" ||
212+
|[global-allowed-response-headers](#global-allowed-response-headers)|string|""||
212213
|[global-auth-url](#global-auth-url)| string | "" ||
213214
|[global-auth-method](#global-auth-method)| string | "" ||
214215
|[global-auth-signin](#global-auth-signin)| string | "" ||
@@ -1285,6 +1286,10 @@ Sets the port of syslog server. _**default:**_ 514
12851286
A comma-separated list of locations on which http requests will never get redirected to their https counterpart.
12861287
_**default:**_ "/.well-known/acme-challenge"
12871288

1289+
## global-allowed-response-headers
1290+
1291+
A comma-separated list of allowed response headers inside the [custom headers annotations](https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/annotations.md#custom-headers)
1292+
12881293
## global-auth-url
12891294

12901295
A url to an existing service that provides authentication for all the locations.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require (
2626
github.com/yudai/gojsondiff v1.0.0
2727
github.com/zakjan/cert-chain-resolver v0.0.0-20221221105603-fcedb00c5b30
2828
golang.org/x/crypto v0.22.0
29+
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
2930
google.golang.org/grpc v1.63.2
3031
google.golang.org/grpc/examples v0.0.0-20240223204917-5ccf176a08ab
3132
gopkg.in/go-playground/pool.v3 v3.1.1

0 commit comments

Comments
 (0)