From 937aecc8f7b8889f06f4b53a7ff6281df3c085e9 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Wed, 18 Nov 2026 17:06:29 -0700 Subject: [PATCH] webmail: secrets as mounted files, and check the read-only root The webmail reads app-secret and oauth-client-secret from the mounted Secret (APP_SECRET_FILE, OAUTH_CLIENT_SECRET_FILE) instead of its environment, with fsGroup 1000 so it can read them. IMMUTABLE=1 makes it refuse to start on a writable root. webmail.previousAppSecret reads app-secret-previous from existingSecret during a rotation. Needs webmail 27.1-rc.7 or later. --- CHANGELOG.md | 7 ++- charts/inbuxa/templates/webmail.yaml | 45 ++++++++++--------- charts/inbuxa/tests/frontends_test.yaml | 60 +++++++++++++++++++++---- charts/inbuxa/values.schema.json | 3 ++ charts/inbuxa/values.yaml | 11 +++-- 5 files changed, 91 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be2e584..2c6810c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,10 @@ runs, pinned by digest. webmail keeps sessions in sealed cookies, so any replica serves any request, and signs in through the server's page. Its app and OAuth client secrets are a Secret the chart makes (kept across upgrades) or - `webmail.existingSecret`. Every server pod is told both addresses, so it - registers them as OAuth clients. + `webmail.existingSecret`, mounted as files rather than set in its + environment; `webmail.previousAppSecret` reads the old app secret during a + rotation. The webmail checks its read-only root at start (`IMMUTABLE`). + Every server pod is told both addresses, so it registers them as OAuth + clients. - `routes`: the server's, the webmail's and the console's public addresses, each by host name, as Gateway API HTTPRoutes or one Ingress. diff --git a/charts/inbuxa/templates/webmail.yaml b/charts/inbuxa/templates/webmail.yaml index 98f2576..eca0d91 100644 --- a/charts/inbuxa/templates/webmail.yaml +++ b/charts/inbuxa/templates/webmail.yaml @@ -16,6 +16,9 @@ the server inside the cluster, through the HTTP Service. {{- end }} {{- $name := printf "%s-webmail" (include "inbuxa.fullname" $root) }} {{- $secretName := default $name $wm.existingSecret }} +{{- if and $wm.previousAppSecret (not $wm.existingSecret) }} +{{- fail "webmail.previousAppSecret needs webmail.existingSecret: the chart's own Secret keeps only the two keys it makes" }} +{{- end }} {{- if not $wm.existingSecret }} {{- /* Random once, then kept: a new APP_SECRET would sign everybody out */}} {{- $existing := (lookup "v1" "Secret" $root.Release.Namespace $name).data | default dict }} @@ -42,10 +45,7 @@ metadata: {{- include "inbuxa.labels" $root | nindent 4 }} app.kubernetes.io/component: webmail annotations: - ignore-check.kube-linter.io/read-secret-from-env-var: "TODO(K-W4): the webmail reads its secrets from the environment until it takes *_FILE" - {{- if $wm.existingSecret }} - ignore-check.kube-linter.io/env-value-from: "existingSecret is the operator's, made outside the chart" - {{- end }} + ignore-check.kube-linter.io/env-var-secret: "the *_SECRET_FILE variables hold paths to the mounted Secret, not secrets" spec: {{- if not $wm.autoscaling.enabled }} replicas: {{ $wm.replicas }} @@ -82,6 +82,8 @@ spec: # node, in the image runAsUser: 1000 runAsGroup: 1000 + # Owns the mounted secret files (mode 0440) + fsGroup: 1000 seccompProfile: type: RuntimeDefault terminationGracePeriodSeconds: 30 @@ -133,22 +135,18 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name - - name: APP_SECRET - valueFrom: - secretKeyRef: - name: {{ $secretName }} - key: app-secret - - name: APP_SECRET_PREVIOUS - valueFrom: - secretKeyRef: - name: {{ $secretName }} - key: app-secret-previous - optional: true - - name: OAUTH_CLIENT_SECRET - valueFrom: - secretKeyRef: - name: {{ $secretName }} - key: oauth-client-secret + # Checked at start: a read-only root, nothing kept on disk + - name: IMMUTABLE + value: "1" + # Secrets as files, never in the environment + - name: APP_SECRET_FILE + value: /etc/inbuxa-webmail/app-secret + {{- if $wm.previousAppSecret }} + - name: APP_SECRET_PREVIOUS_FILE + value: /etc/inbuxa-webmail/app-secret-previous + {{- end }} + - name: OAUTH_CLIENT_SECRET_FILE + value: /etc/inbuxa-webmail/oauth-client-secret {{- with $wm.extraEnv }} {{- toYaml . | nindent 12 }} {{- end }} @@ -179,10 +177,17 @@ spec: volumeMounts: - name: tmp mountPath: /tmp + - name: secrets + mountPath: /etc/inbuxa-webmail + readOnly: true volumes: - name: tmp emptyDir: sizeLimit: 64Mi + - name: secrets + secret: + secretName: {{ $secretName }} + defaultMode: 0440 --- apiVersion: v1 kind: Service diff --git a/charts/inbuxa/tests/frontends_test.yaml b/charts/inbuxa/tests/frontends_test.yaml index 28760d5..245bab7 100644 --- a/charts/inbuxa/tests/frontends_test.yaml +++ b/charts/inbuxa/tests/frontends_test.yaml @@ -50,11 +50,6 @@ tests: - contains: path: spec.template.spec.containers[0].env content: {name: ADMIN_URL, value: "https://admin.example.org"} - - contains: - path: spec.template.spec.containers[0].env - content: - name: OAUTH_CLIENT_SECRET - valueFrom: {secretKeyRef: {name: mail-inbuxa-webmail, key: oauth-client-secret}} - equal: path: spec.replicas value: 2 @@ -62,6 +57,34 @@ tests: path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem value: true + - it: gives the webmail its secrets as files, and has it check its read-only root + template: webmail.yaml + documentSelector: + path: kind + value: Deployment + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: {name: APP_SECRET_FILE, value: /etc/inbuxa-webmail/app-secret} + - contains: + path: spec.template.spec.containers[0].env + content: {name: OAUTH_CLIENT_SECRET_FILE, value: /etc/inbuxa-webmail/oauth-client-secret} + - contains: + path: spec.template.spec.containers[0].env + content: {name: IMMUTABLE, value: "1"} + - notContains: + path: spec.template.spec.containers[0].env + content: {name: APP_SECRET_PREVIOUS_FILE, value: /etc/inbuxa-webmail/app-secret-previous} + - contains: + path: spec.template.spec.volumes + content: {name: secrets, secret: {secretName: mail-inbuxa-webmail, defaultMode: 0440}} + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: {name: secrets, mountPath: /etc/inbuxa-webmail, readOnly: true} + - equal: + path: spec.template.spec.securityContext.fsGroup + value: 1000 + - it: makes the webmail's secrets when none is given template: webmail.yaml documentSelector: @@ -81,14 +104,33 @@ tests: - hasDocuments: count: 3 - contains: - path: spec.template.spec.containers[0].env - content: - name: APP_SECRET - valueFrom: {secretKeyRef: {name: my-webmail, key: app-secret}} + path: spec.template.spec.volumes + content: {name: secrets, secret: {secretName: my-webmail, defaultMode: 0440}} documentSelector: path: kind value: Deployment + - it: reads the old app secret while rotating, from the operator's Secret only + template: webmail.yaml + set: + webmail.existingSecret: my-webmail + webmail.previousAppSecret: true + documentSelector: + path: kind + value: Deployment + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: {name: APP_SECRET_PREVIOUS_FILE, value: /etc/inbuxa-webmail/app-secret-previous} + + - it: refuses previousAppSecret on the chart's own Secret + template: webmail.yaml + set: + webmail.previousAppSecret: true + asserts: + - failedTemplate: + errorPattern: "previousAppSecret needs webmail.existingSecret" + - it: tells every server pod about the webmail and the console, so it registers them template: server/deployment.yaml asserts: diff --git a/charts/inbuxa/values.schema.json b/charts/inbuxa/values.schema.json index 8d142e9..b047775 100644 --- a/charts/inbuxa/values.schema.json +++ b/charts/inbuxa/values.schema.json @@ -538,6 +538,9 @@ "existingSecret": { "type": "string" }, + "previousAppSecret": { + "type": "boolean" + }, "trustedProxies": { "type": "array", "items": { diff --git a/charts/inbuxa/values.yaml b/charts/inbuxa/values.yaml index 5b13d48..f019501 100644 --- a/charts/inbuxa/values.yaml +++ b/charts/inbuxa/values.yaml @@ -201,11 +201,14 @@ webmail: publicUrl: "" replicas: 2 # A Secret with app-secret (seals sessions; the same on every replica) and - # oauth-client-secret (the server holds it too), and optionally - # app-secret-previous (comma-separated secrets that still open sessions - # after a rotation). Empty: the chart makes one with random values and - # keeps them across upgrades. + # oauth-client-secret (the server holds it too). Empty: the chart makes one + # with random values and keeps them across upgrades. The webmail reads both + # as files, never from its environment. existingSecret: "" + # While rotating app-secret: true, with the old value(s), comma-separated, + # under app-secret-previous in existingSecret. Sessions sealed with them + # still open. Set it back to false once they have expired. + previousAppSecret: false # Addresses whose X-Forwarded-For the webmail believes, as CIDRs. Empty: # the private ranges, which covers an ingress inside the cluster. trustedProxies: [] -- 2.54.0