postfix

by dreitier

Helm chartv2.0.0App 1.0.0Verified publisher

Postfix SMTP relay that forwards mail from the cluster to an upstream SMTP server with TLS and SASL

About this chart

Helm chart: postfix - SMTP relay

Postfix as an SMTP relay in Kubernetes: applications in the cluster send mail without authentication to the service, Postfix forwards it to an upstream SMTP server (e.g. Mailgun, Amazon SES, Microsoft 365) with TLS and SASL authentication.

Getting started

$ helm repo add dreitier https://dreitier.github.io/helm-charts/
$ helm repo update
$ helm install postfix dreitier/postfix \
    --set smtp.relayHost='[smtp.mailgun.org]:587' \
    --set smtp.relayMyhostname=relay.example.com \
    --set [email protected] \
    --set secret.useExistingSecret=true \
    --set secret.existingSecretName=postfix-relay

The chart is also available as OCI artifact: oci://ghcr.io/dreitier/charts/postfix.

Applications use <release>-postfix.<namespace>.svc:25 as SMTP server, without authentication and TLS.

Configuration parameters

ParameterDescriptionDefault
smtp.relayHostUpstream SMTP server, e.g. [smtp.mailgun.org]:587 (brackets: no MX lookup). Required[smtp.mailgun.org]:587
smtp.relayMyhostnameHost name of the relay (HELO, Received: header). Requiredmy.host.local
smtp.relayUsernameSASL user name; without user name and password, SASL is disabled""
smtp.relayPasswordSASL password, stored in a Secret created by the chart. Prefer secret.useExistingSecret""
smtp.relayNetworksClients allowed to relay (Postfix mynetworks), comma-separated127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
smtp.tlsSecurityLevelTLS to the upstream server: encrypt (required), secure/verify (with certificate check), may, noneencrypt
smtp.tlsWrappermodetrue for implicit TLS (port 465), false for STARTTLS (ports 587/25)false
smtp.saslSecurityOptionsPostfix smtp_sasl_security_optionsnoanonymous, noplaintext
smtp.saslTlsSecurityOptionsPostfix smtp_sasl_tls_security_optionsnoanonymous
smtp.postfixParametersAny other main.cf parameter, e.g. {message_size_limit: "52428800"}{}
secret.useExistingSecretRead the password from an existing Secret instead of smtp.relayPasswordfalse
secret.existingSecretNameName of the existing Secretmy-postfix-secret
secret.existingSecretKeyKey of the password in the existing Secrettx-smtp-relay-password
extraEnvAdditional environment variables of the container[]
replicaCountNumber of replicas. Each replica has its own mail queue1
image.repository / image.tagImagedreitier/postfix / chart appVersion
service.type / service.port / service.annotationsServiceClusterIP / 25 / {}
serviceAccount.create / .name / .annotationsService accounttrue / generated / {}
serviceAccount.automountServiceAccountTokenMount the API token into the pod (Postfix doesn't need it)false
podAnnotations, podSecurityContext, securityContext, resources, nodeSelector, tolerations, affinityUsual pod settingsempty

The password is mounted as a file (TX_SMTP_RELAY_PASSWORD_FILE), not passed as an environment variable. The pod restarts when the configuration or the chart's Secret changes; after changing an existing Secret, restart it with kubectl rollout restart.

Security

Every client in smtp.relayNetworks can send mail with your credentials. In Kubernetes the default private networks include every pod and every node of the cluster. Keep the service internal (ClusterIP): with a LoadBalancer (externalTrafficPolicy: Cluster) or NodePort, external connections arrive with a node address and are allowed to relay. Narrow smtp.relayNetworks or add a NetworkPolicy if only some workloads should send mail.

The Postfix master process runs as root and drops privileges for its daemons; runAsNonRoot doesn't work.

Queued mail (e.g. while the upstream server is unreachable) lives in the container and is lost when the pod is replaced.

Upgrading to chart 2.0.0 (image 1.x)

  • smtp.saslSecurityLevel was renamed to smtp.tlsSecurityLevel, default encrypt instead of may (TLS to the upstream server is required). The chart refuses to render with the old key.
  • smtp.relayNetworks defaults to the private networks; the old default contained the public range 192.0.0.0/8. Check values that set it explicitly.
  • smtp.relayUsername / smtp.relayPassword default to empty (SASL disabled) instead of placeholders.
  • rbac.* and autoscaling.* were removed: Postfix doesn't use the Kubernetes API, and the HorizontalPodAutoscaler used the API version autoscaling/v2beta1 removed in Kubernetes 1.25.
  • The password is mounted as a file; existing Secrets keep working (key configurable with secret.existingSecretKey).
  • TCP readiness/liveness probes on port 25.
  • Image 1.x: logs on stdout only, Postfix in the foreground, see the postfix-docker changelog.

Deploy postfix with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has postfix 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 chartpostfix is pinned at v2.0.0 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