debug(homelab): record diun load-shaping, workload exemption and authenticated smtps rca
Brain Structural Validation / Validate Markdown Structure & Links (push) Successful in 8s

Six post-deployment issues resolved on the Core Diun notifier:
- Portainer bcrypt dollar-sign interpolation eliminated via full deprecation
- High-concurrency registry scan mitigated via WORKERS=6 + JITTER=30s
- Local-build image exemptions decentralized to Sites/* via diun.enable=false
- Startup socket-proxy race accepted as benign transient noise
- Unauthenticated port-25 spam flagging resolved by migrating to port 465 SMTPS
- Dedicated notifier@roadtotech.me service account provisioned via SOPS

Result: 19 upstream images monitored cleanly (0 failures), mail delivered
authenticated and landing directly in INBOX with auth=pass.
This commit is contained in:
kiskaadee committed 2026-09-24 20:35:59 -05:00
1 parent 5037c5578c
commit 00f426b24d
3 files changed
+218

No files matched your search

+2
View File
@@ -116,6 +116,7 @@ Archived and foundational documentation for completed milestones:
* [**Core Service Qualification & Portainer Deprecation**](discussions/core-service-qualification-and-portainer-deprecation.md) — Evaluated platform service qualification criteria; resolved via complete deprecation of Portainer and retaining Gitea and CI runner decoupled.
### Completed Plans
* 🟢 [**Diun Load-Shaping, Workload Exemption & Authenticated SMTPS Delivery (2026-09-24)**](../../records/debug/2026-09-24-diun-workload-isolation-and-load-shaping.md) — Resolved 6 post-deployment issues: Portainer bcrypt `$` interpolation, high-concurrency DNS load mitigated via `WORKERS=6` + `JITTER=30s`, local-build exemptions decentralized to `Sites/*`, and Diun migrated to port 465 SMTPS with dedicated service account. 19 images clean, mail delivered authenticated.
* 🟢 [**Clean Deprecation of Portainer from Core**](plans/portainer-deprecation-plan.md)
* 🟢 [**Stalwart Mail Server & SnappyMail Webmail Deployment**](plans/stalwart-email-server-implementation-plan.md)
* 🟢 [**Multirepo Refactor of Homepage & Learning Hub**](plans/multirepo-refactor-homepage-courses.md)
@@ -129,3 +130,4 @@ Archived and foundational documentation for completed milestones:
* 🟢 [**NixOS Server & Laptop Migration**](archive/nixos-server-laptop-migration.md)
* 🟢 [**Domain Migration (`roadtotech.me`)**](archive/domain-migration-roadtotech.md)
* 🟢 [**Production Folder Structure Reorganization**](plans/server-24-7/folder-structure-reorganization.md)
@@ -0,0 +1,192 @@
---
type: debug
project: homelab
date: 2026-09-24
tags:
- operations
- homelab
- troubleshooting
- diun
- docker
- stalwart
- smtp
- sops
---
# Incident RCA & Architectural Tuning: Diun Load-Shaping, Workload Exemption & Authenticated SMTPS Delivery
## System Context & Fundamentals
The `roadtotech.me` homelab operates an autonomous container image update notifier ([Diun](https://crazymax.dev/diun/)) in the Core Compose stack. Diun queries Docker state via `socket-proxy` (`tcp://socket-proxy:2375`) and dispatches notification emails through the local Stalwart mail server (`stalwart`).
Platform boundaries follow a clear operational contract:
* **Core Platform**: Manages shared infrastructure, platform listeners, secrets, and global scanner defaults (`DIUN_PROVIDERS_DOCKER_WATCHBYDEFAULT=true`).
* **Sites Workloads**: Independent application stacks (`Sites/*`) that declare workload-specific traits and exemptions.
---
## Problem & Initial Observations
Following the initial Diun setup and routine operational monitoring, several distinct classes of issues and warnings emerged across container and mail logs:
1. **Compose Variable Warning**:
```text
WARN[0000] The "PxkuR3uP0bQtqJnPfehtenptbPl" variable is not set. Defaulting to a blank string.
```
2. **Registry Manifest DNS Timeouts**:
```text
WRN Cannot get remote manifest error="... dial tcp: lookup registry-1.docker.io on 127.0.0.11:53: read udp ...: i/o timeout"
```
3. **Startup Socket Proxy Race**:
```text
ERR Cannot create Docker client error="Cannot connect to the Docker daemon at tcp://socket-proxy:2375. Is the docker daemon running?"
```
4. **Registry Access Denied on Local Builds**:
```text
WRN Cannot get remote manifest error="reading digest latest in docker.io/library/homelab-doc2site-docs: requested access to the resource is denied"
WRN Cannot get remote manifest error="reading digest latest in docker.io/library/homelab-minecraft-web: requested access to the resource is denied"
```
5. **Notification Distrusted & Spam Flagging**:
Alert emails arriving from `diun@roadtotech.me` displayed a maximum red spam score bar in SnappyMail and routed directly to the `Junk` mailbox.
6. **Port 587 Submission Connection Refusal**:
When configuring authenticated submission on standard STARTTLS port 587, Diun reported:
```text
dial failed: dial tcp 172.18.0.16:587: connect: connection refused
```
---
## Diagnostic Inquiries & Root Cause Analysis
### 1. Bcrypt Variable Interpolation in Docker Compose
* **Investigation**: Grepping the variable name across the server environment revealed it originated from `PORTAINER_ADMIN_PASSWORD` in `/run/secrets/rendered/homeserver.env`. Portainer's bcrypt string (`$2y$05$...`) contained three `$` delimiters. The first two were escaped (`$$2y$$05`), but the third was left unescaped before the salt/hash string `PxkuR3uP0bQtqJnPfehtenptbPl`. Docker Compose parsed it as a variable reference and defaulted it to a blank string.
* **Resolution**: Portainer was subsequently deprecated and cleanly pruned from the entire Core platform (containers, SOPS secrets, volumes, and docs), naturally eliminating this warning and corrupt password state.
- See: [Core Service Qualification & Portainer Deprecation](../../projects/homelab/discussions/core-service-qualification-and-portainer-deprecation.md)
### 2. High-Concurrency Registry Scan vs. DNS Blip
* **Investigation**: During a single scan at 13:26:18 UTC, 22 images were evaluated concurrently with `DIUN_WATCH_WORKERS=20`. Subsequent runs succeeded cleanly across the exact same public registries without code changes.
* **Epistemic Distinction**: The 20 concurrent workers were an **exacerbating load factor**, not the proven root cause of the network drop. Rather than diagnosing a persistent DNS failure, the appropriate engineering action was **load-shaping**:
* **Concurrency Limit**: Reduced `DIUN_WATCH_WORKERS` from `20` to `6` to shape the peak request volume against Docker's internal DNS forwarder (`127.0.0.11:53`).
* **Synchronization Limit**: Enabled `DIUN_WATCH_JITTER=30s` to randomize scheduled job dispatches and prevent simultaneous request bursts upon cron ticks.
### 3. Startup Readiness Race
* **Investigation**: `ERR Cannot create Docker client` occurred exclusively during the sub-second window of `docker compose restart`.
* **Mechanism**: Standard Compose `depends_on: [socket-proxy]` gates container startup, not TCP port readiness. Because Diun boots in under 50ms, it probes port 2375 before HAProxy finishes binding its listener.
* **Decision**: Accepted as benign transient startup noise (Option A). Diun handles the initial connection failure gracefully and runs its periodic cron triggers without issue once `socket-proxy` binds.
### 4. Decentralized Workload Image Exemption
* **Investigation**: `homelab-doc2site-docs` and `homelab-minecraft-web` are locally built images (`build: .`) without remote registry mirrors. With `watchByDefault=true`, Diun assumed Docker Hub as the default registry and queried `docker.io/library/*`, which returned 401 Unauthorized.
* **Architectural Fix**: Maintained decentralized workload ownership by adding `diun.enable=false` directly to the application manifests:
* `Sites/doc2site/docker-compose.yml` (`docs` service)
* `Sites/minecraft/docker-compose.yml` (`web` service)
Core continues to watch by default, while workloads explicitly opt out if they do not publish to remote registries.
### 5. Inbound Mail Trust & Stalwart Listener Topography
* **Investigation**:
* Diun's mail notifier does not support arbitrary custom headers.
* When sending unauthenticated mail over port 25 claiming to be `@roadtotech.me`, Stalwart treated it as external ingress. Because the internal Docker bridge IP (`172.18.0.x`) does not match the public SPF record for `roadtotech.me` and lacked DKIM or SMTP AUTH, Stalwart's anti-spoofing engine penalized it as a forged sender.
* Probing Stalwart's active listener catalog revealed:
* `listenerId = "smtp"` (Port 25): Active, but explicitly disables authentication (MTA ingress only).
* `listenerId = "submission"` (Port 587): Disabled / inactive in Stalwart.
* `listenerId = "submissions"` (Port 465): Active, listening with implicit TLS (SMTPS), and enforcing `AUTH PLAIN LOGIN XOAUTH2 OAUTHBEARER`.
* **Architectural Fix**:
* Created dedicated service account `notifier@roadtotech.me` in LLDAP.
* Encrypted password in `nixos/secrets.yaml` under `diun/smtp_password` and projected it declaratively into `/run/secrets/rendered/homeserver.env` via `homeserver.nix`.
* Configured Diun to use **Port 465 with implicit TLS (`DIUN_NOTIF_MAIL_SSL=true`)** and aligned sender identity `DIUN_NOTIF_MAIL_FROM=notifier@${DOMAIN:-roadtotech.me}`.
---
## Declarative Remediation Summary
### `Core/docker-compose.yml`
```yaml
- DIUN_WATCH_WORKERS=6
- DIUN_WATCH_JITTER=30s
- DIUN_WATCH_SCHEDULE=0 */6 * * *
- DIUN_NOTIF_MAIL_HOST=stalwart
- DIUN_NOTIF_MAIL_PORT=465
- DIUN_NOTIF_MAIL_USERNAME=notifier@${DOMAIN:-roadtotech.me}
- DIUN_NOTIF_MAIL_PASSWORD=${DIUN_SMTP_PASSWORD}
- DIUN_NOTIF_MAIL_SSL=true
- DIUN_NOTIF_MAIL_INSECURESKIPVERIFY=true
- DIUN_NOTIF_MAIL_FROM=notifier@${DOMAIN:-roadtotech.me}
- DIUN_NOTIF_MAIL_TO=kiskaadee@${DOMAIN:-roadtotech.me}
```
### `Core/nixos/modules/homeserver.nix`
```nix
sops.secrets = lib.genAttrs [
# ...
"diun/smtp_password"
] (name: { owner = "kiskaadee"; });
sops.templates."homeserver.env" = {
owner = "kiskaadee";
content = lib.generators.toKeyValue {} {
# ...
DIUN_SMTP_PASSWORD = config.sops.placeholder."diun/smtp_password";
};
};
```
### `Sites/doc2site/docker-compose.yml` & `Sites/minecraft/docker-compose.yml`
```yaml
labels:
- "diun.enable=false"
- "traefik.enable=true"
```
---
## Post-Deployment Verification
1. **Image Scan & Filtering Output**:
```text
INF Found 19 image(s) to analyze provider=docker
INF Jobs completed added=0 failed=0 skipped=0 unchanged=19 updated=0
INF Cron initialized with schedule 0 */6 * * *
INF Next run in 53 minutes (2026-09-25 00:00:27.868114284 +0000 UTC)
```
* Monitored exactly 19 upstream images (22 minus Portainer [1] and local custom builds [2]).
* Zero failures (`failed=0`).
* Jitter active (`00:00:27` desynchronization).
2. **Mail Authentication & Delivery**:
* Direct probe and Diun test notification succeeded:
```text
Notification sent for mail notifier(s)
```
* Stalwart logs confirmed authenticated submission:
```text
INFO Authentication successful (auth.success)
listenerId = "submissions", remotePort = 465, accountName = "notifier@roadtotech.me"
INFO Delivery completed (delivery.completed)
to = ["kiskaadee@roadtotech.me"], code = 250, details = "OK"
```
* Messages land directly in `INBOX` with clean spam scores and `auth=pass` trust verification.
---
## Architectural Lessons Learned
1. **Load Shaping Over Speculative Repair**: Distinguish correlation from causation. When an external service experiences transient timeouts, avoid over-engineering network plumbing; use concurrency limits and desynchronization jitter to keep system load predictable.
2. **Workload Sovereignty in Declarative GitOps**: Exceptions belong to the domain that creates them. Local build exemptions belong in `Sites/*` compose manifests, keeping the Core platform generic and declarative.
3. **MTA Ingress vs. Client Submission Topography**:
* Port 25 is strictly for unauthenticated MX exchange; internal infrastructure must never send unauthenticated alerts over port 25 claiming internal domain identities, as anti-spoofing filters will correctly penalize them.
* Service accounts must authenticate via dedicated submission endpoints (Port 465 SMTPS / Port 587 STARTTLS) matching the specific active listeners of the mail appliance.
---
## Related
* [Diun Initial Integration & Socket Proxy RCA (2026-09-22)](../debug/2026-09-22-diun-socket-proxy-integration-and-stalwart-alerting.md) — Previous incident establishing the Diun foundation this session built upon.
* [Diun Documentation](https://crazymax.dev/diun/)
* [Stalwart Mail Server Docs](https://stalw.art/docs/)
+24
View File
@@ -58,3 +58,27 @@ Routine templates must represent aspirational intent, not immutable dogma. Freez
### Factual Adherence over Gamified Streaks
Conventional fitness applications encourage dishonesty and cognitive stress by imposing fragile binary streak counters that reset on missed days. Praxis models adherence as factual distribution rates over sliding windows, separating set-level completion intent from binary day attendance.
---
## Phase 0 Complete: Praxis Implementation Readiness
### Toolchain Hardening & Blueprint (v0.2.0)
Session completed a full Phase 0 implementation-readiness pass on the Praxis repository:
- **Blueprint v0.2.0** finalised: translated SRS v1.0.2 + Domain Model v1.0.1 into concrete Python decisions — package structure, dependency direction, immutability strategy (`@dataclass(frozen=True)` value objects, `@dataclass(eq=False)` entities), ID representation (newtype frozen dataclasses over `uuid.UUID`), and `SetData` as explicit frozen VO to prevent `record_set()`/`MetricValidationPolicy` divergence.
- Resolved all Phase-1-blocking ambiguities (OQ-2: `Phase.end_week = None` → return last phase; `ValueError` on empty phases list). Remaining OQs (OQ-1, 3, 4, 5) formally deferred.
- Established `pyproject.toml` toolchain: `ruff` (E/W/F/I/UP/B/C4/SIM/RUF/N/ANN/PT/TCH, line 100, Python 3.13), `pyright` strict mode, `pytest` with `--strict-markers` and 90% branch coverage gate.
- Implemented Git hooks: `pre-commit` (ruff format + check + re-stage), `pre-push` (pyright strict + `pytest -m unit`), and one-shot `install-hooks.sh`.
- Expanded `AGENTS.md` with §5 Toolchain & Static Analysis Constraints, §6 Git Hook Workflow, and tightened §7 Rules of Engagement.
Repository now at **Phase 1 start**: `identifiers → enums → measurement → RepRange → SetData → Exercise → Routine → MetricValidationPolicy → SessionSnapshotFactory → WorkoutSession → CompletionPolicy → WorkloadCalculator → AdherenceCalculator`.
📋 [Praxis Implementation Blueprint (v0.2.0)](../../projects/praxis/plans/praxis-implementation-blueprint.md)
---
## Incidents & Debugging
- [Diun Load-Shaping, Workload Exemption & Authenticated SMTPS Delivery (2026-09-24)](../../records/debug/2026-09-24-diun-workload-isolation-and-load-shaping.md): Resolved 6 classes of post-deployment issues on the Core Diun notifier. Root causes: bcrypt `$` interpolation from deprecated Portainer secrets (resolved by full Portainer deprecation), high-concurrency registry scan load factor mitigated via `DIUN_WATCH_WORKERS=6` + `DIUN_WATCH_JITTER=30s`, local-build image exemptions decentralized to `Sites/*` compose manifests via `diun.enable=false`, and authenticated SMTPS delivery migrated from unauthenticated port 25 to port 465 with dedicated `notifier@roadtotech.me` service account projected via SOPS. All 19 upstream images now scan cleanly with zero failures; mail lands in `INBOX` with `auth=pass`.