From 13f6bda4cbb94e4eaae4ef6f52d9ed8314813a66 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Sun, 29 Nov 2026 17:20:51 -0800 Subject: [PATCH] Add a Gateway API HTTPRoute for the Rspamd web interface rspamd.httpRoute is the Gateway API counterpart of rspamd.ingress: it routes a hostname on an existing Gateway to the Rspamd port on the internal Service. Co-Authored-By: Claude Opus 5.5 --- charts/docker-mailserver/README.md | 15 ++++- .../templates/httproute-rspamd.yaml | 36 +++++++++++ .../tests/httproute_test.yaml | 62 +++++++++++++++++++ charts/docker-mailserver/values.yaml | 12 ++++ 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 charts/docker-mailserver/templates/httproute-rspamd.yaml create mode 100644 charts/docker-mailserver/tests/httproute_test.yaml diff --git a/charts/docker-mailserver/README.md b/charts/docker-mailserver/README.md index f754c61..3f67025 100644 --- a/charts/docker-mailserver/README.md +++ b/charts/docker-mailserver/README.md @@ -251,10 +251,23 @@ If you do not enable the PROXY protocol and your mail server is not exposed usin ### Rspamd web interface and metrics -The Rspamd web interface (port 11334) and the metrics exporter (`monitoring.service.port`, 9102 by default) are not on the main Service. They are on a separate ClusterIP Service named `-internal`, so a main Service of type `LoadBalancer` or `NodePort` never publishes them outside the cluster. The Rspamd ingress (`rspamd.ingress`) and the ServiceMonitor (`metrics.serviceMonitor`) use the internal Service, and it carries the `prometheus.io/*` annotations. `service.labels`, `service.ipFamilyPolicy` and `service.ipFamilies` apply to both Services. +The Rspamd web interface (port 11334) and the metrics exporter (`monitoring.service.port`, 9102 by default) are not on the main Service. They are on a separate ClusterIP Service named `-internal`, so a main Service of type `LoadBalancer` or `NodePort` never publishes them outside the cluster. The Rspamd ingress (`rspamd.ingress`), the Rspamd HTTPRoute (`rspamd.httpRoute`) and the ServiceMonitor (`metrics.serviceMonitor`) use the internal Service, and it carries the `prometheus.io/*` annotations. `service.labels`, `service.ipFamilyPolicy` and `service.ipFamilies` apply to both Services. If you reached the Rspamd web interface or scraped the metrics through the main Service before (a port-forward, an annotation-based scrape, or an external address), use `-internal` instead. +To expose the web interface through the [Gateway API](https://gateway-api.sigs.k8s.io/) instead of an ingress, enable `rspamd.httpRoute` and set `rspamd.httpRoute.parentRefs` to your Gateway: + +```yaml +rspamd: + httpRoute: + enabled: true + parentRefs: + - name: gateway + namespace: gateway-system + hostnames: + - rspamd.example.com +``` + ## Persistence Docker-mailserver assumes there are [four](https://docker-mailserver.github.io/docker-mailserver/latest/config/advanced/optional-config/#volumes) mounted volumes: diff --git a/charts/docker-mailserver/templates/httproute-rspamd.yaml b/charts/docker-mailserver/templates/httproute-rspamd.yaml new file mode 100644 index 0000000..49ba703 --- /dev/null +++ b/charts/docker-mailserver/templates/httproute-rspamd.yaml @@ -0,0 +1,36 @@ +{{- if and (.Values.deployment.env.ENABLE_RSPAMD) (.Values.rspamd.httpRoute.enabled) -}} +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + labels: + app.kubernetes.io/name: {{ template "dockermailserver.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" +{{- with .Values.rspamd.httpRoute.labels }} +{{ toYaml . | indent 4 }} +{{- end }} + name: {{ template "dockermailserver.fullname" . }}-rspamd +{{- with .Values.rspamd.httpRoute.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: + parentRefs: +{{- if not .Values.rspamd.httpRoute.parentRefs }} +{{- fail "rspamd.httpRoute.parentRefs is required" }} +{{- end }} +{{ toYaml .Values.rspamd.httpRoute.parentRefs | indent 4 }} +{{- with .Values.rspamd.httpRoute.hostnames }} + hostnames: +{{ toYaml . | indent 4 }} +{{- end }} + rules: + - matches: + - path: + type: PathPrefix + value: {{ .Values.rspamd.httpRoute.path }} + backendRefs: + - name: {{ template "dockermailserver.fullname" . }}-internal + port: 11334 +{{- end }} diff --git a/charts/docker-mailserver/tests/httproute_test.yaml b/charts/docker-mailserver/tests/httproute_test.yaml new file mode 100644 index 0000000..eaf595c --- /dev/null +++ b/charts/docker-mailserver/tests/httproute_test.yaml @@ -0,0 +1,62 @@ +suite: rspamd httproute tests +templates: + - httproute-rspamd.yaml +chart: + version: 0.1.0 + appVersion: 0.1.0 +values: + - ../values.yaml +tests: + - it: is not rendered by default + asserts: + - hasDocuments: + count: 0 + + - it: routes to the rspamd port on the internal service + set: + rspamd.httpRoute.enabled: true + rspamd.httpRoute.parentRefs: + - name: gateway + namespace: gateway-system + sectionName: https + rspamd.httpRoute.hostnames: + - rspamd.example.com + asserts: + - isKind: + of: HTTPRoute + - matchRegex: + path: metadata.name + pattern: -docker-mailserver-rspamd$ + - equal: + path: spec.parentRefs[0].name + value: gateway + - equal: + path: spec.hostnames + value: + - rspamd.example.com + - equal: + path: spec.rules[0].matches[0].path.value + value: / + - matchRegex: + path: spec.rules[0].backendRefs[0].name + pattern: -docker-mailserver-internal$ + - equal: + path: spec.rules[0].backendRefs[0].port + value: 11334 + + - it: is not rendered when rspamd is disabled + set: + deployment.env.ENABLE_RSPAMD: 0 + rspamd.httpRoute.enabled: true + rspamd.httpRoute.parentRefs: + - name: gateway + asserts: + - hasDocuments: + count: 0 + + - it: requires parentRefs + set: + rspamd.httpRoute.enabled: true + asserts: + - failedTemplate: + errorMessage: rspamd.httpRoute.parentRefs is required diff --git a/charts/docker-mailserver/values.yaml b/charts/docker-mailserver/values.yaml index 8331340..2d4a35d 100644 --- a/charts/docker-mailserver/values.yaml +++ b/charts/docker-mailserver/values.yaml @@ -455,6 +455,18 @@ rspamd: tls: enabled: false secret: + httpRoute: + enabled: false + annotations: {} + labels: {} + # Gateways (or listeners) to attach to, for example: + # - name: gateway + # namespace: gateway-system + # sectionName: https + parentRefs: [] + hostnames: [] + # - rspamd.example.com + path: / dovecot: # Full text search using Dovecot's flatcurve plugin. See