diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md
index 43284b09..7e3e7018 100755
--- a/.claude/CLAUDE.md
+++ b/.claude/CLAUDE.md
@@ -80,7 +80,7 @@ Violations cause state drift, which causes future applies to break or silently r
**Flow**: `git push → GHA build+push DockerHub (8-char SHA) → POST Woodpecker API → kubectl set image`
-**Migrated to GHA** (9): Website, k8s-portal, f1-stream, claude-memory-mcp, apple-health-data, audiblez-web, plotting-book, insta2spotify, audiobook-search
+**Migrated to GHA** (10): Website, k8s-portal, f1-stream, claude-memory-mcp, apple-health-data, audiblez-web, plotting-book, insta2spotify, audiobook-search, council-complaints
**Woodpecker-only**: travel_blog (1.4GB content too large for GHA), infra pipelines (terragrunt apply, certbot, build-cli — need cluster access)
**Per-project files**:
@@ -89,7 +89,7 @@ Violations cause state drift, which causes future applies to break or silently r
- `.woodpecker/build-fallback.yml` — Old full build pipeline preserved (event: `deployment` — never auto-fires)
**Woodpecker API**: Uses **numeric repo IDs** (`/api/repos/2/pipelines`), NOT owner/name paths (those return HTML).
-Repo IDs: infra=1, Website=2, finance=3, health=4, travel_blog=5, webhook-handler=6, audiblez-web=9, f1-stream=10, plotting-book=43, claude-memory-mcp=78, infra-onboarding=79
+Repo IDs: infra=1, Website=2, finance=3, health=4, travel_blog=5, webhook-handler=6, audiblez-web=9, f1-stream=10, plotting-book=43, claude-memory-mcp=78, infra-onboarding=79, council-complaints=TBD
**Woodpecker YAML gotchas**:
- Commands with `${VAR}:${VAR}` must be **quoted** — unquoted `:` triggers YAML map parsing when vars are empty
@@ -131,7 +131,7 @@ Repo IDs: infra=1, Website=2, finance=3, health=4, travel_blog=5, webhook-handle
- Exclude completed CronJob pods from "pod not ready" alerts.
- Every new service gets Prometheus scrape config + Uptime Kuma monitor.
- Key alerts: OOMKill, pod replica mismatch, 4xx/5xx error rates, UPS battery, CPU temp, SSD writes, NFS responsiveness, ClusterMemoryRequestsHigh (>85%), ContainerNearOOM (>85% limit), PodUnschedulable.
-- **E2E email monitoring**: CronJob `email-roundtrip-monitor` (every 30 min) sends test email via Mailgun API to `smoke-test@viktorbarzin.me` (catch-all → `spam@`), verifies IMAP delivery, deletes test email, pushes metrics to Pushgateway + Uptime Kuma. Alerts: `EmailRoundtripFailing` (90m), `EmailRoundtripStale` (90m), `EmailRoundtripNeverRun` (2h). Vault: `mailgun_api_key` in `secret/viktor`.
+- **E2E email monitoring**: CronJob `email-roundtrip-monitor` (every 20 min) sends test email via Mailgun API to `smoke-test@viktorbarzin.me` (catch-all → `spam@`), verifies IMAP delivery, deletes test email, pushes metrics to Pushgateway + Uptime Kuma. Alerts: `EmailRoundtripFailing` (60m), `EmailRoundtripStale` (60m), `EmailRoundtripNeverRun` (60m). Outbound relay: Brevo EU (`smtp-relay.brevo.com:587`, 300/day free — migrated from Mailgun). Mailserver on dedicated MetalLB IP `10.0.20.202` with `externalTrafficPolicy: Local` for CrowdSec real-IP detection. Vault: `mailgun_api_key` in `secret/viktor` (probe), `brevo_api_key` in `secret/viktor` (relay).
## Storage & Backup Architecture
diff --git a/config.tfvars b/config.tfvars
index 35620563..3824c21f 100644
Binary files a/config.tfvars and b/config.tfvars differ
diff --git a/docs/architecture/mailserver-visual.html b/docs/architecture/mailserver-visual.html
new file mode 100644
index 00000000..8d45627e
--- /dev/null
+++ b/docs/architecture/mailserver-visual.html
@@ -0,0 +1,665 @@
+
+
+
+
+
+
+Mail Server Architecture — viktorbarzin.me
+
+
+
+
+
+
+
+
+
+
+
+
+ Operational
+ Mail Server Architecture
+ Self-hosted email infrastructure for viktorbarzin.me on Kubernetes with CrowdSec protection
+
+ docker-mailserver 15.0.0
+ |
+ Updated 2026-04-12
+
+
+
+
+
+
+
+
+
30m
+
Alert Threshold
+
+
+
+
Local
+
Traffic Policy
+
+
+
+
+
+
Inbound Mail Flow
+
+
+
+
📧
+
Sender MTA
+
MX lookup
+
+
+
+
🌐
+
mail.viktorbarzin.me
+
176.12.22.76
+
+
+
+
🛡
+
pfSense
+
port 25 fwd
+
+
+
+
⚖
+
MetalLB
+
ETP: Local
+
+
+
+
📬
+
Postfix
+
+ CrowdSec
+
+
+
+
🔍
+
Rspamd
+
spam/DKIM/DMARC
+
+
+
+
📥
+
Dovecot
+
IMAP :993
+
+
+
+
+
+
+
+
Outbound Mail Flow
+
+
+
+
📬
+
Postfix
+
relayhost
+
+
+
+
🚀
+
Mailgun EU
+
smtp.eu.mailgun.org
+
+
+
+
📧
+
Recipient
+
IP reputation handled
+
+
+
+
+
+
+
+
DNS Records
+
+
+ | Type | Name | Value | Status |
+
+
+ | MX | viktorbarzin.me | mail.viktorbarzin.me (pri 1) | OK |
+ | A | mail.viktorbarzin.me | 176.12.22.76 (DNS-only) | OK |
+ | AAAA | mail.viktorbarzin.me | 2001:470:6e:43d::2 | OK |
+ | SPF | viktorbarzin.me | v=spf1 include:mailgun.org -all | Hard Fail |
+ | DKIM | s1._domainkey | RSA 1024-bit (Mailgun outbound) | OK |
+ | DKIM | mail._domainkey | RSA 2048-bit (Rspamd signing) | OK |
+ | DMARC | _dmarc | p=quarantine; pct=100 | OK |
+ | MTA-STS | _mta-sts | v=STSv1; id=20260412 | OK |
+ | TLSRPT | _smtp._tls | rua=mailto:postmaster@viktorbarzin.me | OK |
+
+
+
+
+
⚠
+
PTR Mismatch: Reverse DNS returns 176-12-22-76.pon.spectrumnet.bg (ISP-assigned) instead of mail.viktorbarzin.me. ISP-controlled, cannot fix. Minimal impact — Gmail/Outlook rely on SPF/DKIM/DMARC.
+
+
+
+
+
+
Security Layers
+
+
+
🛡 CrowdSec
+
+ crowdsecurity/postfix + dovecot collections
+ - Real client IPs via ETP: Local on
10.0.20.202
+ - Automatic brute-force detection & ban
+
+
+
+
🔍 Rspamd
+
+ - Spam filtering + phishing detection
+ - DKIM signing (selector:
mail, 2048-bit)
+ - DMARC verification on inbound
+ - Auto-learns from Junk folder
+
+
+
+
🚦 Postfix Rate Limiting
+
+ - 10 connections/min per client
+ - 30 messages/min per client
+ - Now effective with real IPs (ETP: Local)
+
+
+
+
🔒 TLS Enforcement
+
+ - Let's Encrypt wildcard cert
+ - MTA-STS enforces TLS for inbound
+ - TLSRPT for failure reporting
+ - STARTTLS on SMTP, SSL on IMAP
+
+
+
+
+
+
+
+
Monitoring & Alerts
+
+
+
📊
+
+
MailServerDown
+
No replicas for 5m
+
+
+
+
📧
+
+
EmailRoundtripFailing
+
Probe failing for 30m
+
+
+
+
⏱
+
+
EmailRoundtripStale
+
No success in >40m
+
+
+
+
❓
+
+
EmailRoundtripNeverRun
+
Metric absent for 40m
+
+
+
+
+
+ | Monitor | Type | Target | Interval |
+
+ | E2E Roundtrip Probe | CronJob | Mailgun API → MX → IMAP | */10 * * * * |
+ | SMTP External | Uptime Kuma | 176.12.22.76:25 | 60s |
+ | Dovecot Exporter | Prometheus | :9166/metrics | scrape |
+
+
+
+
+
+
+
+
Terraform Stacks
+
+ | Stack | Path | Resources |
+
+ | Mailserver | stacks/mailserver/ | Namespace, Deployment, Service, CronJob, PVCs |
+ | DNS | stacks/cloudflared/ | MX, SPF, DKIM x2, DMARC, MTA-STS, TLSRPT |
+ | Monitoring | stacks/monitoring/ | Prometheus alert rules |
+ | CrowdSec | stacks/crowdsec/ | postfix + dovecot collections, log acquisition |
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/architecture/mailserver.md b/docs/architecture/mailserver.md
new file mode 100644
index 00000000..1c70c087
--- /dev/null
+++ b/docs/architecture/mailserver.md
@@ -0,0 +1,246 @@
+# Mail Server Architecture
+
+Last updated: 2026-04-12 (Brevo relay migration)
+
+## Overview
+
+Self-hosted email for `viktorbarzin.me` using docker-mailserver 15.0.0 on Kubernetes. Inbound mail arrives directly via MX record to the home IP on port 25. Outbound mail relays through Mailgun EU. Roundcubemail provides webmail access. CrowdSec protects SMTP/IMAP from brute-force attacks using real client IPs via `externalTrafficPolicy: Local` on a dedicated MetalLB IP.
+
+## Architecture Diagram
+
+```mermaid
+graph TB
+ subgraph "Inbound Mail"
+ SENDER[Sending MTA] -->|MX lookup| MX[mail.viktorbarzin.me:25]
+ MX -->|176.12.22.76:25| PF[pfSense NAT]
+ PF -->|10.0.20.202:25| MLB[MetalLB
ETP: Local]
+ MLB --> POSTFIX[Postfix MTA]
+ end
+
+ subgraph "Mail Processing"
+ POSTFIX --> RSPAMD[Rspamd
Spam/DKIM/DMARC]
+ RSPAMD --> DOVECOT[Dovecot IMAP]
+ DOVECOT --> MAILBOX[(Mailboxes
proxmox-lvm PVC)]
+ end
+
+ subgraph "Outbound Mail"
+ POSTFIX_OUT[Postfix] -->|SASL + TLS| MAILGUN[Brevo EU Relay
smtp-relay.brevo.com:587]
+ MAILGUN --> RECIPIENT[Recipient]
+ end
+
+ subgraph "Webmail"
+ USER[User] -->|HTTPS| TRAEFIK[Traefik Ingress]
+ TRAEFIK --> RC[Roundcubemail]
+ RC -->|IMAP 993| DOVECOT
+ RC -->|SMTP 587| POSTFIX_OUT
+ end
+
+ subgraph "Security"
+ MLB -->|Real client IPs| CS_AGENT[CrowdSec Agent
postfix + dovecot parsers]
+ CS_AGENT --> CS_LAPI[CrowdSec LAPI]
+ end
+
+ subgraph "Monitoring"
+ PROBE[E2E Roundtrip Probe
CronJob every 10m] -->|Mailgun API| SENDER
+ PROBE -->|IMAP check| DOVECOT
+ PROBE --> PUSH[Pushgateway + Uptime Kuma]
+ DEXP[Dovecot Exporter
:9166] --> PROM[Prometheus]
+ end
+```
+
+## Components
+
+| Component | Version | Location | Purpose |
+|-----------|---------|----------|---------|
+| docker-mailserver | 15.0.0 | `mailserver` namespace | Postfix MTA + Dovecot IMAP + Rspamd |
+| Roundcubemail | 1.6.13-apache | `mailserver` namespace | Webmail UI (MySQL-backed) |
+| Dovecot Exporter | latest | Sidecar in mailserver pod | Prometheus metrics (port 9166) |
+| Rspamd | Built into docker-mailserver | — | Spam filtering, DKIM signing, DMARC verification |
+| Brevo EU (ex-Sendinblue) | SaaS | — | Outbound SMTP relay (300/day free) |
+
+## Mail Flow
+
+### Inbound
+```
+Internet → MX: mail.viktorbarzin.me (priority 1)
+ → A record: 176.12.22.76 (non-proxied Cloudflare DNS-only)
+ → pfSense NAT: port 25 → 10.0.20.202:25
+ → MetalLB (dedicated IP, ETP: Local — preserves real client IPs)
+ → Postfix → Rspamd (spam + DKIM + DMARC check) → Dovecot → mailbox
+```
+
+No backup MX. If the server is down, sender MTAs queue and retry for 4-5 days per SMTP standards (RFC 5321).
+
+### Outbound
+```
+Postfix → relayhost [smtp-relay.brevo.com]:587 (SASL auth + TLS required)
+ → Brevo handles IP reputation, deliverability, bounce processing
+ → 300 emails/day free tier (migrated from Mailgun 100/day on 2026-04-12)
+```
+
+### Webmail
+```
+https://mail.viktorbarzin.me → Traefik → Roundcubemail
+ IMAP: ssl://mailserver:993 (internal K8s service)
+ SMTP: tls://mailserver:587 (internal K8s service)
+ DB: MySQL (mysql.dbaas.svc.cluster.local)
+```
+
+## DNS Records
+
+All managed in Terraform at `stacks/cloudflared/modules/cloudflared/cloudflare.tf`.
+
+| Type | Name | Value | Purpose |
+|------|------|-------|---------|
+| MX | `viktorbarzin.me` | `mail.viktorbarzin.me` (pri 1) | Inbound mail routing |
+| A | `mail.viktorbarzin.me` | `176.12.22.76` (non-proxied) | Mail server IP |
+| AAAA | `mail.viktorbarzin.me` | `2001:470:6e:43d::2` | IPv6 (HE tunnel) |
+| TXT (SPF) | `viktorbarzin.me` | `v=spf1 include:mailgun.org -all` | Authorize Mailgun for outbound |
+| TXT (DKIM) | `s1._domainkey` | RSA 1024-bit key | Mailgun DKIM (roundtrip probe) |
+| TXT (DKIM) | `mail._domainkey` | RSA 2048-bit key | Rspamd self-hosted DKIM signing |
+| CNAME (DKIM) | `brevo1._domainkey` | b1.viktorbarzin-me.dkim.brevo.com | Brevo outbound DKIM (delegated) |
+| CNAME (DKIM) | `brevo2._domainkey` | b2.viktorbarzin-me.dkim.brevo.com | Brevo outbound DKIM (delegated) |
+| TXT | `viktorbarzin.me` | `brevo-code:a6ef1dd9...` | Brevo domain verification |
+| TXT (DMARC) | `_dmarc` | `p=quarantine; pct=100` | DMARC enforcement, reports to Mailgun + ondmarc |
+| TXT (MTA-STS) | `_mta-sts` | `v=STSv1; id=20260412` | TLS enforcement for inbound |
+| TXT (TLSRPT) | `_smtp._tls` | `v=TLSRPTv1; rua=mailto:postmaster@...` | TLS failure reporting |
+
+### Known Limitation: PTR Mismatch
+
+Reverse DNS for `176.12.22.76` returns `176-12-22-76.pon.spectrumnet.bg.` (ISP-assigned) instead of `mail.viktorbarzin.me`. This is ISP-controlled and cannot be changed on a residential connection. Most modern providers (Gmail, Outlook) rely on SPF/DKIM/DMARC rather than PTR, so impact is minimal.
+
+## Security
+
+### CrowdSec Integration
+- **Collections**: `crowdsecurity/postfix` + `crowdsecurity/dovecot` (installed)
+- **Log acquisition**: CrowdSec agents parse mailserver pod logs for brute-force patterns
+- **Real client IPs**: `externalTrafficPolicy: Local` on dedicated MetalLB IP `10.0.20.202` preserves original client IPs (not SNATed to node IPs)
+- **Decisions**: CrowdSec bans/challenges attackers via firewall bouncer rules
+
+### Rspamd
+- Spam filtering with phishing detection and Oletools
+- DKIM signing (selector `mail`, 2048-bit RSA)
+- DMARC verification on inbound mail
+- Auto-learns from Junk folder movements (`RSPAMD_LEARN=1`)
+- SRS (Sender Rewriting Scheme) enabled for forwarded mail
+
+### Postfix Rate Limiting
+```
+smtpd_client_connection_rate_limit = 10 # per minute per client
+smtpd_client_message_rate_limit = 30 # per minute per client
+anvil_rate_time_unit = 60s
+```
+
+### TLS
+- Wildcard Let's Encrypt cert (`*.viktorbarzin.me`) for SMTP STARTTLS and IMAPS
+- Renewed via Woodpecker CI cron pipeline (DNS-01 challenge via Cloudflare)
+- MTA-STS enforces TLS for inbound delivery
+
+## Monitoring
+
+### E2E Roundtrip Probe
+CronJob `email-roundtrip-monitor` (every 10 min):
+1. Sends test email via Mailgun HTTP API to `smoke-test@viktorbarzin.me`
+2. Email hits MX → Postfix → catch-all delivers to `spam@` mailbox
+3. Verifies delivery via IMAP (searches by UUID marker)
+4. Deletes test email, pushes metrics to Pushgateway + Uptime Kuma
+
+### Prometheus Alerts
+| Alert | Threshold | Severity |
+|-------|-----------|----------|
+| MailServerDown | No replicas for 5m | warning |
+| EmailRoundtripFailing | Probe failing for 30m | warning |
+| EmailRoundtripStale | No success in >40m | warning |
+| EmailRoundtripNeverRun | Metric absent for 40m | warning |
+
+### Uptime Kuma Monitors
+- TCP SMTP on `176.12.22.76:25` (external, 60s interval)
+- TCP IMAP on `10.0.20.202:993` (internal)
+- E2E Push monitor (receives push from roundtrip probe)
+
+### Dovecot Exporter
+- Sidecar container in mailserver pod, port 9166
+- Scraped by Prometheus for IMAP connection metrics
+
+## Terraform
+
+| Stack | Path | Resources |
+|-------|------|-----------|
+| Mailserver | `stacks/mailserver/` | Namespace, deployment, service, CronJob, PVCs |
+| DNS | `stacks/cloudflared/modules/cloudflared/cloudflare.tf` | MX, SPF, DKIM, DMARC, MTA-STS, TLSRPT records |
+| Monitoring | `stacks/monitoring/` | Prometheus alert rules |
+| CrowdSec | `stacks/crowdsec/` | Collections, log acquisition (already configured) |
+
+### Secrets (Vault)
+| Path | Key | Purpose |
+|------|-----|---------|
+| `secret/platform` | `mailserver_accounts` | User credentials (JSON) |
+| `secret/platform` | `mailserver_aliases` | Postfix virtual aliases |
+| `secret/platform` | `mailserver_opendkim_key` | DKIM private key |
+| `secret/platform` | `mailserver_sasl_passwd` | Mailgun relay credentials |
+| `secret/viktor` | `mailgun_api_key` | Mailgun API for E2E probe (inbound testing) |
+| `secret/viktor` | `brevo_api_key` | Brevo API key (stored for reference) |
+
+## Storage
+
+| PVC | Size | Storage Class | Purpose |
+|-----|------|---------------|---------|
+| `mailserver-data-proxmox` | 2Gi (auto-resize 5Gi) | proxmox-lvm | Mail data, state, logs |
+| `roundcubemail-html-proxmox` | 1Gi | proxmox-lvm | Roundcube web files |
+| `roundcubemail-enigma-proxmox` | 1Gi | proxmox-lvm | Roundcube encryption |
+
+## Decisions & Rationale
+
+### No Backup MX
+- **Alternatives considered**: ForwardEmail (free relay), Cloudflare Email Routing, Dynu Store/Forward
+- **Decision**: Direct MX only. ForwardEmail relay was evaluated (2026-04-12) and abandoned — its anti-spoofing enforcement rejects legitimate forwarded mail regardless of SPF configuration. Cloudflare Email Routing can't store-and-forward (pass-through proxy only). Dynu ($9.99/yr) is a viable future option.
+- **Tradeoff**: If server is down, mail delivery relies on sender MTA retry queues (4-5 days standard). No immediate forwarding to a backup address.
+
+### Brevo for Outbound (migrated from Mailgun 2026-04-12)
+- **Decision**: All outbound relays through Brevo EU (ex-Sendinblue). 300 emails/day free tier (3x Mailgun's 100/day).
+- **Why migrated**: Mailgun's 100/day limit was too tight — the E2E probe uses ~72/day, leaving only 28 for real mail.
+- **DKIM**: Brevo uses delegated DKIM via CNAME (`brevo1._domainkey`, `brevo2._domainkey`). Mailgun's `s1._domainkey` retained for the roundtrip probe (still uses Mailgun API for inbound testing).
+- **Tradeoff**: Dependency on Brevo SaaS for outbound.
+
+### Rspamd over SpamAssassin/OpenDKIM
+- **Decision**: Rspamd replaces both SpamAssassin and OpenDKIM in a single component
+- **Tradeoff**: Higher memory usage (~150-200MB) but simpler stack
+
+### Dedicated MetalLB IP for CrowdSec
+- **Decision**: Mailserver gets `10.0.20.202` (separate from shared `10.0.20.200`) with `externalTrafficPolicy: Local`
+- **Why**: Shared IP with ETP: Cluster SNATs away real client IPs, making CrowdSec detections and Postfix rate limiting useless
+- **Tradeoff**: Uses one extra IP from the MetalLB pool. Requires separate pfSense NAT rule.
+
+## Troubleshooting
+
+### Inbound mail not arriving
+1. Check MX: `dig MX viktorbarzin.me +short` → should show `mail.viktorbarzin.me`
+2. Check port 25: `nc -zw5 mail.viktorbarzin.me 25`
+3. Check pfSense NAT rule: port 25 → `10.0.20.202:25`
+4. Check Postfix logs: `kubectl logs -n mailserver deploy/mailserver -c docker-mailserver | grep -E 'from=|reject'`
+5. Check if CrowdSec is blocking the sender: `kubectl exec -n crowdsec deploy/crowdsec-lapi -- cscli decisions list`
+
+### Outbound mail failing
+1. Check Brevo relay: `kubectl logs -n mailserver deploy/mailserver -c docker-mailserver | grep relay` — should show `relay=smtp-relay.brevo.com`
+2. Check SASL credentials: `vault kv get -field=mailserver_sasl_passwd secret/platform` — should show `[smtp-relay.brevo.com]:587`
+3. Check Brevo dashboard for delivery status
+4. SASL auth failure → verify SMTP key (xsmtpsib-...) and login (a7e778001@smtp-brevo.com)
+
+### E2E roundtrip probe failing
+1. Check CronJob: `kubectl get cronjob -n mailserver email-roundtrip-monitor`
+2. Check job logs: `kubectl logs -n mailserver -l job-name --tail=20`
+3. Check Mailgun rate limit (HTTP 429 errors mean too many API calls)
+4. Check IMAP login: verify `spam@viktorbarzin.me` password in Vault (`secret/platform` → `mailserver_accounts`)
+
+### Spam/brute-force attacks
+1. Check CrowdSec decisions: `kubectl exec -n crowdsec deploy/crowdsec-lapi -- cscli decisions list`
+2. Check Postfix logs for auth failures: `kubectl logs -n mailserver deploy/mailserver -c docker-mailserver | grep 'authentication failed'`
+3. Verify real client IPs in logs (not 10.0.20.x node IPs)
+
+## Related
+
+- [Monitoring Architecture](monitoring.md) — alert definitions, Uptime Kuma
+- [Networking Architecture](networking.md) — MetalLB, pfSense NAT, Cloudflare DNS
+- [Security Architecture](security.md) — CrowdSec deployment
+- [Secrets Management](secrets.md) — Vault paths for mail credentials
+- [Mailserver Hardening Plan](../plans/2026-02-23-mailserver-hardening-plan.md) — historical
diff --git a/docs/architecture/monitoring.md b/docs/architecture/monitoring.md
index 97477ca1..983bf3f2 100644
--- a/docs/architecture/monitoring.md
+++ b/docs/architecture/monitoring.md
@@ -15,7 +15,7 @@ graph TB
GPU[NVIDIA GPU via dcgm-exporter]
UPS[UPS Exporter]
NFS[NFS Exporter]
- EMAIL[Email Roundtrip Probe
CronJob every 30m]
+ EMAIL[Email Roundtrip Probe
CronJob every 10m]
end
subgraph "Monitoring Stack (platform stack)"
@@ -148,11 +148,11 @@ spec:
- **4xx/5xx Error Rates**: HTTP error rate threshold exceeded
#### Email Monitoring Alerts
-- **EmailRoundtripFailing**: E2E email probe returning failure for >90m
-- **EmailRoundtripStale**: No successful email round-trip in >90m
-- **EmailRoundtripNeverRun**: Email probe has never reported (CronJob not running)
+- **EmailRoundtripFailing**: E2E email probe returning failure for >30m
+- **EmailRoundtripStale**: No successful email round-trip in >40m
+- **EmailRoundtripNeverRun**: Email probe has never reported (40m)
-The email monitoring system uses a CronJob (`email-roundtrip-monitor`, every 30 min) in the `mailserver` namespace that:
+The email monitoring system uses a CronJob (`email-roundtrip-monitor`, every 10 min) in the `mailserver` namespace that:
1. Sends a test email via Mailgun HTTP API to `smoke-test@viktorbarzin.me`
2. Email lands in the `spam@` catch-all mailbox via MX delivery
3. Verifies delivery via IMAP (searches by UUID marker in subject)
@@ -160,7 +160,7 @@ The email monitoring system uses a CronJob (`email-roundtrip-monitor`, every 30
5. Pushes metrics (`email_roundtrip_success`, `email_roundtrip_duration_seconds`, `email_roundtrip_last_success_timestamp`) to Prometheus Pushgateway
6. Pushes status to Uptime Kuma E2E Push monitor
-Uptime Kuma also has TCP monitors for SMTP (port 25) and IMAP (port 993) on `10.0.20.200`.
+Uptime Kuma monitors: TCP SMTP (port 25) on `176.12.22.76` (external), IMAP (port 993) on `10.0.20.202`, and Dovecot exporter metrics on port 9166.
#### Backup Alerts
- **PostgreSQLBackupStale**: >36h since last backup
diff --git a/docs/plans/2026-02-23-mailserver-hardening-design.md b/docs/plans/2026-02-23-mailserver-hardening-design.md
index 33657c20..d0a9f56b 100644
--- a/docs/plans/2026-02-23-mailserver-hardening-design.md
+++ b/docs/plans/2026-02-23-mailserver-hardening-design.md
@@ -2,6 +2,7 @@
**Date**: 2026-02-23
**Scope**: Security, reliability, and hygiene improvements to the docker-mailserver stack
+**Status**: Completed. ForwardEmail relay removed 2026-04-12 — MX now direct to mail.viktorbarzin.me on dedicated MetalLB IP with CrowdSec protection.
## Current State
diff --git a/docs/plans/2026-02-23-mailserver-hardening-plan.md b/docs/plans/2026-02-23-mailserver-hardening-plan.md
index b555017f..042c50b3 100644
--- a/docs/plans/2026-02-23-mailserver-hardening-plan.md
+++ b/docs/plans/2026-02-23-mailserver-hardening-plan.md
@@ -4,6 +4,8 @@
**Goal:** Harden the mail server with spam filtering (Rspamd), DMARC enforcement, rate limiting, monitoring alerts, and hygiene cleanup.
+**Status**: Completed. ForwardEmail references in this plan are historical — relay removed 2026-04-12. MX points directly to mail.viktorbarzin.me.
+
**Architecture:** All changes are to the existing docker-mailserver 15.0.0 deployment managed by Terraform. Rspamd replaces OpenDKIM for DKIM signing and adds spam filtering. DMARC moves from `none` to `quarantine` in Cloudflare DNS. Postfix gets rate-limiting parameters. Prometheus gets a mailserver-down alert. Roundcubemail debug logging is disabled and image pinned.
**Tech Stack:** Terraform/HCL, docker-mailserver, Rspamd, Cloudflare DNS, Prometheus
diff --git a/stacks/cloudflared/modules/cloudflared/cloudflare.tf b/stacks/cloudflared/modules/cloudflared/cloudflare.tf
index 54f376af..f7d25120 100644
--- a/stacks/cloudflared/modules/cloudflared/cloudflare.tf
+++ b/stacks/cloudflared/modules/cloudflared/cloudflare.tf
@@ -113,46 +113,19 @@ resource "cloudflare_record" "non_proxied_dns_record_ipv6" {
zone_id = var.cloudflare_zone_id
}
-resource "cloudflare_record" "forwardemail_mx1" {
- content = "mx1.forwardemail.net"
+resource "cloudflare_record" "mail_mx" {
+ content = "mail.viktorbarzin.me"
name = "viktorbarzin.me"
proxied = false
ttl = 1
type = "MX"
- priority = 10
+ priority = 1
zone_id = var.cloudflare_zone_id
}
-resource "cloudflare_record" "forwardemail_mx2" {
- content = "mx2.forwardemail.net"
- name = "viktorbarzin.me"
- proxied = false
- ttl = 1
- type = "MX"
- priority = 10
- zone_id = var.cloudflare_zone_id
-}
-
-resource "cloudflare_record" "forwardemail_config" {
- content = "\"forward-email=mail.viktorbarzin.me\""
- name = "viktorbarzin.me"
- proxied = false
- ttl = 1
- type = "TXT"
- zone_id = var.cloudflare_zone_id
-}
-
-resource "cloudflare_record" "forwardemail_port" {
- content = "\"forward-email-port=266\""
- name = "viktorbarzin.me"
- proxied = false
- ttl = 1
- type = "TXT"
- zone_id = var.cloudflare_zone_id
-}
resource "cloudflare_record" "mail_domainkey" {
- content = "\"k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIDLB8mhAHNqs1s6GeZMQHOxWweoNKIrqo5tqRM3yFilgfPUX34aTIXNZg9xAmlK+2S/xXO1ymt127ZGMjnoFKOEP8/uZ54iHTCnioHaPZWMfJ7o6TYIXjr+9ShKfoJxZLv7lHJ2wKQK3yOw4lg4cvja5nxQ6fNoGRwo+mQ/mgJQIDAQAB\""
+ content = "\"v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIDLB8mhAHNqs1s6GeZMQHOxWweoNKIrqo5tqRM3yFilgfPUX34aTIXNZg9xAmlK+2S/xXO1ymt127ZGMjnoFKOEP8/uZ54iHTCnioHaPZWMfJ7o6TYIXjr+9ShKfoJxZLv7lHJ2wKQK3yOw4lg4cvja5nxQ6fNoGRwo+mQ/mgJQIDAQAB\""
name = "s1._domainkey.viktorbarzin.me"
proxied = false
ttl = 1
@@ -162,7 +135,7 @@ resource "cloudflare_record" "mail_domainkey" {
}
resource "cloudflare_record" "mail_spf" {
- content = "\"v=spf1 include:mailgun.org ~all\""
+ content = "\"v=spf1 include:mailgun.org -all\""
name = "viktorbarzin.me"
proxied = false
ttl = 1
@@ -171,6 +144,60 @@ resource "cloudflare_record" "mail_spf" {
zone_id = var.cloudflare_zone_id
}
+resource "cloudflare_record" "mail_domainkey_rspamd" {
+ content = "\"v=DKIM1; h=sha256; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs9XHeFBKhUAEJSikXx+P49Q3nEBbnaSpn6h/9TqIhKaZWSVa2uGUGYQieNdon7DEJZ0VFo0Tvm3/UFsy2qF7ZmF+E/+N8EmkcPrMlxgJT281dpk5DxrZ+kbzw/DosfHH71K6vCLB4rSexzxJHaAx0AUddI3bFUJGjMgCXXCMZF+p8YCx+DDGPIXz2FOTtlJlR7aeZ2xXavwE/lBfI3MLnsq7X+GhPjQEax070nndOdZI0S8HpZkVxdGWl1N2Ec6LukYm2RiUkEMMQHSYX7WF3JBc+CGqUyd706Iy/5oeC3UGwZSM2uLkrp8YBjmw/h1rAeyv/ITt6ZXraP/cIMRiVQIDAQAB\""
+ name = "mail._domainkey.viktorbarzin.me"
+ proxied = false
+ ttl = 1
+ type = "TXT"
+ zone_id = var.cloudflare_zone_id
+}
+
+resource "cloudflare_record" "brevo_domainkey1" {
+ content = "b1.viktorbarzin-me.dkim.brevo.com."
+ name = "brevo1._domainkey.viktorbarzin.me"
+ proxied = false
+ ttl = 1
+ type = "CNAME"
+ zone_id = var.cloudflare_zone_id
+}
+
+resource "cloudflare_record" "brevo_domainkey2" {
+ content = "b2.viktorbarzin-me.dkim.brevo.com."
+ name = "brevo2._domainkey.viktorbarzin.me"
+ proxied = false
+ ttl = 1
+ type = "CNAME"
+ zone_id = var.cloudflare_zone_id
+}
+
+resource "cloudflare_record" "brevo_code" {
+ content = "\"brevo-code:a6ef1dd91b248559900246eb4e7ceebd\""
+ name = "viktorbarzin.me"
+ proxied = false
+ ttl = 1
+ type = "TXT"
+ zone_id = var.cloudflare_zone_id
+}
+
+resource "cloudflare_record" "mail_mta_sts" {
+ content = "\"v=STSv1; id=20260412\""
+ name = "_mta-sts.viktorbarzin.me"
+ proxied = false
+ ttl = 1
+ type = "TXT"
+ zone_id = var.cloudflare_zone_id
+}
+
+resource "cloudflare_record" "mail_tlsrpt" {
+ content = "\"v=TLSRPTv1; rua=mailto:postmaster@viktorbarzin.me\""
+ name = "_smtp._tls.viktorbarzin.me"
+ proxied = false
+ ttl = 1
+ type = "TXT"
+ zone_id = var.cloudflare_zone_id
+}
+
resource "cloudflare_record" "mail_dmarc" {
content = "\"v=DMARC1; p=quarantine; pct=100; fo=1; ri=3600; sp=quarantine; adkim=r; aspf=r; rua=mailto:e21c0ff8@dmarc.mailgun.org,mailto:adb84997@inbox.ondmarc.com; ruf=mailto:e21c0ff8@dmarc.mailgun.org,mailto:adb84997@inbox.ondmarc.com,mailto:postmaster@viktorbarzin.me;\""
name = "_dmarc.viktorbarzin.me"
diff --git a/stacks/mailserver/modules/mailserver/main.tf b/stacks/mailserver/modules/mailserver/main.tf
index 7f5c0055..81308138 100644
--- a/stacks/mailserver/modules/mailserver/main.tf
+++ b/stacks/mailserver/modules/mailserver/main.tf
@@ -68,7 +68,7 @@ resource "kubernetes_config_map" "mailserver_env_config" {
POSTFIX_REJECT_UNKNOWN_CLIENT_HOSTNAME = "1"
# TLS_LEVEL = "intermediate"
# DEFAULT_RELAY_HOST = "[smtp.sendgrid.net]:587"
- DEFAULT_RELAY_HOST = "[smtp.eu.mailgun.org]:587"
+ DEFAULT_RELAY_HOST = "[smtp-relay.brevo.com]:587"
SPOOF_PROTECTION = "1"
SSL_TYPE = "manual"
SSL_CERT_PATH = "/tmp/ssl/tls.crt"
@@ -487,14 +487,13 @@ resource "kubernetes_service" "mailserver" {
}
annotations = {
- "metallb.io/loadBalancerIPs" = "10.0.20.200"
- "metallb.io/allow-shared-ip" = "shared"
+ "metallb.io/loadBalancerIPs" = "10.0.20.202"
}
}
spec {
type = "LoadBalancer"
- external_traffic_policy = "Cluster"
+ external_traffic_policy = "Local"
selector = {
app = "mailserver"
}
@@ -549,7 +548,7 @@ resource "kubernetes_cron_job_v1" "email_roundtrip_monitor" {
concurrency_policy = "Replace"
failed_jobs_history_limit = 3
successful_jobs_history_limit = 3
- schedule = "*/10 * * * *"
+ schedule = "*/20 * * * *"
job_template {
metadata {}
spec {
diff --git a/stacks/mailserver/modules/mailserver/variables.tf b/stacks/mailserver/modules/mailserver/variables.tf
index acca4d3a..d63b278c 100644
--- a/stacks/mailserver/modules/mailserver/variables.tf
+++ b/stacks/mailserver/modules/mailserver/variables.tf
@@ -3,7 +3,7 @@
variable "postfix_cf" {
default = < kubelet_volume_stats_capacity_bytes
+ expr: predict_linear(kubelet_volume_stats_used_bytes[6h], 3600*24) > kubelet_volume_stats_capacity_bytes and kubelet_volume_stats_capacity_bytes < 1099511627776
for: 1h
labels:
severity: warning
@@ -1725,21 +1725,21 @@ serverFiles:
summary: "Bank sync has not succeeded in more than 48h. Check CronJob and account auth."
- alert: EmailRoundtripFailing
expr: email_roundtrip_success{job="email-roundtrip-monitor"} == 0
- for: 30m
+ for: 60m
labels:
severity: warning
annotations:
- summary: "Email round-trip probe failing. Check ForwardEmail relay, DNS, and IMAP."
+ summary: "Email round-trip probe failing. Check MX DNS, Postfix, Mailgun API, and IMAP."
- alert: EmailRoundtripStale
- expr: (time() - email_roundtrip_last_success_timestamp{job="email-roundtrip-monitor"}) > 2400
+ expr: (time() - email_roundtrip_last_success_timestamp{job="email-roundtrip-monitor"}) > 3600
for: 10m
labels:
severity: warning
annotations:
- summary: "Email round-trip probe has not succeeded in >40 min"
+ summary: "Email round-trip probe has not succeeded in >60 min"
- alert: EmailRoundtripNeverRun
expr: absent(email_roundtrip_success{job="email-roundtrip-monitor"})
- for: 40m
+ for: 60m
labels:
severity: warning
annotations: