From f17dd03c480aface87d146c267a29d3d63ecfbdd Mon Sep 17 00:00:00 2001 From: sdimovv <36302090+sdimovv@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:17:04 +0100 Subject: [PATCH] feat(cluster-issuer): Add ability to create cluster-wide certificates (#13852) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** This PR adds the next piece needed to support cluster-wide certificates in Truecharts. See PRs: - #13756 - https://github.com/truecharts/library-charts/pull/537 - https://github.com/truecharts/containers/pull/33273 Relevant issues: #8634 This PR only adds what is needed in cluster-issuer. I will be pushing a separate PR that will change the contents of the question includes. ⚒️ 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?** Tested it produces the correct yaml with helm: ``` helm template -n cluster-issuer cluster-issuer . ``` Tested with 0, 1 and 2 certificate definitions in `values.yaml`. The produced YAML is correct (with one exception - its missing the `secretTemplate` property, which needs https://github.com/truecharts/library-charts/pull/537 in order to work) **📃 Notes:** Should be merged after https://github.com/truecharts/library-charts/pull/537 is merged and the common version dependency is bumped to reflect the new common version. **✔️ Checklist:** - [X] ⚖️ My code follows the style guidelines of this project - [X] 👀 I have performed a self-review of my own code - [X] #️⃣ 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._ --------- Signed-off-by: sdimovv <36302090+sdimovv@users.noreply.github.com> Signed-off-by: Kjeld Schouten Signed-off-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Co-authored-by: Kjeld Schouten --- charts/enterprise/clusterissuer/Chart.yaml | 4 +- .../enterprise/clusterissuer/questions.yaml | 47 +++++++++++++++++++ .../clusterissuer/_clusterCertificates.tpl | 36 ++++++++++++++ .../clusterissuer/templates/common.yaml | 5 ++ charts/enterprise/clusterissuer/values.yaml | 12 +++++ 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 charts/enterprise/clusterissuer/templates/clusterissuer/_clusterCertificates.tpl diff --git a/charts/enterprise/clusterissuer/Chart.yaml b/charts/enterprise/clusterissuer/Chart.yaml index 25dd8f07af0..d8b31deeab2 100644 --- a/charts/enterprise/clusterissuer/Chart.yaml +++ b/charts/enterprise/clusterissuer/Chart.yaml @@ -10,7 +10,7 @@ keywords: dependencies: - name: common repository: https://library-charts.truecharts.org - version: 14.0.9 + version: 14.1.0 kubeVersion: ">=1.16.0-0" maintainers: - email: info@truecharts.org @@ -21,7 +21,7 @@ sources: - https://github.com/truecharts/charts/tree/master/charts/enterprise/clusterissuer - https://cert-manager.io/ type: application -version: 4.1.4 +version: 4.2.0 annotations: truecharts.org/category: core truecharts.org/SCALE-support: "true" diff --git a/charts/enterprise/clusterissuer/questions.yaml b/charts/enterprise/clusterissuer/questions.yaml index 2ae5abf1af0..e0a2c8266ea 100644 --- a/charts/enterprise/clusterissuer/questions.yaml +++ b/charts/enterprise/clusterissuer/questions.yaml @@ -329,6 +329,53 @@ questions: valid_chars: '^[a-z]+(-?[a-z]){0,63}-?[a-z]+$' default: "selfsigned" + - variable: clusterCertificates + group: App Configuration + label: Cluster Wide Certificates (Experimental) + description: "Creates certificates for use within the entire cluster. Can be used to create wildcard certificates." + schema: + additional_attrs: true + type: dict + attrs: + - variable: certificates + label: Cluster Certificates + schema: + type: list + default: [] + items: + - variable: enabled + label: Enabled + schema: + type: boolean + default: true + - variable: name + label: Certificate Name + schema: + type: string + required: true + default: "" + - variable: certificateIssuer + label: Cert-Manager clusterIssuer + description: "One of the Cert-Manager clusterIssuers defined above" + schema: + type: string + required: true + valid_chars: '^[a-z]+(-?[a-z]){0,63}-?[a-z]+$' + default: "selfsigned" + - variable: hosts + label: Certificate Hosts + description: "NOTE: Creation of wildcard certificates with an ACME issuer requires a DNSO1 solver to be set up." + schema: + type: list + default: [] + items: + - variable: host + label: Host + schema: + type: string + default: "" + required: true + - variable: customMetrics group: Metrics label: Prometheus Metrics diff --git a/charts/enterprise/clusterissuer/templates/clusterissuer/_clusterCertificates.tpl b/charts/enterprise/clusterissuer/templates/clusterissuer/_clusterCertificates.tpl new file mode 100644 index 00000000000..ef3da9464e5 --- /dev/null +++ b/charts/enterprise/clusterissuer/templates/clusterissuer/_clusterCertificates.tpl @@ -0,0 +1,36 @@ +{{- define "certmanager.clusterissuer.clusterCertificates" -}} + {{- if .Values.clusterCertificates -}} + {{- $certs := dict -}} + {{- $secretTemplates := dict -}} + {{- $certNamespace := (include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $ "objectData" $certs "caller" "ClusterCertificates")) -}} + {{- $replicationNamespaces := ".*" -}} + {{- if .Values.clusterCertificates.replicationNamespaces -}} + {{- $replicationNamespaces = .Values.clusterCertificates.replicationNamespaces -}} + {{- else if .Values.ixChartContext -}} + {{- $replicationNamespaces = "ix-.*" -}} + {{- end -}} + {{- $reflectorAnnotations := (dict + "reflector.v1.k8s.emberstack.com/reflection-allowed" "true" + "reflector.v1.k8s.emberstack.com/reflection-auto-enabled" "true" + "reflector.v1.k8s.emberstack.com/reflection-allowed-namespaces" (printf "%v,%v" $certNamespace $replicationNamespaces) + "reflector.v1.k8s.emberstack.com/reflection-auto-namespaces" $replicationNamespaces ) -}} + {{- $certAnnotations := (mustMerge ($reflectorAnnotations) (include "tc.v1.common.lib.metadata.allAnnotations" $ | fromYaml)) -}} + + {{- $_ := set $secretTemplates "annotations" $certAnnotations -}} + + {{- range .Values.clusterCertificates.certificates -}} + {{- $_ := set $certs .name dict -}} + {{- $currentCert := (index $certs (.name)) -}} + {{- $_ := set $currentCert "enabled" .enabled -}} + {{- $_ := set $currentCert "nameOverride" .name -}} + {{- $_ := set $currentCert "hosts" .hosts -}} + {{- $_ := set $currentCert "certificateIssuer" .certificateIssuer -}} + {{- $_ := set $currentCert "secretTemplate" $secretTemplates -}} + {{- end -}} + + {{- $_ := set .Values "cert" $certs -}} + {{/* Render the ClusterWide Certificate(s) */}} + {{- include "tc.v1.common.spawner.certificate" . | nindent 0 -}} + {{- end -}} +{{- end -}} + diff --git a/charts/enterprise/clusterissuer/templates/common.yaml b/charts/enterprise/clusterissuer/templates/common.yaml index 874f41f5c4e..8d713d12f0f 100644 --- a/charts/enterprise/clusterissuer/templates/common.yaml +++ b/charts/enterprise/clusterissuer/templates/common.yaml @@ -7,3 +7,8 @@ {{- include "certmanager.clusterissuer.acme" . }} {{- include "certmanager.clusterissuer.selfsigned" . }} {{- include "certmanager.clusterissuer.ca" . }} + +{{/* Must be called after the initial loader.apply template, + because it overrides .Values.cert in order to generate + the additional cluster-wide certificates */}} +{{- include "certmanager.clusterissuer.clusterCertificates" . }} diff --git a/charts/enterprise/clusterissuer/values.yaml b/charts/enterprise/clusterissuer/values.yaml index 51f5c994b2e..70218d5c15a 100644 --- a/charts/enterprise/clusterissuer/values.yaml +++ b/charts/enterprise/clusterissuer/values.yaml @@ -94,3 +94,15 @@ clusterIssuer: # fulldomain: "" # subdomain: "" # allowFrom: [] + +clusterCertificates: + # Namespaces in which the certificates must be available + # Accepts comma-separated regex expressions + # replicationNamespaces: 'ix-.*' + certificates: [] + # - name: mycert + # enabled: true + # certificateIssuer: selfsigned + # hosts: + # - my.domain.com + # - '*.my.domain.com'