mailcow: Add rollout runbook, config scripts and local manifests.

Add the 2026-10 rollout runbook, bin/apply-mailcow-conf and
bin/edit-mailcow-conf, the alternative Mailcow manifests (deployment,
ext, native, prefetch), mailcow/pkg, and the local nginx templates and
rspamd Lua script.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Change-Id: I20efc2f0ce32a0e08ce1d1e4716209261d0795e4
diff --git a/MAILCOW-UPDATE.md b/MAILCOW-UPDATE.md
new file mode 100644
index 0000000..8face0c
--- /dev/null
+++ b/MAILCOW-UPDATE.md
@@ -0,0 +1,162 @@
+# Mailcow update to 2026-10: rollout runbook
+
+Status as of 2026-10-23. Nothing has been changed in the cluster yet.
+
+## Where things are
+
+| What | Where |
+|---|---|
+| Update branch | `mailcow-update` (worktree `~/Arbeitskasten/Kubeia-mailcow-update`), based on `repo-cleanup` |
+| New image | `docker.benkard.de/mulk/mailcow:9q2d15n90wjlwqph7rgf6967ir9bw9aj` (pushed, built with `make mailcow.load`) |
+| Old image (rollback) | `docker.benkard.de/mulk/mailcow:zxabqwczc1nb589mz98ikmn25d6rrwd8` |
+| Backups and config changes | `~/Arbeitskasten/mailcow-conf-2026-10/` (mode 700, **contains secrets, never put in git**) |
+| Config update script | `bin/apply-mailcow-conf` (runs inside the helper pod, see step 4) |
+| Live pod | namespace `mulk`, node `ifirn`; config PVC `mailcow-config-v2` |
+
+Contents of `~/Arbeitskasten/mailcow-conf-2026-10/`:
+
+- `conf-live-backup.tar.gz`: the live `data/conf` (183 files), verified identical to the PVC.
+- `live-ownership.txt`: owner and mode of every entry (`uid:gid mode path`); the PVC has mixed owners.
+- `live-snapshot.md5`: checksums of the live config, used to check that nothing changed before step 4.
+- `conf-changes.tar.gz`: the 45 files from upstream 2026-10 that are new or changed compared to live.
+- `changed-files.txt`, `deleted-files.txt`: what step 4 updates and deletes (33 stale stock files; the
+  old nginx `.conf` files must go because the new nginx includes `conf.d/*.conf`).
+- `mailcow-db-before-2026-10.sql.gz`: full dump of the `mailcow` database (64 tables, no routines or
+  events, see "MariaDB system tables" in `TODO.md`).
+
+## Done
+
+- [x] Subrepo updated to upstream `55982ac7` (tag 2026-10), local patches re-applied
+      (no Unbound DNS entries, IPv6 off via `ENABLE_IPV6`, DockerApi MySQL upgrade stubs, Postfix overrides).
+- [x] Compose override adapted (`version:` and Solr removed) in `mailcow/default.nix`.
+- [x] `REDISPASS` and `SOGO_URL_ENCRYPTION_KEY` added to `mailcow.conf` in `mailcow-secrets`
+      (use `bin/edit-mailcow-conf`); `dbpass` key present.
+- [x] Image built, pushed and checked.
+- [x] Database dump and config backup.
+- [x] Config update script tested on a copy of the live config (30 updated, 15 created, 33 deleted).
+- [ ] `mailcow/mailcow.yaml` on `mailcow-update` set to the new image tag: **edited, not committed yet**.
+      `kubectl diff` shows only the image and the `DBPASS` → `secretKeyRef` change.
+
+## Rollout
+
+Run everything from `~/Arbeitskasten/mailcow-conf-2026-10`. Mail is down from step 3 until step 6 finishes.
+
+```shell
+cd ~/Arbeitskasten/mailcow-conf-2026-10
+KUBEIA=~/Arbeitskasten/Kubeia
+```
+
+### 3. Stop mailcow
+
+```shell
+kubectl -n mulk scale deploy/mailcow --replicas=0
+kubectl -n mulk wait --for=delete pod -l name=mailcow --timeout=300s
+```
+
+### 4. Update the config on the PVC
+
+Start a helper pod on `ifirn` with the config PVC mounted at `/conf`:
+
+```shell
+kubectl -n mulk run mailcow-conf-sync --image=busybox:1.36 --restart=Never --overrides='{"apiVersion":"v1","spec":{"nodeName":"ifirn","containers":[{"name":"mailcow-conf-sync","image":"busybox:1.36","command":["sleep","3600"],"volumeMounts":[{"name":"conf","mountPath":"/conf"}]}],"volumes":[{"name":"conf","persistentVolumeClaim":{"claimName":"mailcow-config-v2"}}]}}'
+kubectl -n mulk wait --for=condition=Ready pod/mailcow-conf-sync
+```
+
+Check that the config hasn't changed since the backup. **No output means OK.** If anything is printed,
+stop here, delete the helper pod and take a fresh backup first.
+
+```shell
+kubectl -n mulk exec mailcow-conf-sync -- sh -c 'cd /conf && find . -type f -exec md5sum {} +' | sort -k2 | diff - live-snapshot.md5
+```
+
+Copy the changes in and apply them:
+
+```shell
+kubectl -n mulk cp conf-changes.tar.gz mailcow-conf-sync:/tmp/
+kubectl -n mulk cp deleted-files.txt mailcow-conf-sync:/tmp/
+kubectl -n mulk cp $KUBEIA/bin/apply-mailcow-conf mailcow-conf-sync:/tmp/apply-conf.sh
+kubectl -n mulk exec mailcow-conf-sync -- sh -c 'mkdir /tmp/changes && tar -C /tmp/changes -xzf /tmp/conf-changes.tar.gz && sh /tmp/apply-conf.sh'
+```
+
+The script prints one line per file (`updated`, `created`, `deleted`); expect 30 / 15 / 33.
+Then remove the helper pod:
+
+```shell
+kubectl -n mulk delete pod mailcow-conf-sync
+```
+
+### 5. Start the new version
+
+```shell
+kubectl apply -f ~/Arbeitskasten/Kubeia-mailcow-update/mailcow/mailcow.yaml
+```
+
+Then commit the image tag on `mailcow-update` (`mailcow: Update image to 2026-10.`).
+
+### 6. Watch the first start
+
+The first start pulls about 20 images (now from `ghcr.io`) and builds 3 (netfilter, dockerapi, watchdog),
+so it takes a while.
+
+```shell
+kubectl -n mulk logs -f deploy/mailcow
+kubectl -n mulk exec deploy/mailcow -- docker ps     # repeat until everything is healthy
+```
+
+Check:
+
+- [ ] all containers up and healthy, none restarting
+- [ ] web UI at https://mail.benkard.de/ works, login works
+- [ ] SOGo works
+- [ ] IMAP login, and sending and receiving a test mail in both directions
+- [ ] no Redis auth errors (`REDISPASS`) in the logs
+
+## Rollback
+
+```shell
+cd ~/Arbeitskasten/mailcow-conf-2026-10
+kubectl -n mulk scale deploy/mailcow --replicas=0
+kubectl -n mulk wait --for=delete pod -l name=mailcow --timeout=300s
+```
+
+Restore the config: start the helper pod as in step 4, then
+
+```shell
+kubectl -n mulk cp conf-live-backup.tar.gz mailcow-conf-sync:/tmp/
+kubectl -n mulk cp live-ownership.txt mailcow-conf-sync:/tmp/
+kubectl -n mulk exec mailcow-conf-sync -- sh -c '
+  find /conf -mindepth 1 -delete &&
+  tar -C /conf -xzf /tmp/conf-live-backup.tar.gz &&
+  while read -r owner mode path; do chown "$owner" "/conf/$path"; chmod "$mode" "/conf/$path"; done </tmp/live-ownership.txt'
+kubectl -n mulk exec mailcow-conf-sync -- sh -c 'cd /conf && find . -type f -exec md5sum {} +' | sort -k2 | diff - live-snapshot.md5
+kubectl -n mulk delete pod mailcow-conf-sync
+```
+
+The ownership loop is needed because the archive stores owner names from the local machine.
+The `diff` must print nothing.
+
+Restore the database only if the new version has already migrated it (it does so on first start):
+
+```shell
+DBPASS=$(kubectl -n mulk get secret mailcow-secrets -o jsonpath='{.data.dbpass}' | base64 -d)
+zcat mailcow-db-before-2026-10.sql.gz | kubectl -n system exec -i deploy/mysql -- mariadb -u mailcow -p"$DBPASS" mailcow
+```
+
+Then go back to the old image (the old manifest on `repo-cleanup` already has it, and keeps the `dbpass`
+secret reference):
+
+```shell
+kubectl apply -f ~/Arbeitskasten/Kubeia/mailcow/mailcow.yaml
+```
+
+## Afterwards
+
+- Commit the image tag on `mailcow-update`; merge into `master` when you're happy (not done yet).
+- Once the update is stable: delete the `mailcow-solr` PVC and the `/vol/solr-data` mount/volume
+  (`mailcow.yaml`, and `solr-data` in `mailcow/default.nix`).
+- Optional new `mailcow.conf` keys: `SKIP_FTS`, `FTS_HEAP`, `FTS_PROCS`, `SKIP_OLEFY`, `AUTODISCOVER_SAN`,
+  `HTTP_REDIRECT`, `ACME_ACCOUNT_EMAIL` (replaces `ACME_CONTACT`), `ACME_DNS_CHALLENGE`, `ACME_DNS_PROVIDER`.
+  Obsolete: `SKIP_SOLR`, `SOLR_HEAP`, `SOLR_PORT`.
+- Fix the MariaDB system tables (see `TODO.md`) so mailcow's cleanup events get created.
+- Keep `~/Arbeitskasten/mailcow-conf-2026-10/` until you're sure you won't need to roll back, then delete
+  it (it contains secrets and a full mail database dump).
diff --git a/bin/apply-mailcow-conf b/bin/apply-mailcow-conf
new file mode 100755
index 0000000..8368804
--- /dev/null
+++ b/bin/apply-mailcow-conf
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Runs inside the mailcow-conf-sync helper pod.  Updates the config PVC
+# mounted at /conf in place:
+#
+#   - files in /tmp/changes that already exist: overwrite content only,
+#     keeping owner and mode,
+#   - new files: create, owned like their parent directory,
+#   - files listed in /tmp/deleted-files.txt: delete.
+set -eu
+
+conf=/conf
+changes=/tmp/changes
+
+cd "$changes"
+find . -type f | while read -r f; do
+    f=${f#./}
+    dst=$conf/$f
+    if [ -e "$dst" ]; then
+        cat "$f" >"$dst"
+        echo "updated  $f"
+    else
+        dir=$(dirname "$dst")
+        if [ ! -d "$dir" ]; then
+            parent=$dir
+            while [ ! -d "$parent" ]; do parent=$(dirname "$parent"); done
+            owner=$(stat -c %u:%g "$parent")
+            mkdir -p "$dir"
+            # Hand every newly created directory to the existing parent's owner.
+            d=$dir
+            while [ "$d" != "$parent" ]; do chown "$owner" "$d"; d=$(dirname "$d"); done
+        fi
+        cp "$f" "$dst"
+        chown "$(stat -c %u:%g "$dir")" "$dst"
+        chmod "$(stat -c %a "$f")" "$dst"
+        echo "created  $f"
+    fi
+done
+
+while read -r f; do
+    if [ -e "$conf/$f" ]; then
+        rm "$conf/$f"
+        echo "deleted  $f"
+    fi
+done </tmp/deleted-files.txt
diff --git a/bin/edit-mailcow-conf b/bin/edit-mailcow-conf
new file mode 100755
index 0000000..b95b97a
--- /dev/null
+++ b/bin/edit-mailcow-conf
@@ -0,0 +1,52 @@
+#! /bin/bash
+# Edits mailcow.conf in the mailcow-secrets secret with $EDITOR.
+#
+# Usage: edit-mailcow-conf [namespace] [secret] [key]
+set -euo pipefail
+
+namespace=${1:-mulk}
+secret=${2:-mailcow-secrets}
+key=${3:-mailcow.conf}
+
+editor=${VISUAL:-${EDITOR:-vi}}
+
+# Keep the plaintext on tmpfs and readable only by us.
+umask 077
+workdir=$(mktemp -d "${XDG_RUNTIME_DIR:-/tmp}/edit-secret.XXXXXX")
+trap 'rm -rf "$workdir"' EXIT
+
+json=$(kubectl -n "$namespace" get secret "$secret" -o json)
+resource_version=$(jq -r '.metadata.resourceVersion' <<<"$json")
+jq -r --arg key "$key" '.data[$key] // error("key \($key) not found")' <<<"$json" \
+    | base64 -d >"$workdir/original"
+cp "$workdir/original" "$workdir/$key"
+
+while :; do
+    $editor "$workdir/$key"
+
+    if cmp -s "$workdir/original" "$workdir/$key"; then
+        echo "No changes."
+        exit 0
+    fi
+
+    diff -u --label "$key (cluster)" --label "$key (edited)" \
+        "$workdir/original" "$workdir/$key" || :
+
+    read -r -p "Apply to secret $namespace/$secret? [y]es/[e]dit again/[n]o: " answer
+    case $answer in
+        y|Y|yes) break ;;
+        e|E|edit) continue ;;
+        *) echo "Aborted."; exit 1 ;;
+    esac
+done
+
+# Including resourceVersion makes the patch fail if someone else changed
+# the secret in the meantime.
+jq -n \
+    --arg key "$key" \
+    --arg rv "$resource_version" \
+    --arg data "$(base64 -w0 <"$workdir/$key")" \
+    '{metadata: {resourceVersion: $rv}, data: {($key): $data}}' \
+    >"$workdir/patch.json"
+
+kubectl -n "$namespace" patch secret "$secret" --type merge --patch-file "$workdir/patch.json"
diff --git a/mailcow/deployment.yaml b/mailcow/deployment.yaml
new file mode 100644
index 0000000..a59ed6d
--- /dev/null
+++ b/mailcow/deployment.yaml
@@ -0,0 +1,176 @@
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: mailcow
+  namespace: mulk
+  labels:
+    name: mailcow
+    k8s-app: mailcow
+
+spec:
+  replicas: 1
+
+  strategy:
+    rollingUpdate:
+      maxSurge: 1
+      maxUnavailable: 1
+
+  selector:
+    matchLabels:
+      k8s-app: mailcow
+      name: mailcow
+
+  template:
+    metadata:
+      labels:
+        name: mailcow
+        k8s-app: mailcow
+
+    spec:
+      imagePullSecrets:
+        - name: portus-token
+
+      runtimeClassName: kata
+
+      containers:
+        - name: master
+          image: docker.benkard.de/mulk/mailcow:latest
+
+          securityContext:
+            # In a Kata container, this only gives the container full
+            # access to the guest VM rather than the host.  (To ensure
+            # this, it is important to set privileged_without_host_devices
+            # = true in the [plugins.cri.containerd.runtimes.kata] section
+            # of containerd's config.toml.)
+            privileged: true
+
+          env:
+            - {name: COMPOSE_HTTP_TIMEOUT, value: "600"}
+            - {name: TZ,                   value: Europe/Vienna}
+            - {name: DBNAME,               value: mailcow}
+            - {name: DBUSER,               value: mailcow}
+            - {name: DBPASS,               value: REDACTED}
+            - {name: MAILCOW_HOSTNAME,     value: mail.benkard.de}
+            - {name: ADDITIONAL_SAN,       value: ""}
+
+          ports:
+            - name: http
+              containerPort: 80
+            - name: smtp
+              hostPort: 25
+              containerPort: 25
+            - name: pop
+              hostPort: 110
+              containerPort: 110
+            - name: imap
+              hostPort: 143
+              containerPort: 143
+            - name: smtps
+              hostPort: 465
+              containerPort: 465
+            - name: submission
+              hostPort: 587
+              containerPort: 587
+            - name: imaps
+              hostPort: 993
+              containerPort: 993
+            - name: pops
+              hostPort: 995
+              containerPort: 995
+            - name: sieve
+              hostPort: 4190
+              containerPort: 4190
+            - name: doveadm
+              hostPort: 19991
+              containerPort: 12345
+
+          volumeMounts:
+            # Configuration data.
+            - name: assets
+              subPath: ssl
+              mountPath: /mailcow-dockerized/data/assets/ssl
+            - name: config
+              mountPath: /mailcow-dockerized/data/conf
+            - name: secrets
+              subPath: mailcow.conf
+              mountPath: /mailcow-dockerized/mailcow.conf
+
+            # State.
+            - name: crypt-data
+              mountPath: /vol/crypt-data
+            - name: postfix-data
+              mountPath: /vol/postfix-data
+            - name: redis-data
+              mountPath: /vol/redis-data
+            - name: rspamd-data
+              mountPath: /vol/rspamd-data
+            - name: solr-data
+              mountPath: /vol/solr-data
+            - name: sogo-web
+              mountPath: /vol/sogo-web
+            - name: sogo-userdata-backup
+              mountPath: /vol/sogo-userdata-backup
+            - name: vmail
+              mountPath: /vol/vmail
+            - name: vmail-index
+              mountPath: /vol/vmail-index
+            - name: web-data
+              mountPath: /vol/web-data
+            #- name: docker-data
+            #  subPath: vfs
+            #  mountPath: /var/lib/docker/vfs
+            #- name: docker-data
+            #  subPath: image
+            #  mountPath: /var/lib/docker/image
+            #- name: docker-data
+            #  subPath: overlay2
+            #  mountPath: /var/lib/docker/overlay2
+            #- name: docker-data
+            #  mountPath: /var/lib/docker
+            - name: docker-data
+              mountPath: /vol/docker-data
+
+      volumes:
+        - name: assets
+          persistentVolumeClaim:
+            claimName: mailcow-assets
+        - name: config
+          persistentVolumeClaim:
+            claimName: mailcow-config-v2
+        - name: crypt-data
+          persistentVolumeClaim:
+            claimName: mailcow-crypt
+        - name: postfix-data
+          persistentVolumeClaim:
+            claimName: mailcow-postfix
+        - name: redis-data
+          persistentVolumeClaim:
+            claimName: mailcow-redis
+        - name: rspamd-data
+          persistentVolumeClaim:
+            claimName: mailcow-rspamd
+        - name: solr-data
+          persistentVolumeClaim:
+            claimName: mailcow-solr
+        - name: sogo-web
+          persistentVolumeClaim:
+            claimName: mailcow-sogo-web
+        - name: sogo-userdata-backup
+          persistentVolumeClaim:
+            claimName: mailcow-sogo-userdata-backup
+        - name: vmail
+          persistentVolumeClaim:
+            claimName: mailcow-vmail
+        - name: vmail-index
+          persistentVolumeClaim:
+            claimName: mailcow-vmail-index
+        - name: web-data
+          persistentVolumeClaim:
+            claimName: mailcow-web
+        - name: docker-data
+          persistentVolumeClaim:
+            claimName: mailcow-docker
+        - name: secrets
+          secret:
+            secretName: mailcow-secrets
diff --git a/mailcow/mailcow-ext.yaml b/mailcow/mailcow-ext.yaml
new file mode 100644
index 0000000..e69bb8c
--- /dev/null
+++ b/mailcow/mailcow-ext.yaml
@@ -0,0 +1,20 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: mailcow-pub
+  namespace: mulk
+  labels:
+    name: mailcow-pub
+    k8s-app: mailcow
+spec:
+  selector:
+    name: mailcow
+  type: NodePort
+  externalTrafficPolicy: Local
+  ports:
+    - name: smtp-alt
+      port: 31025
+      targetPort: 25
+      protocol: TCP
+      nodePort: 31025
+---
diff --git a/mailcow/mailcow-native.yaml b/mailcow/mailcow-native.yaml
new file mode 100644
index 0000000..5aaef1d
--- /dev/null
+++ b/mailcow/mailcow-native.yaml
@@ -0,0 +1,618 @@
+---
+apiVersion: extensions/v1beta1
+kind: Ingress
+metadata:
+  name: mailcow
+  namespace: mulk
+  labels:
+    name: mailcow
+    k8s-app: mailcow
+  annotations:
+    kubernetes.io/ingress.class: traefik
+    traefik.ingress.kubernetes.io/preserve-host: "true"
+spec:
+  rules:
+    - host: mail.benkard.de
+      http:
+        paths:
+          - path: /
+            backend:
+              serviceName: mailcow
+              servicePort: 80
+    - host: autodiscover.benkard.de
+      http:
+        paths:
+          - path: /
+            backend:
+              serviceName: mailcow
+              servicePort: 80
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: mailcow-pub
+  namespace: mulk
+  labels:
+    name: mailcow-pub
+    k8s-app: mailcow
+spec:
+  selector:
+    name: mailcow
+  type: NodePort
+  externalTrafficPolicy: Local
+  ports:
+    - name: smtp-alt
+      port: 31025
+      targetPort: 25
+      protocol: TCP
+      nodePort: 31025
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: mailcow
+  namespace: mulk
+  labels:
+    name: mailcow
+    k8s-app: mailcow
+spec:
+  selector:
+    name: mailcow
+  type: ClusterIP
+  ports:
+    - name: http
+      port: 80
+      targetPort: 80
+      protocol: TCP
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: mailcow
+  namespace: mulk
+  labels:
+    name: mailcow
+    k8s-app: mailcow
+spec:
+  replicas: 1
+  strategy:
+    rollingUpdate:
+      maxSurge: 1
+      maxUnavailable: 1
+  selector:
+    matchLabels:
+      k8s-app: mailcow
+      name: mailcow
+  template:
+    metadata:
+      labels:
+        name: mailcow
+        k8s-app: mailcow
+    spec:
+      imagePullSecrets:
+        - name: kube-registry-token
+      hostAliases:
+        - ip: "127.0.0.1"
+          hostnames:
+            - "mysql"
+            - "mysql-mailcow"
+            - "mysql-proxy"
+            - "redis"
+            - "redis-mailcow"
+            - "clamd"
+            - "clamd-mailcow"
+            - "dockerapi"
+            - "dockerapi-mailcow"
+            - "solr"
+            - "solr-mailcow"
+            - "watchdog"
+            - "watchdog-mailcow"
+            - "acme"
+            - "acme-mailcow"
+            - "nginx"
+            - "nginx-mailcow"
+            - "memcached"
+            - "memcached-mailcow"
+            - "postfix"
+            - "postfix-mailcow"
+            - "dovecot"
+            - "dovecot-mailcow"
+            - "sogo"
+            - "sogo-mailcow"
+            - "phpfpm"
+            - "phpfpm-mailcow"
+            - "rspamd"
+            - "rspamd-mailcow"
+            - "unbound"
+            - "unbound-mailcow"
+      containers:
+        - name: mysql-proxy
+          image: alpine/socat:1.0.3
+          args:
+            - UNIX-LISTEN:/var/run/mysqld/mysqld.sock,reuseaddr,fork,unlink-early,mode=0777
+            - TCP-CONNECT:mysql.system.svc.cluster.local.:3306
+          volumeMounts:
+            - name: mysql-socket
+              mountPath: /var/run/mysqld
+        - name: redis
+          image: redis:5-alpine
+          env:
+            - name: TZ
+              value: Europe/Vienna
+          volumeMounts:
+            - name: redis-data
+              mountPath: /data
+        - name: clamd
+          image: mailcow/clamd:1.35
+          env:
+            - name: TZ
+              value: Europe/Vienna
+            - name: SKIP_CLAMD
+              value: "y"
+          volumeMounts:
+            - name: config
+              subPath: clamav
+              mountPath: /etc/clamav
+            - name: clamav-data
+              mountPath: /var/lib/clamav
+        - name: rspamd
+          image: mailcow/rspamd:1.57
+          env:
+            - name: TZ
+              value: Europe/Vienna
+            - name: DOVECOT_V4
+              value: 127.0.0.1
+          volumeMounts:
+            - name: rspamd-data
+              mountPath: /var/lib/rspamd
+            - name: config
+              subPath: rspamd/custom
+              mountPath: /etc/rspamd/custom
+            - name: config
+              subPath: rspamd/override.d
+              mountPath: /etc/rspamd/override.d
+            - name: config
+              subPath: rspamd/local.d
+              mountPath: /etc/rspamd/local.d
+            - name: config
+              subPath: rspamd/lua/
+              mountPath: /etc/rspamd/lua
+              readOnly: true
+        - name: php-fpm
+          image: mailcow/phpfpm:1.55
+          command:
+            - php-fpm
+            - -d
+            - date.timezone=Europe/Vienna
+            - -d
+            - expose_php=0
+          env:
+            - {name: LOG_LINES, value: "9999"}
+            - {name: TZ, value: Europe/Vienna}
+            - {name: DBNAME, value: mailcow}
+            - {name: DBUSER, value: mailcow}
+            - {name: DBPASS, value: REDACTED}
+            - {name: MAILCOW_HOSTNAME, value: mail.benkard.de}
+            - {name: IMAP_PORT, value: "143"}
+            - {name: IMAPS_PORT, value: "993"}
+            - {name: POP_PORT, value: "110"}
+            - {name: POPS_PORT, value: "995"}
+            - {name: SIEVE_PORT, value: "4190"}
+            - {name: SUBMISSION_PORT, value: "587"}
+            - {name: SMTPS_PORT, value: "465"}
+            - {name: SMTP_PORT, value: "25"}
+            - {name: API_KEY, value: invalid}
+            - {name: API_ALLOW_FROM, value: invalid}
+            - {name: COMPOSE_PROJECT_NAME, value: mailcow-dockerized}
+            - {name: SKIP_SOLR, value: "y"}
+          volumeMounts:
+            - name: web-data
+              mountPath: /web
+            - name: config
+              subPath: rspamd/dynmaps
+              mountPath: /dynmaps
+              readOnly: true
+            - name: rspamd-data
+              mountPath: /var/lib/rspamd
+            - name: config
+              subPath: sogo
+              mountPath: /etc/sogo
+            - name: config
+              subPath: rspamd/meta_exporter
+              mountPath: /meta_exporter
+              readOnly: true
+            - name: config
+              subPath: phpfpm/php-fpm.d/pools.conf
+              mountPath: /usr/local/etc/php-fpm.d/z-pools.conf
+            - name: config
+              subPath: phpfpm/php-conf.d/opcache-recommended.ini
+              mountPath: /usr/local/etc/php/conf.d/opcache-recommended.ini
+            - name: config
+              subPath: phpfpm/php-conf.d/upload.ini
+              mountPath: /usr/local/etc/php/conf.d/upload.ini
+            - name: config
+              subPath: phpfpm/php-conf.d/other.ini
+              mountPath: /usr/local/etc/php/conf.d/zzz-other.ini
+            - name: mysql-socket
+              mountPath: /var/run/mysqld
+        - name: sogo
+          image: mailcow/sogo:1.65
+          command:
+            - /bin/sleep
+            - inf
+          env:
+            - {name: DBNAME, value: mailcow}
+            - {name: DBUSER, value: mailcow}
+            - {name: DBPASS, value: REDACTED}
+            - {name: TZ, value: Europe/Vienna}
+            - {name: LOG_LINES, value: "9999"}
+            - {name: MAILCOW_HOSTNAME, value: mail.benkard.de}
+            - {name: ACL_ANYONE, value: disallow}
+          volumeMounts:
+            - name: config
+              subPath: sogo
+              mountPath: /etc/sogo
+            - name: config
+              subPath: sogo/custom-sogo.js
+              mountPath: /usr/lib/GNUstep/SOGo/WebServerResources/js/custom-sogo.js
+            - name: web-data
+              subPath: inc/init_db.inc.php
+              mountPath: /init_db.inc.php
+            - name: mysql-socket
+              mountPath: /var/run/mysqld
+        - name: dovecot
+          image: mailcow/dovecot:1.54
+          tty: true
+          env:
+            - {name: DBNAME, value: mailcow}
+            - {name: DBUSER, value: mailcow}
+            - {name: DBPASS, value: REDACTED}
+            - {name: TZ, value: Europe/Vienna}
+            - {name: LOG_LINES, value: "9999"}
+            - {name: MAILDIR_GC_TIME, value: "1440"}
+            - {name: ACL_ANYONE, value: disallow}
+          volumeMounts:
+            - name: config
+              subPath: dovecot
+              mountPath: /usr/local/etc/dovecot
+            - name: assets
+              subPath: ssl
+              mountPath: /etc/ssl/mail
+              readOnly: true
+            - name: config
+              subPath: sogo
+              mountPath: /etc/sogo/
+            - name: vmail
+              mountPath: /var/vmail
+            - name: vmail-attachments
+              mountPath: /var/attachments
+            - name: crypt-data
+              mountPath: /mail_crypt
+            - name: config
+              subPath: rspamd/custom
+              mountPath: /etc/rspamd/custom
+            - name: rspamd-data
+              mountPath: /var/lib/rspamd
+            - name: mysql-socket
+              mountPath: /var/run/mysqld
+          ports:
+            - name: doveadm
+              hostPort: 19991
+              containerPort: 12345
+            - name: imap
+              hostPort: 143
+              containerPort: 143
+            - name: imaps
+              hostPort: 993
+              containerPort: 993
+            - name: pop
+              hostPort: 110
+              containerPort: 110
+            - name: pops
+              hostPort: 995
+              containerPort: 995
+            - name: sieve
+              hostPort: 4190
+              containerPort: 4190
+        - name: postfix
+          image: mailcow/postfix:1.44
+          volumeMounts:
+            - name: config
+              subPath: postfix
+              mountPath: /opt/postfix/conf
+            - name: assets
+              subPath: ssl
+              mountPath: /etc/ssl/mail
+              readOnly: true
+            - name: postfix-data
+              mountPath: /var/spool/postfix
+            - name: crypt-data
+              mountPath: /var/lib/zeyple
+            - name: rspamd-data
+              mountPath: /var/lib/rspamd
+            - name: mysql-socket
+              mountPath: /var/run/mysqld
+          env:
+            - {name: LOG_LINES, value: "9999"}
+            - {name: TZ, value: Europe/Vienna}
+            - {name: DBNAME, value: mailcow}
+            - {name: DBUSER, value: mailcow}
+            - {name: DBPASS, value: REDACTED}
+          ports:
+            - name: smtp
+              hostPort: 25
+              containerPort: 25
+            - name: smtps
+              hostPort: 465
+              containerPort: 465
+            - name: submission
+              hostPort: 587
+              containerPort: 587
+        - name: memcached
+          image: memcached:1.5.16
+        - name: nginx
+          image: nginx:1.17.0-alpine
+          command:
+            - /bin/sh
+            - -c
+            - envsubst < /etc/nginx/conf.d/templates/listen_plain.template > /etc/nginx/conf.d/listen_plain.active &&
+              envsubst < /etc/nginx/conf.d/templates/listen_ssl.template > /etc/nginx/conf.d/listen_ssl.active &&
+              envsubst < /etc/nginx/conf.d/templates/server_name.template > /etc/nginx/conf.d/server_name.active &&
+              envsubst < /etc/nginx/conf.d/templates/sogo.template > /etc/nginx/conf.d/sogo.active &&
+              envsubst < /etc/nginx/conf.d/templates/sogo_eas.template > /etc/nginx/conf.d/sogo_eas.active &&
+              nginx -t &&
+              exec nginx -g 'daemon off;'
+          env:
+            - {name: HTTPS_PORT, value: "443"}
+            - {name: HTTP_PORT, value: "80"}
+            - {name: MAILCOW_HOSTNAME, value: mail.benkard.de}
+            #- {name: IPV4_NETWORK, value: ${IPV4_NETWORK:-172.22.1}}
+            - {name: TZ, value: Europe/Vienna}
+          volumeMounts:
+            - name: web-data
+              mountPath: /web
+              readOnly: true
+            - name: config
+              subPath: rspamd/dynmaps
+              mountPath: /dynmaps
+              readOnly: true
+            - name: assets
+              subPath: ssl
+              mountPath: /etc/ssl/mail
+              readOnly: true
+            - name: config
+              subPath: nginx
+              mountPath: /etc/nginx/conf.d
+            - name: config
+              subPath: rspamd/meta_exporter
+              mountPath: /meta_exporter
+              readOnly: true
+          ports:
+            - name: http
+              containerPort: 80
+        - name: acme
+          image: mailcow/acme:1.70
+          env:
+            - {name: LOG_LINES, value: "9999"}
+            - {name: ADDITIONAL_SAN, value: ""}
+            - {name: MAILCOW_HOSTNAME, value: mail.benkard.de}
+            - {name: DBNAME, value: mailcow}
+            - {name: DBUSER, value: mailcow}
+            - {name: DBPASS, value: REDACTED}
+            - {name: SKIP_LETS_ENCRYPT, value: "n"}
+            - {name: SKIP_IP_CHECK, value: "y"}
+            - {name: LE_STAGING, value: "n"}
+            - {name: TZ, value: Europe/Vienna}
+          volumeMounts:
+            - name: web-data
+              subPath: .well-known/acme-challenge
+              mountPath: /var/www/acme
+            - name: assets
+              subPath: ssl
+              mountPath: /var/lib/acme
+            - name: assets
+              subPath: ssl-example
+              mountPath: /var/lib/ssl-example
+              readOnly: true
+            - name: mysql-socket
+              mountPath: /var/run/mysqld
+      volumes:
+        - name: web-data
+          persistentVolumeClaim:
+            claimName: mailcow-web
+        - name: assets
+          persistentVolumeClaim:
+            claimName: mailcow-assets
+        - name: vmail
+          persistentVolumeClaim:
+            claimName: mailcow-vmail
+        - name: vmail-attachments
+          persistentVolumeClaim:
+            claimName: mailcow-vmail-attachments
+        - name: redis-data
+          persistentVolumeClaim:
+            claimName: mailcow-redis
+        - name: rspamd-data
+          persistentVolumeClaim:
+            claimName: mailcow-rspamd
+        - name: postfix-data
+          persistentVolumeClaim:
+            claimName: mailcow-postfix
+        - name: crypt-data
+          persistentVolumeClaim:
+            claimName: mailcow-crypt
+        - name: config
+          persistentVolumeClaim:
+            claimName: mailcow-config
+        - name: mysql-socket
+          emptyDir: {}
+        - name: clamav-data
+          emptyDir: {}
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-web
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-assets
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-vmail
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-vmail-attachments
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-redis
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-rspamd
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-postfix
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-crypt
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: mailcow-config
+  namespace: mulk
+  labels:
+    k8s-app: mailcow
+  annotations:
+    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
+spec:
+  storageClassName: local-path
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+---
+#kind: ConfigMap
+#apiVersion: v1
+#metadata:
+#  name: mailcow-config
+#  namespace: mulk
+#  labels:
+#    k8s-app: mailcow
+#data:
+#  gerrit.config: |
+#    [gerrit]
+#      basePath = git
+#      canonicalWebUrl = https://gerrit.benkard.de/
+#      serverId = 4f1749e7-9b7f-449e-acf9-5e80b87f8173
diff --git a/mailcow/mailcow-prefetch.yaml b/mailcow/mailcow-prefetch.yaml
new file mode 100644
index 0000000..64a1434
--- /dev/null
+++ b/mailcow/mailcow-prefetch.yaml
@@ -0,0 +1,64 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: mailcow-fake
+  namespace: mulk
+  labels:
+    name: mailcow-fake
+    k8s-app: mailcow-fake
+
+spec:
+  replicas: 1
+
+  strategy:
+    rollingUpdate:
+      maxSurge: 1
+      maxUnavailable: 1
+
+  selector:
+    matchLabels:
+      k8s-app: mailcow-fake
+      name: mailcow-fake
+
+  template:
+    metadata:
+      labels:
+        name: mailcow-fake
+        k8s-app: mailcow-fake
+
+    spec:
+      imagePullSecrets:
+        - name: portus-token
+
+      runtimeClassName: kata
+
+      containers:
+        - name: master
+          image: docker.benkard.de/mulk/mailcow:latest
+
+          args:
+            - "prefetch"
+
+          securityContext:
+            # In a Kata container, this only gives the container full
+            # access to the guest VM rather than the host.  (To ensure
+            # this, it is important to set privileged_without_host_devices
+            # = true in the [plugins.cri.containerd.runtimes.kata] section
+            # of containerd's config.toml.)
+            privileged: true
+
+          volumeMounts:
+            - name: docker-data
+              subPath: vfs
+              mountPath: /var/lib/docker/vfs
+            - name: docker-data
+              subPath: image
+              mountPath: /var/lib/docker/image
+            - name: docker-data
+              subPath: overlay2
+              mountPath: /var/lib/docker/overlay2
+
+      volumes:
+        - name: docker-data
+          persistentVolumeClaim:
+            claimName: mailcow-docker
diff --git a/mailcow/pkg/GNUmakefile b/mailcow/pkg/GNUmakefile
new file mode 100644
index 0000000..3f8af07
--- /dev/null
+++ b/mailcow/pkg/GNUmakefile
@@ -0,0 +1,2 @@
+install:
+	install -Dm 0755 init $(out)/bin/init
diff --git a/mailcow/pkg/init b/mailcow/pkg/init
new file mode 100755
index 0000000..50d4884
--- /dev/null
+++ b/mailcow/pkg/init
@@ -0,0 +1 @@
+#! /bin/sh
diff --git a/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/server_name.template b/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/server_name.template
new file mode 100644
index 0000000..261a1ec
--- /dev/null
+++ b/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/server_name.template
@@ -0,0 +1 @@
+server_name ${MAILCOW_HOSTNAME} autodiscover.* autoconfig.*;
diff --git a/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/sogo.auth_request.template.sh b/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/sogo.auth_request.template.sh
new file mode 100644
index 0000000..f6d2d98
--- /dev/null
+++ b/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/sogo.auth_request.template.sh
@@ -0,0 +1,10 @@
+if printf "%s\n" "${ALLOW_ADMIN_EMAIL_LOGIN}" | grep -E '^([yY][eE][sS]|[yY])+$' >/dev/null; then
+    echo 'auth_request /sogo-auth-verify;
+auth_request_set $user $upstream_http_x_user;
+auth_request_set $auth $upstream_http_x_auth;
+auth_request_set $auth_type $upstream_http_x_auth_type;
+proxy_set_header x-webobjects-remote-user "$user";
+proxy_set_header Authorization "$auth";
+proxy_set_header x-webobjects-auth-type "$auth_type";
+'
+fi
diff --git a/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/sogo_eas.template b/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/sogo_eas.template
new file mode 100644
index 0000000..f0cd348
--- /dev/null
+++ b/mailcow/src/mailcow-dockerized/data/conf/nginx/templates/sogo_eas.template
@@ -0,0 +1 @@
+proxy_pass http://sogo:20000/SOGo/Microsoft-Server-ActiveSync;
diff --git a/mailcow/src/mailcow-dockerized/data/conf/rspamd/lua/ivm-sg.lua b/mailcow/src/mailcow-dockerized/data/conf/rspamd/lua/ivm-sg.lua
new file mode 100644
index 0000000..6642fe4
--- /dev/null
+++ b/mailcow/src/mailcow-dockerized/data/conf/rspamd/lua/ivm-sg.lua
@@ -0,0 +1,61 @@
+-- Thanks to https://raw.githubusercontent.com/fatalbanana
+
+local lua_maps = require 'lua_maps'
+local rspamd_regexp = require 'rspamd_regexp'
+local rspamd_util = require 'rspamd_util'
+
+local ivm_sendgrid_ids = lua_maps.map_add_from_ucl(
+  'https://www.invaluement.com/spdata/sendgrid-id-dnsbl.txt',
+  'set',
+  'Invaluement Service Provider DNSBL: Sendgrid IDs'
+)
+
+local ivm_sendgrid_envfromdomains = lua_maps.map_add_from_ucl(
+  'https://www.invaluement.com/spdata/sendgrid-envelopefromdomain-dnsbl.txt',
+  'set',
+  'Invaluement Service Provider DNSBL: Sendgrid envelope domains'
+)
+
+local cb_id = rspamd_config:register_symbol({
+  name = 'IVM_SENDGRID',
+  callback = function(task)
+    -- Is it Sendgrid?
+    local sg_hdr = task:get_header('X-SG-EID')
+    if not sg_hdr then return end
+
+    -- Get original envelope from
+    local env_from = task:get_from{'smtp', 'orig'}
+    if not env_from then return end
+
+    -- Check normalised domain in domains list
+    if ivm_sendgrid_envfromdomains and ivm_sendgrid_envfromdomains:get_key(rspamd_util.get_tld(env_from[1].domain)) then
+      task:insert_result('IVM_SENDGRID_DOMAIN', 1.0)
+    end
+
+    -- Check ID in ID list
+    local lp_re = rspamd_regexp.create_cached([[^bounces\+(\d+)-]])
+    local res = lp_re:search(env_from[1].user, true, true)
+    if not res then return end
+    if ivm_sendgrid_ids and ivm_sendgrid_ids:get_key(res[1][2]) then
+      task:insert_result('IVM_SENDGRID_ID', 1.0)
+    end
+  end,
+  description = 'Invaluement Service Provider DNSBL: Sendgrid',
+  type = 'callback',
+})
+
+rspamd_config:register_symbol({
+  name = 'IVM_SENDGRID_DOMAIN',
+  parent = cb_id,
+  group = 'ivmspdnsbl',
+  score = 8.0,
+  type = 'virtual',
+})
+
+rspamd_config:register_symbol({
+  name = 'IVM_SENDGRID_ID',
+  parent = cb_id,
+  group = 'ivmspdnsbl',
+  score = 8.0,
+  type = 'virtual',
+})