From 6bc7e087fccdb9d2faf8e3239b4405c4416293a5 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Thu, 28 Dec 2023 14:50:16 +0100 Subject: [PATCH] feat: enable forceTLS on traefik integration on main ingress by default (#667) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # **⚙️ 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 - [x] 👀 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 - [x] ⚠️ My changes generate no new warnings - [x] 🧪 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._ --------- Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> --- library/common-test/Chart.yaml | 2 +- .../tests/ingress/traefik_test.yaml | 77 +++++++++++++++++++ library/common/Chart.yaml | 2 +- .../lib/ingress/integrations/_traefik.tpl | 4 +- library/common/values.yaml | 2 + 5 files changed, 83 insertions(+), 4 deletions(-) diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index 3b1b3583..dd961968 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -3,7 +3,7 @@ appVersion: "" dependencies: - name: common repository: file://../common - version: ~17.1.0 + version: ~17.2.0 deprecated: false description: Helper chart to test different use cases of the common library home: https://github.com/truecharts/apps/tree/master/charts/library/common-test diff --git a/library/common-test/tests/ingress/traefik_test.yaml b/library/common-test/tests/ingress/traefik_test.yaml index 40a0d777..10d1fc5e 100644 --- a/library/common-test/tests/ingress/traefik_test.yaml +++ b/library/common-test/tests/ingress/traefik_test.yaml @@ -46,6 +46,7 @@ tests: equal: path: metadata.annotations value: + traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.middlewares: test-release-namespace-chain-basic@kubernetescrd - documentIndex: *ingressDoc @@ -113,6 +114,7 @@ tests: equal: path: metadata.annotations value: + traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.middlewares: test-release-namespace-tc-opencors-chain@kubernetescrd @@ -149,6 +151,7 @@ tests: equal: path: metadata.annotations value: + traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.middlewares: test-release-namespace-tc-opencors-chain@kubernetescrd @@ -180,6 +183,7 @@ tests: equal: path: metadata.annotations value: + traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.middlewares: test-release-namespace-some-fixed-middleware@kubernetescrd @@ -211,6 +215,7 @@ tests: equal: path: metadata.annotations value: + traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.entrypoints: web,websecure traefik.ingress.kubernetes.io/router.middlewares: test-release-namespace-chain-basic@kubernetescrd @@ -237,6 +242,7 @@ tests: equal: path: metadata.annotations value: + traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.entrypoints: websecure - it: should not contain fixed middlewares when local is disabled @@ -263,6 +269,7 @@ tests: equal: path: metadata.annotations value: + traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.entrypoints: websecure - it: should add the defined middlewares to the ingress @@ -298,9 +305,79 @@ tests: equal: path: metadata.annotations value: + traefik.ingress.kubernetes.io/router.tls: "true" traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.middlewares: test-release-namespace-chain-basic@kubernetescrd,test-release-namespace-some-middleware@kubernetescrd,test-release-namespace-some-other-middleware@kubernetescrd + - it: should add the the tls annotation + set: + operator: *operator + service: *service + global: *global + ingress: + my-ingress: + enabled: true + primary: true + integrations: + traefik: + enabled: true + forceTLS: true + entrypoints: + - web + hosts: *hosts + asserts: + - documentIndex: *ingressDoc + isKind: + of: Ingress + - documentIndex: *ingressDoc + isKind: + of: Ingress + - documentIndex: *ingressDoc + equal: + path: metadata.name + value: test-release-name-common-test + - documentIndex: *ingressDoc + equal: + path: metadata.annotations + value: + traefik.ingress.kubernetes.io/router.tls: "true" + traefik.ingress.kubernetes.io/router.entrypoints: web + traefik.ingress.kubernetes.io/router.middlewares: test-release-namespace-chain-basic@kubernetescrd + + - it: should not add the the tls annotation + set: + operator: *operator + service: *service + global: *global + ingress: + my-ingress: + enabled: true + primary: true + integrations: + traefik: + enabled: true + forceTLS: false + entrypoints: + - web + hosts: *hosts + asserts: + - documentIndex: *ingressDoc + isKind: + of: Ingress + - documentIndex: *ingressDoc + isKind: + of: Ingress + - documentIndex: *ingressDoc + equal: + path: metadata.name + value: test-release-name-common-test + - documentIndex: *ingressDoc + equal: + path: metadata.annotations + value: + traefik.ingress.kubernetes.io/router.entrypoints: web + traefik.ingress.kubernetes.io/router.middlewares: test-release-namespace-chain-basic@kubernetescrd + # Failures - it: should fail with entrypoint not a slice set: diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 37beedac..17c6d960 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 17.1.5 +version: 17.2.0 diff --git a/library/common/templates/lib/ingress/integrations/_traefik.tpl b/library/common/templates/lib/ingress/integrations/_traefik.tpl index b20fc044..ffacfcba 100644 --- a/library/common/templates/lib/ingress/integrations/_traefik.tpl +++ b/library/common/templates/lib/ingress/integrations/_traefik.tpl @@ -119,8 +119,8 @@ {{- $_ := set $objectData.annotations "traefik.ingress.kubernetes.io/router.middlewares" (join "," $formattedMiddlewares) -}} {{- end -}} - {{- if or $traefik.forceTLS ( has websecure $entrypoints ) -}} - {{- $_ := set $objectData.annotations "traefik.ingress.kubernetes.io/router.tls" 'true' -}} + {{- if or $traefik.forceTLS (mustHas "websecure" $entrypoints) -}} + {{- $_ := set $objectData.annotations "traefik.ingress.kubernetes.io/router.tls" "true" -}} {{- end -}} {{- end -}} diff --git a/library/common/values.yaml b/library/common/values.yaml index ec66cd4f..8ecec239 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -593,6 +593,8 @@ ingress: entrypoints: - websecure enableFixedMiddlewares: true + # Ensures tls annotation is set + forceTLS: true # Drops both global and local fixedMiddlewares when enabled allowCors: false # fixedMiddlewares: