feat(traefik): add customRequest/ResponseHeaders middlewares (#10401)

This commit is contained in:
Dion Larson 2023-07-15 02:54:49 -04:00 committed by GitHub
parent d23c3a6683
commit fe7f2c03a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 140 additions and 1 deletions

View File

@ -23,7 +23,7 @@ sources:
- https://github.com/traefik/traefik-helm-chart
- https://traefik.io/
type: application
version: 18.0.18
version: 18.1.0
annotations:
truecharts.org/catagories: |
- network

View File

@ -0,0 +1,11 @@
# Adding or removing headers
The `customRequestHeaders` and `customResponseHeaders` middlewares will allow you to add or remove headers from the request or response.
## `customRequestHeaders`
You can specify a list of headers to add to requests. When removing a header, you only need to specify the header name (an empty value removes the header with that name from requests, if it exists).
## `customResponseHeaders`
You can specify a list of headers to add to responses. When removing a header, you only need to specify the header name (an empty value removes the header with that name from responses, if it exists).

View File

@ -184,6 +184,8 @@ questions:
attrs:
# Include{basicAuthMiddleware}
# Include{forwardAuthMiddleware}
# Include{customRequestHeadersMiddleware}
# Include{customResponseHeadersMiddleware}
# Include{chainMiddleware}
# Include{redirectSchemeMiddleware}
# Include{rateLimitMiddleware}

View File

@ -0,0 +1,18 @@
{{- $values := .Values }}
{{ range $index, $middlewareData := .Values.middlewares.customRequestHeaders }}
---
# Declaring the user list
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
spec:
headers:
customRequestHeaders:
{{ range $index, $customRequestHeader := $middlewareData.headers }}
{{ $customRequestHeader.name }}: {{ $customRequestHeader.value | quote }}
{{ end }}
{{ end }}

View File

@ -0,0 +1,18 @@
{{- $values := .Values }}
{{ range $index, $middlewareData := .Values.middlewares.customResponseHeaders }}
---
# Declaring the user list
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
spec:
headers:
customResponseHeaders:
{{ range $index, $customResponseHeader := $middlewareData.headers }}
{{ $customResponseHeader.name }}: {{ $customResponseHeader.value | quote }}
{{ end }}
{{ end }}

View File

@ -332,6 +332,20 @@ middlewares:
# - "X-CustomHeader"
# authResponseHeadersRegex: "^X-"
# trustForwardHeader: true
customRequestHeaders: []
# - name: customRequestHeaderExample
# headers:
# - name: X-Custom-Header
# value: "foobar"
# - name: X-Header-To-Remove
# value: ""
customResponseHeaders: []
# - name: customResponseHeaderExample
# headers:
# - name: X-Custom-Header
# value: "foobar"
# - name: X-Header-To-Remove
# value: ""
chain: []
# - name: chainname
# middlewares:

View File

@ -0,0 +1,38 @@
- variable: customRequestHeaders
label: Custom Request Headers
schema:
type: list
default: []
items:
- variable: customRequestHeadersEntry
label: ""
schema:
additional_attrs: true
type: dict
attrs:
- variable: name
label: Name
schema:
type: string
required: true
- variable: headers
label: Headers to Add
schema:
type: list
default: []
items:
- variable: name
label: Header Name
description: Name of custom header to be added to requests, eg. X-Custom-Header
pattern: ^[a-zA-Z0-9_\-]*$
schema:
type: string
required: true
default: ""
- variable: value
label: Header Value
description: The value of the header. If the value is empty, the header will be removed.
schema:
type: string
required: true
default: ""

View File

@ -0,0 +1,38 @@
- variable: customResponseHeaders
label: Custom Response Headers
schema:
type: list
default: []
items:
- variable: customResponseHeadersEntry
label: ""
schema:
additional_attrs: true
type: dict
attrs:
- variable: name
label: Name
schema:
type: string
required: true
- variable: headers
label: Headers to Add
schema:
type: list
default: []
items:
- variable: name
label: Header Name
description: Name of custom header to be added to responses, eg. X-Custom-Header
pattern: ^[a-zA-Z0-9_\-]*$
schema:
type: string
required: true
default: ""
- variable: value
label: Header Value
description: The value of the header. If the value is empty, the header will be removed.
schema:
type: string
required: true
default: ""