stalwart-mail-ha

by L4G

Helm chartv0.1.3App 1.0.1AGPL-3.0Verified publisher

Helm chart for Stalwart Mail Server (SMTP, IMAP, JMAP, CalDAV/CardDAV) running multi-replica with all state on external backends

About this chart

stalwart-mail-ha

Helm chart for Stalwart Mail Server running multi-replica with all state on external backends.

Pinned to Stalwart 0.16.3. Stalwart 0.16 stores configuration as JMAP records inside the data store, so the on-disk config.json rendered by this chart only describes the data store wiring. SMTP listeners, blob store, DKIM, directories, rate limits, and everything else are managed at runtime through the Stalwart WebUI or stalwart-cli apply.

Architecture

                        ┌────────────────────────────┐
                        │        Kubernetes          │
                        │                            │
   ───── 25/465/587 ───▶│   Service: <name>-mail     │
   ───── 143/993 ──────▶│   (LoadBalancer / NLB)     │─┐
   ───── 4190 ─────────▶│                            │ │
                        └────────────────────────────┘ │
                                                       ▼
                              ┌──────────────────────────────────┐
                              │   Deployment: stalwart-mail      │
                              │   replicas=N, anti-affinity      │
                              │                                  │
                              │   Pod 1   Pod 2   Pod 3   ...    │
                              │     │       │       │            │
                              └─────┼───────┼───────┼────────────┘
                                    │       │       │
   ┌── HTTP/JMAP/Admin ──┐          │       │       │
   │ Service: <name>-http│◀─────────┴───────┴───────┘
   │ (ClusterIP, 8080)   │                 │
   └──────────┬──────────┘                 │
              │                            │
              ▼                            ▼
        Ingress (TLS)            ┌──────────────────────┐
                                 │  Data store          │  (config.json)
                                 │  Postgres / MySQL    │
                                 │  FoundationDB / Rocks│
                                 └──────────────────────┘
                                            │
                                            ▼ (configured at runtime)
                                 ┌──────────────────────┐
                                 │ Blob: S3 / Azure / FS│
                                 │ Lookup: Redis        │
                                 │ FTS: ES / Meilisearch│
                                 │ Directory: LDAP/SQL  │
                                 └──────────────────────┘

Quick start

helm repo add l4g https://l4gdev.github.io/helm-charts
helm install mail l4g/stalwart-mail-ha \
  -f charts/stalwart-mail-ha/examples/values-minimal.yaml

The minimal values use RocksDB on a single replica. For production HA, start with examples/values-ha.yaml (Postgres + S3 + Redis + LDAP).

First-boot bootstrap

Stalwart 0.16 stores its configuration inside the data store and auto-bootstraps roles, listeners, queues, and the web UI Application bundle on first start. It does NOT create an initial admin Account, so you must inject a fallback admin via STALWART_RECOVERY_ADMIN. The chart wires this for you whenever recovery.adminPassword (or recovery.existingSecret) is set, regardless of recovery.enabled.

helm install mail l4g/stalwart-mail-ha \
  --set recovery.adminPassword=ChangeMe \
  -f my-values.yaml

# Wait for the pod to download the web UI bundle from
# github.com/stalwartlabs/webui/releases/latest/download/webui.zip,
# then log in as admin/ChangeMe at:
#   https://<your-ingress-host>/admin/

Inside the admin UI you create real Accounts, domains, directories, blob/lookup backends, and so on. Once a real admin Account exists you can drop recovery.adminPassword from the values file and roll the deployment to remove the fallback.

recovery.enabled=true is a separate emergency mode that sets STALWART_RECOVERY_MODE=1. It skips the bootstrap defaults and only exposes /api/auth, /jmap, and /healthz — the web UI is NOT loaded. Use it to recover from a misconfigured data store, not for first boot.

Cross-origin webmail (Bulwark, JMAP clients)

Browsers reject credentialed CORS requests when the JMAP server replies with Access-Control-Allow-Origin: *. Stalwart 0.16 emits exactly that and has no built-in option for Allow-Credentials: true, so a webmail running on a different hostname will fail with The server is reachable but is blocking cross-origin requests.

Two ways to make it work, in order of preference:

  1. Override at the ingress. Add nginx.ingress.kubernetes.io/enable-cors: "true" plus cors-allow-origin, cors-allow-credentials, cors-allow-methods, and cors-allow-headers annotations to the Stalwart ingress. ingress-nginx handles preflight itself and replaces Stalwart's wildcard reply with a per-origin one. See examples/values-ha.yaml for the full annotation set.
  2. Configure it in Stalwart. In the admin UI go to Settings → HTTP, set usePermissiveCors=false, and add responseHeaders containing Access-Control-Allow-Origin: <webmail-origin> and Access-Control-Allow-Credentials: true. The values live in the data store along with the rest of the config.

A same-origin deployment (webmail on https://mail.example.com/webmail/, Stalwart on https://mail.example.com/) avoids the issue entirely. Bulwark supports a subpath via NEXT_PUBLIC_BASE_PATH.

Values

Top-level

KeyDefaultDescription
replicaCount2Pod replicas. RocksDB / SQLite force single replica.
image.repositorydocker.io/stalwartlabs/stalwartContainer image.
image.tag""Defaults to Chart.appVersion.
image.variant""Set fdb for FoundationDB image; auto-selected when dataStore.type=foundationdb.
publicUrlhttps://mail.example.comWired into STALWART_PUBLIC_URL.

Data store

KeyDefaultDescription
dataStore.typepostgresOne of postgres, mysql, foundationdb, rocksdb, sqlite.
dataStore.postgres.hostpg-cluster.example.svcPostgres host.
dataStore.postgres.existingSecret""Secret containing the Postgres password.
dataStore.postgres.existingSecretKeySTALWART_STORE_PG_PASSWORDKey inside the Secret.
dataStore.rocksdb.persistence.size20GiPVC size for embedded RocksDB.

Listeners

Each listener compiles to a containerPort and a Service port. Server-side binding (which protocol speaks on which port) is part of the runtime configuration applied through stalwart-cli.

ListenerDefaultPort
smtpenabled25
submissionenabled587
submissionsenabled465
imapenabled143
imapsenabled993
pop3disabled110
pop3sdisabled995
managesieveenabled4190
httpenabled8080

Optional resources

Each is gated behind <resource>.enabled:

  • ingress — HTTP/JMAP/admin only, multi-host TLS supported.
  • ingress.extra — additional Ingress objects for the same Service with their own annotations (e.g. whitelist-source-range / limit-rps on the admin UI or auth endpoints only).
  • metrics.serviceMonitor — Prometheus scrape, supports bearer-token auth.
  • networkPolicy — namespace-level ingress (or explicit ingressFrom peers, e.g. only the ingress-controller pods), DNS + outbound SMTP/HTTP egress, additionalEgressRules for your data stores.
  • podDisruptionBudget — minAvailable or maxUnavailable.
  • autoscaling — HPA on CPU and / or memory.

Required Secret keys

The chart never creates Secrets containing credentials; reference existing Secrets through existingSecret. Keys it expects to find:

BackendEnv var the chart maps into the containerDefault key
dataStore.postgresSTALWART_STORE_PG_PASSWORDconfigurable via existingSecretKey
dataStore.mysqlSTALWART_STORE_MYSQL_PASSWORDconfigurable via existingSecretKey
recoverySTALWART_RECOVERY_PASSWORDconfigurable via existingSecretKey

For blob/lookup/directory credentials, drop them in a Secret and add it to extraEnvFrom; the runtime apply plan can reference them via {"@type":"EnvVar","envVar":"..."}.

Upgrading

This chart targets Stalwart 0.16.x which is not compatible with the configuration files of 0.15 and earlier. If you are coming from 0.15, follow the upstream v0.16 upgrading guide first; the chart cannot perform that migration for you.

For 0.16.x → 0.16.y upgrades a helm upgrade is sufficient.

What's not in this chart

  • The Stalwart server-side configuration (SMTP listeners, DKIM, queues, rate limits). Apply via stalwart-cli apply — see examples/.
  • A bundled Postgres / Redis / S3. Bring your own; this chart is intentionally generic.
  • A built-in stalwart-cli Job. Bootstrap is run by an operator once, not on every upgrade.

Deploy stalwart-mail-ha with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has stalwart-mail-ha on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartstalwart-mail-ha is pinned at v0.1.3 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply