diff --git a/charts/helm/checkmate/INSTALLATION.md b/charts/helm/checkmate/INSTALLATION.md index c4586cd85..74e58c097 100644 --- a/charts/helm/checkmate/INSTALLATION.md +++ b/charts/helm/checkmate/INSTALLATION.md @@ -53,10 +53,11 @@ If you have [cert-manager](https://cert-manager.io/) installed in your cluster, ### Configuration -Edit `values.yaml` to enable TLS: +Edit `values.yaml` to enable TLS (and update protocols to https): ```yaml client: + protocol: https ingress: enabled: true host: checkmate.example.com @@ -68,6 +69,7 @@ client: secretName: checkmate-client-tls server: + protocol: https ingress: enabled: true host: checkmate.example.com diff --git a/charts/helm/checkmate/templates/_prechecks.yaml b/charts/helm/checkmate/templates/_prechecks.yaml index 870ab5c77..235bc0b8f 100644 --- a/charts/helm/checkmate/templates/_prechecks.yaml +++ b/charts/helm/checkmate/templates/_prechecks.yaml @@ -6,7 +6,36 @@ {{- fail "server.ingress.host must be overridden and not set to 'change_me'" }} {{- end }} -{{- $protocol := .Values.server.protocol }} -{{- if not (or (eq $protocol "http") (eq $protocol "https")) }} +{{- $serverProtocol := .Values.server.protocol }} +{{- if not (or (eq $serverProtocol "http") (eq $serverProtocol "https")) }} {{- fail "server.protocol must be either 'http' or 'https'" }} {{- end }} + +{{- $clientProtocol := .Values.client.protocol }} +{{- if not (or (eq $clientProtocol "http") (eq $clientProtocol "https")) }} + {{- fail "client.protocol must be either 'http' or 'https'" }} +{{- end }} + +{{/* Enforce protocol when TLS is enabled to avoid mixed-content */}} +{{- if and .Values.client.ingress.tls.enabled (ne $clientProtocol "https") }} + {{- fail "client.ingress.tls.enabled is true but client.protocol is not 'https'. Set client.protocol: https to avoid mixed content." }} +{{- end }} + +{{- if and .Values.server.ingress.tls.enabled (ne $serverProtocol "https") }} + {{- fail "server.ingress.tls.enabled is true but server.protocol is not 'https'. Set server.protocol: https to ensure correct API base URL." }} +{{- end }} + +{{/* Fail early if TLS enabled without cert-manager annotations (cluster-issuer or issuer) */}} +{{- $cAnn := .Values.client.ingress.annotations | default dict }} +{{- $sAnn := .Values.server.ingress.annotations | default dict }} + +{{- $clientHasIssuer := or (hasKey $cAnn "cert-manager.io/cluster-issuer") (hasKey $cAnn "cert-manager.io/issuer") }} +{{- $serverHasIssuer := or (hasKey $sAnn "cert-manager.io/cluster-issuer") (hasKey $sAnn "cert-manager.io/issuer") }} + +{{- if and .Values.client.ingress.tls.enabled (not $clientHasIssuer) }} + {{- fail "client.ingress.tls.enabled is true but no cert-manager issuer annotation found. Add 'cert-manager.io/cluster-issuer' or 'cert-manager.io/issuer'." }} +{{- end }} + +{{- if and .Values.server.ingress.tls.enabled (not $serverHasIssuer) }} + {{- fail "server.ingress.tls.enabled is true but no cert-manager issuer annotation found. Add 'cert-manager.io/cluster-issuer' or 'cert-manager.io/issuer'." }} +{{- end }} diff --git a/charts/helm/checkmate/templates/prechecks.yaml b/charts/helm/checkmate/templates/prechecks.yaml new file mode 100644 index 000000000..d9264d60c --- /dev/null +++ b/charts/helm/checkmate/templates/prechecks.yaml @@ -0,0 +1,55 @@ +{{- if eq .Values.client.ingress.host "change_me" }} + {{- fail "client.ingress.host must be overridden and not set to 'change_me'" }} +{{- end }} + +{{- if eq .Values.server.ingress.host "change_me" }} + {{- fail "server.ingress.host must be overridden and not set to 'change_me'" }} +{{- end }} + +{{- $serverProtocol := .Values.server.protocol }} +{{- if not (or (eq $serverProtocol "http") (eq $serverProtocol "https")) }} + {{- fail "server.protocol must be either 'http' or 'https'" }} +{{- end }} + +{{- $clientProtocol := .Values.client.protocol }} +{{- if not (or (eq $clientProtocol "http") (eq $clientProtocol "https")) }} + {{- fail "client.protocol must be either 'http' or 'https'" }} +{{- end }} + +{{/* Enforce protocol when TLS is enabled to avoid mixed-content */}} +{{- if and .Values.client.ingress.tls.enabled (ne $clientProtocol "https") }} + {{- fail "client.ingress.tls.enabled is true but client.protocol is not 'https'. Set client.protocol: https to avoid mixed content." }} +{{- end }} + +{{- if and .Values.server.ingress.tls.enabled (ne $serverProtocol "https") }} + {{- fail "server.ingress.tls.enabled is true but server.protocol is not 'https'. Set server.protocol: https to ensure correct API base URL." }} +{{- end }} + +{{/* If client runs on https, API must also be https to avoid mixed content */}} +{{- if and (eq $clientProtocol "https") (ne $serverProtocol "https") }} + {{- fail "client.protocol is 'https' but server.protocol is not. Set server.protocol: https to prevent browser mixed-content issues." }} +{{- end }} + +{{/* Fail early if TLS enabled without cert-manager annotations (cluster-issuer or issuer) */}} +{{- $cAnn := .Values.client.ingress.annotations | default dict }} +{{- $sAnn := .Values.server.ingress.annotations | default dict }} + +{{- $clientHasIssuer := or (hasKey $cAnn "cert-manager.io/cluster-issuer") (hasKey $cAnn "cert-manager.io/issuer") }} +{{- $serverHasIssuer := or (hasKey $sAnn "cert-manager.io/cluster-issuer") (hasKey $sAnn "cert-manager.io/issuer") }} + +{{- if and .Values.client.ingress.tls.enabled (not $clientHasIssuer) }} + {{- fail "client.ingress.tls.enabled is true but no cert-manager issuer annotation found. Add 'cert-manager.io/cluster-issuer' or 'cert-manager.io/issuer'." }} +{{- end }} + +{{- if and .Values.server.ingress.tls.enabled (not $serverHasIssuer) }} + {{- fail "server.ingress.tls.enabled is true but no cert-manager issuer annotation found. Add 'cert-manager.io/cluster-issuer' or 'cert-manager.io/issuer'." }} +{{- end }} + +{{/* Secret name must be set when TLS is enabled (Ingress requires it) */}} +{{- if and .Values.client.ingress.tls.enabled (not .Values.client.ingress.tls.secretName) }} + {{- fail "client.ingress.tls.enabled is true but client.ingress.tls.secretName is empty. Set a secretName for cert-manager to manage." }} +{{- end }} + +{{- if and .Values.server.ingress.tls.enabled (not .Values.server.ingress.tls.secretName) }} + {{- fail "server.ingress.tls.enabled is true but server.ingress.tls.secretName is empty. Set a secretName for cert-manager to manage." }} +{{- end }} diff --git a/charts/helm/checkmate/values.yaml b/charts/helm/checkmate/values.yaml index 48e312da8..5ca09a007 100644 --- a/charts/helm/checkmate/values.yaml +++ b/charts/helm/checkmate/values.yaml @@ -13,6 +13,8 @@ client: tls: enabled: false # secretName: checkmate-client-tls # Uncomment and set if using TLS with cert-manager + # Note: when enabling TLS, also set client.protocol: https and add + # a cert-manager issuer annotation (e.g. cert-manager.io/cluster-issuer: "letsencrypt-prod"). # The secret will be automatically created by cert-manager when using the cert-manager.io/cluster-issuer annotation server: @@ -30,6 +32,8 @@ server: tls: enabled: false # secretName: checkmate-server-tls # Uncomment and set if using TLS with cert-manager + # Note: when enabling TLS, also set server.protocol: https and add + # a cert-manager issuer annotation (e.g. cert-manager.io/cluster-issuer: "letsencrypt-prod"). # The secret will be automatically created by cert-manager when using the cert-manager.io/cluster-issuer annotation redis: