From ee70b036cd7d82445e49b0a650bf4acbb0c07698 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Thu, 19 Nov 2026 07:15:19 -0700 Subject: [PATCH] Certificates for the mail ports: TLS Secrets, cert-manager, ACME routes (K-C8) server.certificates.secrets mounts TLS Secrets in every server pod, whole directories so a renewal reaches the pod, and names them in INBUXA_TLS_CERTIFICATE_DIRS. certManager has the chart make a cert-manager Certificate for the mail names and mount its Secret. acmeHosts routes the server's own ACME HTTP-01 challenges for those names to it, through the Gateway or the Ingress. Needs server 27.1-rc.33. --- CHANGELOG.md | 6 ++ charts/inbuxa/ci/everything-values.yaml | 7 ++ charts/inbuxa/templates/_helpers.tpl | 23 ++++++ charts/inbuxa/templates/routes.yaml | 59 ++++++++++++++ .../inbuxa/templates/server/certificate.yaml | 41 ++++++++++ .../inbuxa/templates/server/deployment.yaml | 21 +++++ charts/inbuxa/tests/certificates_test.yaml | 79 +++++++++++++++++++ charts/inbuxa/tests/frontends_test.yaml | 57 +++++++++++++ charts/inbuxa/values.schema.json | 32 ++++++++ charts/inbuxa/values.yaml | 24 ++++++ 10 files changed, 349 insertions(+) create mode 100644 charts/inbuxa/templates/server/certificate.yaml create mode 100644 charts/inbuxa/tests/certificates_test.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index a964bc4..c873410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,12 @@ runs, pinned by digest. passwords between all users would ban the ingress for everyone. `server.trustedProxies` lists the proxies when the pod network isn't a private range. Needs server 27.1-rc.32; older servers ignore it. +- Certificates for the mail ports (`server.certificates`): TLS Secrets + (`secrets`, or `certManager` to have the chart ask cert-manager for one) + mounted in every server pod and reread within about two minutes of a + renewal, with no restart; and `acmeHosts`, which routes the server's own + ACME HTTP-01 challenges for the mail names to it. Needs server + 27.1-rc.33. - Mail out from a known address (`server.egress`): with `expectedAddresses` and `checkUrl` set, a Job placed like the mta pods asks which address it leaves from after each install and upgrade, and diff --git a/charts/inbuxa/ci/everything-values.yaml b/charts/inbuxa/ci/everything-values.yaml index b2f8cd5..aad1485 100644 --- a/charts/inbuxa/ci/everything-values.yaml +++ b/charts/inbuxa/ci/everything-values.yaml @@ -22,6 +22,13 @@ server: trustedProxies: [10.0.0.0/8, 100.64.0.0/10] listeners: pop3s: 995 + certificates: + acmeHosts: [mx.example.org] + secrets: [mail-tls] + certManager: + enabled: true + issuerRef: {name: letsencrypt, kind: ClusterIssuer} + dnsNames: [mail.example.org, mx.example.org] egress: expectedAddresses: [198.51.100.7, "2001:db8::7"] checkUrl: https://ip.example.org/ diff --git a/charts/inbuxa/templates/_helpers.tpl b/charts/inbuxa/templates/_helpers.tpl index c55425c..146ca49 100644 --- a/charts/inbuxa/templates/_helpers.tpl +++ b/charts/inbuxa/templates/_helpers.tpl @@ -154,3 +154,26 @@ Call with (dict "url" .Values.webmail.publicUrl "name" "webmail"). {{- toYaml . | nindent 4 }} {{- end }} {{- end -}} + +{{/* +The TLS Secrets mounted in the server pods, space-separated: the ones named +in server.certificates.secrets, and the one cert-manager issues for the +chart. +*/}} +{{- define "inbuxa.server.tlsSecrets" -}} +{{- $c := .Values.server.certificates }} +{{- $names := $c.secrets }} +{{- if $c.certManager.enabled }} +{{- $names = append $names (printf "%s-mail-tls" (include "inbuxa.fullname" .)) }} +{{- end }} +{{- join " " (uniq $names) }} +{{- end }} + +{{/* INBUXA_TLS_CERTIFICATE_DIRS for a list of TLS Secret names */}} +{{- define "inbuxa.server.tlsDirs" -}} +{{- $dirs := list }} +{{- range . }} +{{- $dirs = append $dirs (printf "/etc/inbuxa/tls/%s" .) }} +{{- end }} +{{- join "," $dirs }} +{{- end }} diff --git a/charts/inbuxa/templates/routes.yaml b/charts/inbuxa/templates/routes.yaml index d0c1bf8..d4fddfa 100644 --- a/charts/inbuxa/templates/routes.yaml +++ b/charts/inbuxa/templates/routes.yaml @@ -5,6 +5,11 @@ SPDX-License-Identifier: Apache-2.0 Routes from outside, one per public address, by host name: the server's publicUrl to its HTTP Service, and the webmail's and the console's to theirs. Gateway API HTTPRoutes, or an Ingress where there's no Gateway. + +For the server's own ACME with HTTP-01, the names in +server.certificates.acmeHosts get one more route: their +/.well-known/acme-challenge/ to the server, which answers the challenge on +any pod. A name the server's publicUrl already routes needs nothing more. */}} {{- $root := . }} {{- $routes := .Values.routes }} @@ -26,6 +31,19 @@ theirs. Gateway API HTTPRoutes, or an Ingress where there's no Gateway. {{- end }} {{- $_ := set $hosts .host .name }} {{- end }} +{{- $acmeHosts := list }} +{{- range .Values.server.certificates.acmeHosts }} +{{- if ne (get $hosts .) "server" }} +{{- if hasKey $hosts . }} +{{- fail (printf "server.certificates.acmeHosts: %s is the %s's host; the server's ACME challenges can't share it" . (get $hosts .)) }} +{{- end }} +{{- $acmeHosts = append $acmeHosts . }} +{{- end }} +{{- end }} +{{- $acmeHosts = uniq $acmeHosts }} +{{- if and $acmeHosts (not (or $routes.gateway.enabled $routes.ingress.enabled)) }} +{{- fail "server.certificates.acmeHosts: turn on routes.gateway or routes.ingress to route the challenges, or use DNS-01" }} +{{- end }} {{- if and $routes.gateway.enabled $routes.ingress.enabled }} {{- fail "routes: turn on gateway or ingress, not both" }} {{- end }} @@ -64,6 +82,35 @@ spec: - name: {{ .service }} port: 8080 {{- end }} +{{- if $acmeHosts }} +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ printf "%s-acme" $full }} + namespace: {{ $root.Release.Namespace }} + labels: + {{- include "inbuxa.labels" $root | nindent 4 }} + app.kubernetes.io/component: server + {{- with $routes.gateway.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + # The Gateway needs an HTTP listener on port 80 for these names + parentRefs: + {{- toYaml $routes.gateway.parentRefs | nindent 4 }} + hostnames: + {{- toYaml $acmeHosts | nindent 4 }} + rules: + - matches: + - path: + type: PathPrefix + value: /.well-known/acme-challenge/ + backendRefs: + - name: {{ printf "%s-http" $full }} + port: 8080 +{{- end }} {{- end }} {{- if $routes.ingress.enabled }} --- @@ -99,4 +146,16 @@ spec: port: name: http {{- end }} + {{- range $acmeHosts }} + - host: {{ . | quote }} + http: + paths: + - path: /.well-known/acme-challenge/ + pathType: Prefix + backend: + service: + name: {{ printf "%s-http" $full }} + port: + name: http + {{- end }} {{- end }} diff --git a/charts/inbuxa/templates/server/certificate.yaml b/charts/inbuxa/templates/server/certificate.yaml new file mode 100644 index 0000000..d3870f1 --- /dev/null +++ b/charts/inbuxa/templates/server/certificate.yaml @@ -0,0 +1,41 @@ +{{/* +SPDX-FileCopyrightText: 2026 Coffey Labs LLC +SPDX-License-Identifier: Apache-2.0 + +A cert-manager Certificate for the mail host names, when +server.certificates.certManager is on. cert-manager keeps it in the Secret +-mail-tls; the server pods mount it and reread it when it's +renewed. Until it's first issued, the pods wait for the Secret. +*/}} +{{- $root := . }} +{{- $cm := .Values.server.certificates.certManager }} +{{- if $cm.enabled }} +{{- if not $cm.issuerRef.name }} +{{- fail "server.certificates.certManager.issuerRef: name the Issuer or ClusterIssuer" }} +{{- end }} +{{- if not $cm.dnsNames }} +{{- fail "server.certificates.certManager.dnsNames: name the mail host names" }} +{{- end }} +{{- $name := printf "%s-mail-tls" (include "inbuxa.fullname" $root) }} +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: {{ $name }} + namespace: {{ $root.Release.Namespace }} + labels: + {{- include "inbuxa.labels" $root | nindent 4 }} + app.kubernetes.io/component: server +spec: + secretName: {{ $name }} + dnsNames: + {{- toYaml $cm.dnsNames | nindent 4 }} + issuerRef: + name: {{ $cm.issuerRef.name }} + kind: {{ $cm.issuerRef.kind | default "Issuer" }} + group: {{ $cm.issuerRef.group | default "cert-manager.io" }} + {{- with $cm.renewBefore }} + renewBefore: {{ . }} + {{- end }} + privateKey: + rotationPolicy: Always +{{- end }} diff --git a/charts/inbuxa/templates/server/deployment.yaml b/charts/inbuxa/templates/server/deployment.yaml index cb5e4a8..c6ad2fa 100644 --- a/charts/inbuxa/templates/server/deployment.yaml +++ b/charts/inbuxa/templates/server/deployment.yaml @@ -8,6 +8,7 @@ are interchangeable: Deployments, not StatefulSets. */}} {{- $root := . }} {{- $server := .Values.server }} +{{- $tlsSecrets := splitList " " (include "inbuxa.server.tlsSecrets" $root) | compact }} {{- range $group := list "front" "mta" "core" }} {{- $g := index $server.groups $group }} {{- if $g.enabled }} @@ -191,6 +192,11 @@ spec: # sign-ins and anonymous requests aren't charged to the proxy - name: INBUXA_HTTP_USE_FORWARDED value: "true" + {{- if $tlsSecrets }} + # Certificates from TLS Secrets, reread when they're renewed + - name: INBUXA_TLS_CERTIFICATE_DIRS + value: {{ include "inbuxa.server.tlsDirs" $tlsSecrets | quote }} + {{- end }} {{- with $server.trustedProxies }} - name: INBUXA_HTTP_TRUSTED_PROXIES value: {{ join "," . | quote }} @@ -281,6 +287,12 @@ spec: mountPath: /etc/inbuxa/webmail readOnly: true {{- end }} + {{- range $i, $name := $tlsSecrets }} + # A whole directory, never a subPath: a renewal reaches the pod + - name: tls-{{ $i }} + mountPath: /etc/inbuxa/tls/{{ $name }} + readOnly: true + {{- end }} - name: data mountPath: /var/lib/inbuxa - name: tmp @@ -313,6 +325,15 @@ spec: path: oauth-client-secret {{- end }} {{- end }} + {{- range $i, $name := $tlsSecrets }} + - name: tls-{{ $i }} + secret: + secretName: {{ $name }} + defaultMode: 0440 + items: + - {key: tls.crt, path: tls.crt} + - {key: tls.key, path: tls.key} + {{- end }} # Scratch only: everything lasting is in the data store - name: data emptyDir: {} diff --git a/charts/inbuxa/tests/certificates_test.yaml b/charts/inbuxa/tests/certificates_test.yaml new file mode 100644 index 0000000..01d5351 --- /dev/null +++ b/charts/inbuxa/tests/certificates_test.yaml @@ -0,0 +1,79 @@ +# SPDX-FileCopyrightText: 2026 Coffey Labs LLC +# SPDX-License-Identifier: Apache-2.0 +suite: certificates +templates: + - server/certificate.yaml + - server/deployment.yaml +release: + name: mail + namespace: inbuxa +values: + - ../ci/defaults-values.yaml +tests: + - it: mounts no certificates unless asked + template: server/deployment.yaml + documentIndex: 0 + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: {name: INBUXA_TLS_CERTIFICATE_DIRS} + any: true + + - it: asks cert-manager for nothing unless asked + template: server/certificate.yaml + asserts: + - hasDocuments: + count: 0 + + - it: mounts each TLS Secret whole, so renewals reach the pod + template: server/deployment.yaml + set: + server.certificates.secrets: [mail-tls, mx-tls] + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: {name: INBUXA_TLS_CERTIFICATE_DIRS, value: "/etc/inbuxa/tls/mail-tls,/etc/inbuxa/tls/mx-tls"} + documentIndex: 1 + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: {name: tls-1, mountPath: /etc/inbuxa/tls/mx-tls, readOnly: true} + documentIndex: 2 + - contains: + path: spec.template.spec.volumes + content: + name: tls-0 + secret: + secretName: mail-tls + defaultMode: 0440 + items: [{key: tls.crt, path: tls.crt}, {key: tls.key, path: tls.key}] + documentIndex: 0 + + - it: asks cert-manager for the mail names, and mounts what it issues + set: + server.certificates.certManager: + enabled: true + issuerRef: {name: letsencrypt, kind: ClusterIssuer} + dnsNames: [mail.example.org, mx.example.org] + asserts: + - equal: + path: spec + value: + secretName: mail-inbuxa-mail-tls + dnsNames: [mail.example.org, mx.example.org] + issuerRef: {name: letsencrypt, kind: ClusterIssuer, group: cert-manager.io} + privateKey: {rotationPolicy: Always} + template: server/certificate.yaml + - contains: + path: spec.template.spec.containers[0].env + content: {name: INBUXA_TLS_CERTIFICATE_DIRS, value: /etc/inbuxa/tls/mail-inbuxa-mail-tls} + template: server/deployment.yaml + documentIndex: 0 + + - it: needs an issuer and names + template: server/certificate.yaml + set: + server.certificates.certManager.enabled: true + server.certificates.certManager.dnsNames: [mail.example.org] + asserts: + - failedTemplate: + errorPattern: issuerRef diff --git a/charts/inbuxa/tests/frontends_test.yaml b/charts/inbuxa/tests/frontends_test.yaml index 4d85784..21750f3 100644 --- a/charts/inbuxa/tests/frontends_test.yaml +++ b/charts/inbuxa/tests/frontends_test.yaml @@ -269,3 +269,60 @@ tests: asserts: - failedTemplate: errorPattern: "routes.gateway.parentRefs" + + - it: sends the ACME challenges for the mail host names to the server + template: routes.yaml + set: + routes.gateway.enabled: true + routes.gateway.parentRefs: [{name: public, namespace: gateway}] + server.certificates.acmeHosts: [mx.example.org, mail.example.org, mx.example.org] + asserts: + - hasDocuments: + count: 4 + - equal: + path: metadata.name + value: mail-inbuxa-acme + documentIndex: 3 + - equal: + path: spec.hostnames + value: [mx.example.org] + documentIndex: 3 + - equal: + path: spec.rules[0] + value: + matches: [{path: {type: PathPrefix, value: /.well-known/acme-challenge/}}] + backendRefs: [{name: mail-inbuxa-http, port: 8080}] + documentIndex: 3 + + - it: and through the Ingress + template: routes.yaml + set: + routes.ingress.enabled: true + server.certificates.acmeHosts: [mx.example.org] + asserts: + - equal: + path: spec.rules[3] + value: + host: mx.example.org + http: + paths: + - path: /.well-known/acme-challenge/ + pathType: Prefix + backend: {service: {name: mail-inbuxa-http, port: {name: http}}} + + - it: refuses an ACME host that's a front end's + template: routes.yaml + set: + routes.ingress.enabled: true + server.certificates.acmeHosts: [webmail.example.org] + asserts: + - failedTemplate: + errorPattern: "webmail.example.org is the webmail's host" + + - it: refuses ACME hosts with no routes to carry them + template: routes.yaml + set: + server.certificates.acmeHosts: [mx.example.org] + asserts: + - failedTemplate: + errorPattern: "turn on routes.gateway or routes.ingress" diff --git a/charts/inbuxa/values.schema.json b/charts/inbuxa/values.schema.json index 9423528..ef97a49 100644 --- a/charts/inbuxa/values.schema.json +++ b/charts/inbuxa/values.schema.json @@ -246,6 +246,38 @@ } } }, + "certificates": { + "type": "object", + "additionalProperties": false, + "properties": { + "acmeHosts": { + "type": "array", + "items": {"type": "string", "pattern": "^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$"} + }, + "secrets": { + "type": "array", + "items": {"type": "string", "pattern": "^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$"} + }, + "certManager": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": {"type": "boolean"}, + "issuerRef": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": {"type": "string"}, + "kind": {"type": "string", "enum": ["Issuer", "ClusterIssuer"]}, + "group": {"type": "string"} + } + }, + "dnsNames": {"type": "array", "items": {"type": "string"}}, + "renewBefore": {"type": "string"} + } + } + } + }, "egress": { "type": "object", "additionalProperties": false, diff --git a/charts/inbuxa/values.yaml b/charts/inbuxa/values.yaml index d73633f..260608b 100644 --- a/charts/inbuxa/values.yaml +++ b/charts/inbuxa/values.yaml @@ -181,6 +181,30 @@ server: expectedAddresses: [] checkUrl: "" + # Certificates for the mail ports (SMTP STARTTLS, submissions, IMAPS, + # POP3S, ManageSieve). HTTPS from outside is the Gateway's or the + # Ingress's (routes below). Two ways: + # - The server's own ACME (an ACME provider set up in the seed or the + # console): certificates are kept in the store, and every pod uses them. + # DNS-01 needs nothing here. For HTTP-01, name the hosts in acmeHosts: + # the routes send their /.well-known/acme-challenge/ to the server. + # - TLS Secrets (kubernetes.io/tls), mounted in every server pod and used + # as they are: existing ones in secrets, or certManager to have the + # chart ask cert-manager for one. The pods reread them within about two + # minutes of a renewal, with no restart. Needs server 27.1-rc.33. + certificates: + acmeHosts: [] + # Names of Secrets in this namespace, each with tls.crt and tls.key + secrets: [] + certManager: + enabled: false + # The Issuer or ClusterIssuer, e.g. {name: letsencrypt, kind: ClusterIssuer} + issuerRef: {} + # The mail host names, e.g. [mail.example.org, mx.example.org] + dnsNames: [] + # Renew this long before expiry; empty is cert-manager's default + renewBefore: "" + # Used for every group that sets no resources of its own resources: requests: -- 2.54.0