From 5ac7e22f67c50f909862f8e2e8085d6387604377 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Mon, 31 Jul 2023 12:16:47 +0300 Subject: [PATCH] feat(traefik): add some middlewares (#11058) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes #4999 ⚒️ Fixes #5633 **⚙️ Type of change** - [x] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [x] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [x] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Signed-off-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Signed-off-by: Kjeld Schouten Co-authored-by: Kjeld Schouten --- charts/enterprise/traefik/Chart.yaml | 2 +- charts/enterprise/traefik/questions.yaml | 2 + .../templates/middlewares/buffering.yaml | 26 ++++++++++ .../middlewares/customFrameOptionsValue.yaml | 12 +++++ charts/enterprise/traefik/values.yaml | 10 ++++ .../traefik/bufferingMiddleware.yaml | 51 +++++++++++++++++++ .../customFrameOptionsValueMiddleware.yaml | 24 +++++++++ 7 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 charts/enterprise/traefik/templates/middlewares/buffering.yaml create mode 100644 charts/enterprise/traefik/templates/middlewares/customFrameOptionsValue.yaml create mode 100644 templates/questions/traefik/bufferingMiddleware.yaml create mode 100644 templates/questions/traefik/customFrameOptionsValueMiddleware.yaml diff --git a/charts/enterprise/traefik/Chart.yaml b/charts/enterprise/traefik/Chart.yaml index a63e40a0530..f45c0488673 100644 --- a/charts/enterprise/traefik/Chart.yaml +++ b/charts/enterprise/traefik/Chart.yaml @@ -23,7 +23,7 @@ sources: - https://github.com/traefik/traefik-helm-chart - https://traefik.io/ type: application -version: 19.0.4 +version: 19.1.0 annotations: truecharts.org/catagories: | - network diff --git a/charts/enterprise/traefik/questions.yaml b/charts/enterprise/traefik/questions.yaml index a7ff907c7bb..bdfb2413ec0 100644 --- a/charts/enterprise/traefik/questions.yaml +++ b/charts/enterprise/traefik/questions.yaml @@ -184,8 +184,10 @@ questions: attrs: # Include{basicAuthMiddleware} # Include{forwardAuthMiddleware} +# Include{bufferingMiddleware} # Include{customRequestHeadersMiddleware} # Include{customResponseHeadersMiddleware} +# Include{customFrameOptionsValueMiddleware} # Include{chainMiddleware} # Include{redirectSchemeMiddleware} # Include{rateLimitMiddleware} diff --git a/charts/enterprise/traefik/templates/middlewares/buffering.yaml b/charts/enterprise/traefik/templates/middlewares/buffering.yaml new file mode 100644 index 00000000000..eae1dad276d --- /dev/null +++ b/charts/enterprise/traefik/templates/middlewares/buffering.yaml @@ -0,0 +1,26 @@ +{{- range $index, $middlewareData := .Values.middlewares.buffering }} +--- +# 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: + buffering: {{/* Only render if its not and has a value of 0 or greater */}} + {{- if not (kindIs "invalid" $middlewareData.maxRequestBodyBytes) (ge ($middlewareData.maxRequestBodyBytes | int) 0) }} + maxRequestBodyBytes: {{ $middlewareData.maxRequestBodyBytes }} + {{- end -}} + {{- if not (kindIs "invalid" $middlewareData.memRequestBodyBytes) (ge ($middlewareData.memRequestBodyBytes | int) 0) }} + memRequestBodyBytes: {{ $middlewareData.memRequestBodyBytes }} + {{- end -}} + {{- if not (kindIs "invalid" $middlewareData.maxResponseBodyBytes) (ge ($middlewareData.maxResponseBodyBytes | int) 0) }} + maxResponseBodyBytes: {{ $middlewareData.maxResponseBodyBytes }} + {{- end -}} + {{- if not (kindIs "invalid" $middlewareData.memResponseBodyBytes) (ge ($middlewareData.memResponseBodyBytes | int) 0) }} + memResponseBodyBytes: {{ $middlewareData.memResponseBodyBytes }} + {{- end -}} + {{- if $middlewareData.retryExpression }} + retryExpression: {{ $middlewareData.retryExpression | quote }} + {{- end -}} +{{- end -}} diff --git a/charts/enterprise/traefik/templates/middlewares/customFrameOptionsValue.yaml b/charts/enterprise/traefik/templates/middlewares/customFrameOptionsValue.yaml new file mode 100644 index 00000000000..2931f1d1126 --- /dev/null +++ b/charts/enterprise/traefik/templates/middlewares/customFrameOptionsValue.yaml @@ -0,0 +1,12 @@ +{{- range $index, $middlewareData := .Values.middlewares.customFrameOptionsValue }} +--- +# 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: + customFrameOptionsValue: {{ $middlewareData.value }} +{{- end -}} diff --git a/charts/enterprise/traefik/values.yaml b/charts/enterprise/traefik/values.yaml index 4ade7b9f4c7..e60e9f75a86 100644 --- a/charts/enterprise/traefik/values.yaml +++ b/charts/enterprise/traefik/values.yaml @@ -346,6 +346,16 @@ middlewares: # value: "foobar" # - name: X-Header-To-Remove # value: "" + customFrameOptionsValue: [] + # - name: customFrameOptionsValueExample + # value: "SAMEORIGIN" + buffering: [] + # - name: bufferingExample + # maxRequestBodyBytes: 1000000 + # memRequestBodyBytes: 1000000 + # maxResponseBodyBytes: 1000000 + # memResponseBodyBytes: 1000000 + # retryExpression: "IsNetworkError() && Attempts() < 2" chain: [] # - name: chainname # middlewares: diff --git a/templates/questions/traefik/bufferingMiddleware.yaml b/templates/questions/traefik/bufferingMiddleware.yaml new file mode 100644 index 00000000000..4986fa0b1a5 --- /dev/null +++ b/templates/questions/traefik/bufferingMiddleware.yaml @@ -0,0 +1,51 @@ + - variable: buffering + label: Buffering + schema: + type: list + default: [] + items: + - variable: bufferingEntry + label: "" + schema: + additional_attrs: true + type: dict + attrs: + - variable: name + label: Name + schema: + type: string + required: true + - variable: maxRequestBodyBytes + label: Max Request Body Bytes + description: Leave empty and it won't be set + schema: + type: string + valid_chars: '^[0-9]*$' + default: "" + - variable: memRequestBodyBytes + label: Mem Request Body Bytes + description: Leave empty and it won't be set + schema: + type: string + valid_chars: '^[0-9]*$' + default: "" + - variable: maxResponseBodyBytes + label: Max Response Body Bytes + description: Leave empty and it won't be set + schema: + type: string + valid_chars: '^[0-9]*$' + default: "" + - variable: memResponseBodyBytes + label: Mem Response Body Bytes + description: Leave empty and it won't be set + schema: + type: string + valid_chars: '^[0-9]*$' + default: "" + - variable: retryExpression + label: Retry Expression + description: Leave empty and it won't be set + schema: + type: string + default: "" diff --git a/templates/questions/traefik/customFrameOptionsValueMiddleware.yaml b/templates/questions/traefik/customFrameOptionsValueMiddleware.yaml new file mode 100644 index 00000000000..11c2c4a1394 --- /dev/null +++ b/templates/questions/traefik/customFrameOptionsValueMiddleware.yaml @@ -0,0 +1,24 @@ + - variable: customFrameOptionsValue + label: Custom Frame Options Value + schema: + type: list + default: [] + items: + - variable: customFrameOptionsValueEntry + label: "" + schema: + additional_attrs: true + type: dict + attrs: + - variable: name + label: Name + schema: + type: string + required: true + - variable: value + label: X-Frame-Options Header Value + description: The value of the header. + schema: + type: string + required: true + default: ""