feat(traefik): BREAKING CHANGE register traefik and use traefik namespace for middleware instead of tc-system (#11086)

**Description**
With the removal of manifest manager tc-system is removed for new users.
Traefik should use it's own namespace for middlewares instead and common
is already adapted to allow this.

This change also allows us to throw errors if traefik isn't installed on
a system when ingress is enabled.

Downside is that this currently breaks ingressclass, which is a
non-supported setup currently, untill we do more R&D for cleanly
handling ingressClasses, namespaces and middlewares correctly.

Also adds helm and SCALE support for the modsecurity plugin.

Also fixes CI bug with metallb.

**⚙️ Type of change**

- [x] ⚙️ Feature/App addition
- [x] 🪛 Bugfix
- [x] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [ ] ⚖️ 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
- [ ] ⬆️ 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._
This commit is contained in:
Kjeld Schouten 2023-07-31 12:32:04 +02:00 committed by GitHub
parent 585525d844
commit 9c2b859a76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 103 additions and 37 deletions

View File

@ -150,7 +150,7 @@ jobs:
run: |
## TODO: Move to our Helm Charts
## TODO: Only add when required
if [[ "${{ matrix.chart }}" != "charts/operators/metallb" ]]; then
if [[ "${{ matrix.chart }}" == "charts/operators/metallb-config" ]]; then
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml --server-side --force-conflicts || echo "error fetching metallb manifest"
fi
if [[ "${{ matrix.chart }}" != "charts/operators/cloudnative-pg" ]]; then
@ -208,7 +208,7 @@ jobs:
- name: Add Dependencies
run: |
if [[ "${{ matrix.chart }}" != "charts/operators/metallb" ]]; then
if [[ "${{ matrix.chart }}" == "charts/operators/metallb-config" ]]; then
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml --server-side --force-conflicts || echo "error fetching metallb manifest"
fi
if [[ "${{ matrix.chart }}" != "charts/operators/cloudnative-pg" ]]; then
@ -266,7 +266,7 @@ jobs:
- name: Add Dependencies
run: |
if [[ "${{ matrix.chart }}" != "charts/operators/metallb" ]]; then
if [[ "${{ matrix.chart }}" == "charts/operators/metallb-config" ]]; then
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml --server-side --force-conflicts || echo "error fetching metallb manifest"
fi
if [[ "${{ matrix.chart }}" != "charts/operators/cloudnative-pg" ]]; then
@ -324,7 +324,7 @@ jobs:
- name: Add Dependencies
run: |
if [[ "${{ matrix.chart }}" != "charts/operators/metallb" ]]; then
if [[ "${{ matrix.chart }}" == "charts/operators/metallb-config" ]]; then
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml --server-side --force-conflicts || echo "error fetching metallb manifest"
fi
if [[ "${{ matrix.chart }}" != "charts/operators/cloudnative-pg" ]]; then
@ -382,7 +382,7 @@ jobs:
- name: Add Dependencies
run: |
if [[ "${{ matrix.chart }}" != "charts/operators/metallb" ]]; then
if [[ "${{ matrix.chart }}" == "charts/operators/metallb-config" ]]; then
kubectl apply -f --server-side --force-conflicts https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml
fi
if [[ "${{ matrix.chart }}" != "charts/operators/cloudnative-pg" ]]; then
@ -440,7 +440,7 @@ jobs:
- name: Add Dependencies
run: |
if [[ "${{ matrix.chart }}" != "charts/operators/metallb" ]]; then
if [[ "${{ matrix.chart }}" == "charts/operators/metallb-config" ]]; then
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml --server-side --force-conflicts || echo "error fetching metallb manifest"
fi
if [[ "${{ matrix.chart }}" != "charts/operators/cloudnative-pg" ]]; then

View File

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

View File

@ -198,6 +198,7 @@ questions:
# Include{realIPMiddleware}
# Include{geoBlockMiddleware}
# Include{addPrefixMiddleware}
# Include{modsecurityMiddleware}
- variable: service
group: "Networking and Services"
label: "Configure Service Entrypoint"

View File

@ -10,7 +10,6 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $name }}
namespace: tc-system
data:
{{- $ports := dict }}
{{- range $.Values.service }}

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
addPrefix:
prefix: {{ $middlewareData.prefix }}

View File

@ -3,7 +3,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-compress" $.Release.Name) "compress" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
compress: {}
---
@ -13,7 +13,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-basic-ratelimit" $.Release.Name) "basic-ratelimit" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
rateLimit:
average: 600
@ -23,7 +23,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-basic-secure-headers" $.Release.Name) "basic-secure-headers" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
headers:
accessControlAllowMethods:
@ -48,7 +48,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-chain-basic" $.Release.Name) "chain-basic" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
chain:
middlewares:

View File

@ -10,7 +10,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ printf "%v-%v" $middlewareData.name "secret" }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
type: Opaque
stringData:
users: |
@ -23,7 +23,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
basicAuth:
secret: {{ printf "%v-%v" $middlewareData.name "secret" }}

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
buffering: {{/* Only render if its not <nil> and has a value of 0 or greater */}}
{{- if not (kindIs "invalid" $middlewareData.maxRequestBodyBytes) (ge ($middlewareData.maxRequestBodyBytes | int) 0) }}

View File

@ -1,7 +1,7 @@
{{- $values := .Values -}}
{{- $namespace := "tc-system" -}}
{{- $namespace := $.Release.Namespace -}}
{{- if $.Values.ingressClass.enabled -}}
{{- $namespace := (printf "tc-system-%s" .Release.Name) -}}
{{- $namespace := (printf "%v-%v" $namespace .Release.Name) -}}
{{- end -}}
{{- range $index, $middlewareData := .Values.middlewares.chain }}
@ -11,7 +11,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
chain:
middlewares:

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
headers:
customFrameOptionsValue: {{ $middlewareData.value }}

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
headers:
customRequestHeaders:

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
headers:
customResponseHeaders:

View File

@ -4,7 +4,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
forwardAuth:
address: {{ $middlewareData.address }}

View File

@ -4,7 +4,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
plugin:
GeoBlock:

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
ipWhiteList:
sourceRange:

View File

@ -0,0 +1,14 @@
{{- range $index, $middlewareData := .Values.middlewares.modsecurity }}
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: {{ $.Release.Namespace }}
spec:
plugin:
traefik-modsecurity-plugin:
modSecurityUrl: {{ $middlewareData.modSecurityUrl }}
timeoutMillis: {{ $middlewareData.timeoutMillis }}
maxBodySize: {{ $middlewareData.maxBodySize }}
{{- end -}}

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
rateLimit:
average: {{ $middlewareData.average }}

View File

@ -4,7 +4,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
plugin:
traefik-real-ip:

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
redirectScheme:
scheme: {{ $middlewareData.scheme }}

View File

@ -5,7 +5,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
redirectRegex:
regex: {{ $middlewareData.regex | quote }}

View File

@ -4,7 +4,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
stripPrefixRegex:
regex:

View File

@ -3,7 +3,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name "tc-opencors-chain") "tc-opencors-chain" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
chain:
middlewares:
@ -15,7 +15,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name "tc-closedcors-chain") "tc-closedcors-chain" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
chain:
middlewares:

View File

@ -3,7 +3,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name "tc-opencors-headers") "tc-opencors-headers" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
headers:
accessControlAllowHeaders:
@ -33,7 +33,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name "tc-closedcors-headers") "tc-closedcors-headers" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
headers:
accessControlAllowMethods:

View File

@ -3,7 +3,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name "tc-nextcloud-redirectregex-dav") "tc-nextcloud-redirectregex-dav" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
redirectRegex:
regex: "https://(.*)/.well-known/(card|cal)dav"
@ -13,7 +13,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name "tc-nextcloud-chain") "tc-nextcloud-chain" $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
chain:
middlewares:

View File

@ -4,7 +4,7 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
namespace: tc-system
namespace: {{ $.Release.Namespace }}
spec:
plugin:
traefik-themepark:

View File

@ -48,6 +48,9 @@ workload:
podOptions:
automountServiceAccountToken: true
operator:
register: true
# -- Use ingressClass. Ignored if Traefik version < 2.3 / kubernetes < 1.18.x
ingressClass:
# true is not unit-testable yet, pending https://github.com/rancher/helm-unittest/pull/12
@ -421,6 +424,14 @@ middlewares:
# blackListMode: false
# countries:
# - RU
modsecurity: []
# - name: modsecurityName
# modSecurityUrl: modSecurity container URL
# timeoutMillis: Configurated timeout
# maxBodySize: maxBodySize
## Note: body of every request will be buffered in memory while the request is in-flight
## (i.e.: during the security check and during the request processing by traefik and the backend),
## so you may want to tune maxBodySize depending on how much RAM you have.
portalhook:
enabled: true

View File

@ -0,0 +1,41 @@
- variable: modsecurity
label: modsecurity
schema:
type: list
default: []
items:
- variable: modsecurityEntry
label: ""
schema:
additional_attrs: true
type: dict
attrs:
- variable: name
label: Name
description: This is a 3rd party plugin and not maintained by TrueCharts,
for more information go to <a href="https://github.com/acouvreur/traefik-modsecurity-plugin">traefik-modsecurity-plugin</a>
schema:
type: string
required: true
default: ""
- variable: modSecurityUrl
label: ModSecurity Url
description: It's the URL for the owasp/modsecurity container.
schema:
type: string
required: true
default: "https://someurl"
- variable: timeoutMillis
label: timeout Millis
description: timeout in milliseconds for the http client to talk with modsecurity container. (
schema:
type: int
required: true
default: 2
- variable: maxBodySize
label: maxBody Size
description: it's the maximum limit for requests body size. Requests exceeding this value will be rejected using HTTP 413 Request Entity Too Large. Zero means "use default value".
schema:
type: int
required: true
default: 0