operator-newsletters / member-newsletters: Listmonk's masked client_secret is echoed back by the SMTP + brand reconcilers, so the token exchange 401s and the door shows its own login form #1611

Closed
opened 2026-09-18 22:21:05 +00:00 by matou-build-agent · 1 comment

The failure

Drive 20260918T211405Z (roles proof #1547, on ae2a2ecd): 43 legs green, two red — operator-newsletters and member-newsletters, both the same fault (artifacts/legs.json, artifacts/verdict.json firstRedLeg: operator-newsletters). Each door reached https://newsletters.roles-proof.idss.nz/auth/oidc?code=… and rendered Listmonk's own login form:

error exchanging token: oauth2: cannot fetch token: 401 Unauthorized

What the box said

The box was kept (artifacts/live-box.json, kept_on_red: true). Nothing had failed:

  • systemctl --failed → 0 loaded units listed.
  • journalctl -u newsletters-oidc.service -b → Login Success for idm_admin@id.roles-proof.idss.nz, Success for every kanidm call, {"data":true} for its settings PUT, then Finished ….

The database named it in one query:

# select key, value from settings where key='security.oidc'
security.oidc|{"enabled": true, "client_id": "newsletters", "provider_url": "https://id.roles-proof.idss.nz/oauth2/openid/newsletters", "client_secret": "••••••••••••••••••••••••••••••••••••••••••••••••", …}

# select length(value->>'client_secret') from settings where key='security.oidc'
48

# select value->0->'password' from settings where key='smtp'
"••••••••••••••••••••••••••••••••"

48 bullets = the kanidm basic secret's own length; 32 = the minted SMTP credential's. The stored secrets are Listmonk's read mask, not secrets.

Cause

All three newsletters reconcilers are GET /api/settings → jq-merge → PUT /api/settings of the ONE settings object, so each echoes back fields it does not own:

  • internal/clan/newsletters.go:406-424 (newsletters-smtp)
  • internal/clan/newsletters.go:717-725 (newsletters-brand)
  • internal/clan/newsletters.go:591-605 (newsletters-oidc)

Against the pinned upstream (listmonk 6.1.0, /tmp/listmonk-6.1.0):

  • cmd/settings.go:66-81 — handleGetSettings masks every secret it returns as strings.Repeat("•", utf8.RuneCountInString(secret)); line 81 is s.OIDC.ClientSecret.
  • cmd/settings.go:232-233 — handleUpdateSettings restores the stored value only when the field arrives empty: if set.OIDC.ClientSecret == "" { set.OIDC.ClientSecret = cur.OIDC.ClientSecret }; lines 142-148 are the UUID-matched twin for smtp[].password.

Bullets are not empty, so the mask is stored verbatim. The journal gives the order: newsletters-oidc finished (real secret written, listmonk restarted) at 22:06:07; newsletters-smtp finished 22:06:09; newsletters-brand 22:06:10, and again 22:06:58 on the redeploy. Each of the last two read the secret back masked and PUT the mask over it.

That is why the fault surfaces one door away from its cause: kanidm still authenticates (branded-login, oidc-admin and the other twelve door legs are green) and the code arrives; only the token exchange — the one step that presents the client secret — refuses. It is also invisible to the OIDC reconciler's compare-before-write (newsletters.go:599-602), which correctly excludes the masked secret from the projection (GOTCHAS #242 rule (a)) and therefore can never notice the clobber.

The fix

internal/clan/newsletters.go: one shared rewrite, newslettersBlankMaskedSecrets, runs over the settings object each reconciler has just read, before its own merge — blanking all ten fields handleGetSettings masks, so Listmonk keeps what it already holds. Wired into the shared readiness gate (newslettersSettingsReadyGate, covering newsletters-smtp + newsletters-brand) and into newsletters-oidc's own read. A reconciler that OWNS a secret still sets it again in its own merge below — verified for the SMTP relay password in the round-trip below.

GOTCHAS #256 records the hazard as the counterpart to #248 ("echo the whole record back" — but never a field the server masked).

Suspected layer

Product, internal/clan render seam. Additions only: 3 files, 86 non-test lines, 0 deletions; no assertion, test or leg touched.

Proposed ruling (Ruled by the healer under ADR 0174 — veto anytime)

Two-way door, mechanical repair, not a design decision.

Why it is not a design decision. The three reconcilers already MEAN to set only their own keys and leave the rest of the settings object alone — that intent is written into their own comments (newsletters.go:402-404, 713-716) and into the OIDC reconciler's projection comment at 594-598, which already knew Listmonk masks client_secret. The change makes the code do what it already meant: it stops a field the server itself redacted from being written back as data. Nothing a community sees changes, no route, message, default, secrets shape or security posture changes — the deploy stops destroying a secret it was never writing on purpose. This is the "wrong ordering / wrong constant" class, not the front-door / co-host-route / secrets class.

Revertible how. git revert 30db5680 restores the previous bytes exactly. The change is additive (127 insertions, 0 deletions): one new function plus two one-line call sites. No schema, no dependency, no state outside the checkout, no infra touched — the box was only ever read.

Proven by which test. TestRenderNewsletters_ReconcilersNeverEchoAMaskedSecretBack (internal/clan/newsletters_test.go:409), written and watched fail first (got 0 of 3). It pins that all three settings-PUT reconcilers blank before they merge, that the blanking covers every field handleGetSettings masks, and that the SMTP reconciler still writes its own relay password afterwards. Beyond the render test, the emitted shell was round-tripped verbatim through real bash + jq against a settings document carrying the box's actual masked values: the secrets come out "" (the restore path), the smtp UUID that Listmonk's password restore matches on is preserved, and the SMTP reconciler's resulting PUT body carries its own real password with client_secret: "". Rules 1 and 2 are untouched: additions only, nothing weakened, 3 files / 86 non-test lines. Built on the workstation (never the drive host) and closed through the close-report gate — the same gate a swarm worker passes.

drive 20260918T211405Z red at operator-newsletters (sig be8cfadc5b90) — self-fixed on the fast lane, commit 679af8442051065e36513e7a76c94fedc3f0bbff; checks: Red-first: GOWORK=off go test ./internal/clan/ -run TestRenderNewsletters_ReconcilersNeverEchoAMaskedSecretBack -count=1 BEFORE the fix — FAIL, every settings-PUT reconciler must blank the masked client_secret before echoing the object back … got 0 of 3. Targeted (after the fix): same command — ok. Package tests: GOWORK=off go test ./internal/clan/ -count=1 — ok (24.5s). Dependent packages: GOWORK=off go test ./internal/brandkit/ ./internal/newslettersvc/ ./control-plane/... -count=1 — all ok. GOWORK=off go vet ./internal/clan/ — exit 0. gofmt -l internal/clan/ — clean. GOWORK=off go build ./... — exit 0. Quoting/behaviour round-trip: extracted the rendered blanking block VERBATIM from the generated newsletters.nix and ran it under bash with real jq against a settings document carrying the box's own masked values (48-bullet client_secret, 32-bullet smtp password) — it emitted oidc_secret: "", smtp_pw: "", bounce_pw: "" while preserving smtp_uuid: u-1 (the key Listmonk's password restore matches on), smtp_host, oidc_enabled: true, oidc_cid: newsletters and app.site_name; feeding that through the SMTP reconciler's own merge produced a PUT body with the real relay password restored and security.oidc.client_secret: "". Diff: 3 files, 127 insertions / 0 deletions (86 non-test lines); no assertion, test or leg touched. The live legs need a rented droplet and re-prove on the next drive.. evidence: /home/dev/swarm/Matou/idss/test-results/drive-rented-services/20260918T211405Z on matou-workstation.

## The failure Drive `20260918T211405Z` (roles proof #1547, on `ae2a2ecd`): 43 legs green, **two** red — `operator-newsletters` and `member-newsletters`, both the same fault (`artifacts/legs.json`, `artifacts/verdict.json` `firstRedLeg: operator-newsletters`). Each door reached `https://newsletters.roles-proof.idss.nz/auth/oidc?code=…` and rendered Listmonk's own login form: > `error exchanging token: oauth2: cannot fetch token: 401 Unauthorized` ## What the box said The box was kept (`artifacts/live-box.json`, `kept_on_red: true`). Nothing had failed: - `systemctl --failed` → `0 loaded units listed.` - `journalctl -u newsletters-oidc.service -b` → `Login Success for idm_admin@id.roles-proof.idss.nz`, `Success` for every kanidm call, `{"data":true}` for its settings PUT, then `Finished …`. The database named it in one query: ``` # select key, value from settings where key='security.oidc' security.oidc|{"enabled": true, "client_id": "newsletters", "provider_url": "https://id.roles-proof.idss.nz/oauth2/openid/newsletters", "client_secret": "••••••••••••••••••••••••••••••••••••••••••••••••", …} # select length(value->>'client_secret') from settings where key='security.oidc' 48 # select value->0->'password' from settings where key='smtp' "••••••••••••••••••••••••••••••••" ``` 48 bullets = the kanidm basic secret's own length; 32 = the minted SMTP credential's. The stored secrets are Listmonk's **read mask**, not secrets. ## Cause All three newsletters reconcilers are `GET /api/settings` → jq-merge → `PUT /api/settings` of the ONE settings object, so each echoes back fields it does not own: - `internal/clan/newsletters.go:406-424` (`newsletters-smtp`) - `internal/clan/newsletters.go:717-725` (`newsletters-brand`) - `internal/clan/newsletters.go:591-605` (`newsletters-oidc`) Against the pinned upstream (listmonk 6.1.0, `/tmp/listmonk-6.1.0`): - `cmd/settings.go:66-81` — `handleGetSettings` masks **every** secret it returns as `strings.Repeat("•", utf8.RuneCountInString(secret))`; line 81 is `s.OIDC.ClientSecret`. - `cmd/settings.go:232-233` — `handleUpdateSettings` restores the stored value **only when the field arrives empty**: `if set.OIDC.ClientSecret == "" { set.OIDC.ClientSecret = cur.OIDC.ClientSecret }`; lines 142-148 are the UUID-matched twin for `smtp[].password`. Bullets are not empty, so the mask is stored verbatim. The journal gives the order: `newsletters-oidc` finished (real secret written, listmonk restarted) at `22:06:07`; `newsletters-smtp` finished `22:06:09`; `newsletters-brand` `22:06:10`, and again `22:06:58` on the redeploy. Each of the last two read the secret back masked and PUT the mask over it. That is why the fault surfaces one door away from its cause: kanidm still authenticates (`branded-login`, `oidc-admin` and the other twelve door legs are green) and the code arrives; only the **token exchange** — the one step that presents the client secret — refuses. It is also invisible to the OIDC reconciler's compare-before-write (`newsletters.go:599-602`), which correctly excludes the masked secret from the projection (GOTCHAS #242 rule (a)) and therefore can never notice the clobber. ## The fix `internal/clan/newsletters.go`: one shared rewrite, `newslettersBlankMaskedSecrets`, runs over the settings object each reconciler has just read, before its own merge — blanking all ten fields `handleGetSettings` masks, so Listmonk keeps what it already holds. Wired into the shared readiness gate (`newslettersSettingsReadyGate`, covering `newsletters-smtp` + `newsletters-brand`) and into `newsletters-oidc`'s own read. A reconciler that OWNS a secret still sets it again in its own merge below — verified for the SMTP relay password in the round-trip below. GOTCHAS #256 records the hazard as the counterpart to #248 ("echo the whole record back" — but never a field the server masked). ## Suspected layer Product, `internal/clan` render seam. Additions only: 3 files, 86 non-test lines, 0 deletions; no assertion, test or leg touched. ## Proposed ruling (Ruled by the healer under ADR 0174 — veto anytime) Two-way door, mechanical repair, not a design decision. **Why it is not a design decision.** The three reconcilers already MEAN to set only their own keys and leave the rest of the settings object alone — that intent is written into their own comments (`newsletters.go:402-404`, `713-716`) and into the OIDC reconciler's projection comment at `594-598`, which already knew Listmonk masks `client_secret`. The change makes the code do what it already meant: it stops a field the server itself redacted from being written back as data. Nothing a community sees changes, no route, message, default, secrets shape or security posture changes — the deploy stops destroying a secret it was never writing on purpose. This is the "wrong ordering / wrong constant" class, not the front-door / co-host-route / secrets class. **Revertible how.** `git revert 30db5680` restores the previous bytes exactly. The change is additive (127 insertions, 0 deletions): one new function plus two one-line call sites. No schema, no dependency, no state outside the checkout, no infra touched — the box was only ever read. **Proven by which test.** `TestRenderNewsletters_ReconcilersNeverEchoAMaskedSecretBack` (`internal/clan/newsletters_test.go:409`), written and watched fail first (`got 0 of 3`). It pins that all three settings-PUT reconcilers blank before they merge, that the blanking covers every field `handleGetSettings` masks, and that the SMTP reconciler still writes its own relay password afterwards. Beyond the render test, the emitted shell was round-tripped verbatim through real bash + jq against a settings document carrying the box's actual masked values: the secrets come out `""` (the restore path), the smtp UUID that Listmonk's password restore matches on is preserved, and the SMTP reconciler's resulting PUT body carries its own real password with `client_secret: ""`. Rules 1 and 2 are untouched: additions only, nothing weakened, 3 files / 86 non-test lines. Built on the workstation (never the drive host) and closed through the close-report gate — the same gate a swarm worker passes. drive `20260918T211405Z` red at `operator-newsletters` (sig be8cfadc5b90) — self-fixed on the fast lane, commit `679af8442051065e36513e7a76c94fedc3f0bbff`; checks: Red-first: `GOWORK=off go test ./internal/clan/ -run TestRenderNewsletters_ReconcilersNeverEchoAMaskedSecretBack -count=1` BEFORE the fix — FAIL, `every settings-PUT reconciler must blank the masked client_secret before echoing the object back … got 0 of 3`. Targeted (after the fix): same command — ok. Package tests: `GOWORK=off go test ./internal/clan/ -count=1` — ok (24.5s). Dependent packages: `GOWORK=off go test ./internal/brandkit/ ./internal/newslettersvc/ ./control-plane/... -count=1` — all ok. `GOWORK=off go vet ./internal/clan/` — exit 0. `gofmt -l internal/clan/` — clean. `GOWORK=off go build ./...` — exit 0. Quoting/behaviour round-trip: extracted the rendered blanking block VERBATIM from the generated newsletters.nix and ran it under bash with real jq against a settings document carrying the box's own masked values (48-bullet client_secret, 32-bullet smtp password) — it emitted `oidc_secret: ""`, `smtp_pw: ""`, `bounce_pw: ""` while preserving `smtp_uuid: u-1` (the key Listmonk's password restore matches on), `smtp_host`, `oidc_enabled: true`, `oidc_cid: newsletters` and `app.site_name`; feeding that through the SMTP reconciler's own merge produced a PUT body with the real relay password restored and `security.oidc.client_secret: ""`. Diff: 3 files, 127 insertions / 0 deletions (86 non-test lines); no assertion, test or leg touched. The live legs need a rented droplet and re-prove on the next drive.. evidence: `/home/dev/swarm/Matou/idss/test-results/drive-rented-services/20260918T211405Z` on matou-workstation. <!-- rehearsal-sig: be8cfadc5b90 -->
Author
Member

close-report for #1611 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 1611,
  "status": "success",
  "commits": [
    "679af8442051065e36513e7a76c94fedc3f0bbff"
  ],
  "changed_files": [
    "docs/GOTCHAS.md",
    "internal/clan/newsletters.go",
    "internal/clan/newsletters_test.go"
  ],
  "tests": [
    {
      "command": "Red-first: `GOWORK=off go test ./internal/clan/ -run TestRenderNewsletters_ReconcilersNeverEchoAMaskedSecretBack -count=1` BEFORE the fix — FAIL, `every settings-PUT reconciler must blank the masked client_secret before echoing the object back … got 0 of 3`. Targeted (after the fix): same command — ok. Package tests: `GOWORK=off go test ./internal/clan/ -count=1` — ok (24.5s). Dependent packages: `GOWORK=off go test ./internal/brandkit/ ./internal/newslettersvc/ ./control-plane/... -count=1` — all ok. `GOWORK=off go vet ./internal/clan/` — exit 0. `gofmt -l internal/clan/` — clean. `GOWORK=off go build ./...` — exit 0. Quoting/behaviour round-trip: extracted the rendered blanking block VERBATIM from the generated newsletters.nix and ran it under bash with real jq against a settings document carrying the box's own masked values (48-bullet client_secret, 32-bullet smtp password) — it emitted `oidc_secret: \"\"`, `smtp_pw: \"\"`, `bounce_pw: \"\"` while preserving `smtp_uuid: u-1` (the key Listmonk's password restore matches on), `smtp_host`, `oidc_enabled: true`, `oidc_cid: newsletters` and `app.site_name`; feeding that through the SMTP reconciler's own merge produced a PUT body with the real relay password restored and `security.oidc.client_secret: \"\"`. Diff: 3 files, 127 insertions / 0 deletions (86 non-test lines); no assertion, test or leg touched. The live legs need a rented droplet and re-prove on the next drive.",
      "exit_code": 0
    }
  ],
  "criteria": {
    "the red leg is now green": "healed on the fast lane, commit 679af8442051065e36513e7a76c94fedc3f0bbff"
  },
  "summary": "Listmonk masks every secret on GET /api/settings and restores the stored one only on an empty field, so the newsletters-smtp and newsletters-brand GET-merge-PUT reconcilers wrote the bullets over the real security.oidc.client_secret and the door 401'd at the token exchange; added one shared blanking rewrite that all three reconcilers run over the object they just read.",
  "blockers": []
}
**close-report** for #1611 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1611, "status": "success", "commits": [ "679af8442051065e36513e7a76c94fedc3f0bbff" ], "changed_files": [ "docs/GOTCHAS.md", "internal/clan/newsletters.go", "internal/clan/newsletters_test.go" ], "tests": [ { "command": "Red-first: `GOWORK=off go test ./internal/clan/ -run TestRenderNewsletters_ReconcilersNeverEchoAMaskedSecretBack -count=1` BEFORE the fix — FAIL, `every settings-PUT reconciler must blank the masked client_secret before echoing the object back … got 0 of 3`. Targeted (after the fix): same command — ok. Package tests: `GOWORK=off go test ./internal/clan/ -count=1` — ok (24.5s). Dependent packages: `GOWORK=off go test ./internal/brandkit/ ./internal/newslettersvc/ ./control-plane/... -count=1` — all ok. `GOWORK=off go vet ./internal/clan/` — exit 0. `gofmt -l internal/clan/` — clean. `GOWORK=off go build ./...` — exit 0. Quoting/behaviour round-trip: extracted the rendered blanking block VERBATIM from the generated newsletters.nix and ran it under bash with real jq against a settings document carrying the box's own masked values (48-bullet client_secret, 32-bullet smtp password) — it emitted `oidc_secret: \"\"`, `smtp_pw: \"\"`, `bounce_pw: \"\"` while preserving `smtp_uuid: u-1` (the key Listmonk's password restore matches on), `smtp_host`, `oidc_enabled: true`, `oidc_cid: newsletters` and `app.site_name`; feeding that through the SMTP reconciler's own merge produced a PUT body with the real relay password restored and `security.oidc.client_secret: \"\"`. Diff: 3 files, 127 insertions / 0 deletions (86 non-test lines); no assertion, test or leg touched. The live legs need a rented droplet and re-prove on the next drive.", "exit_code": 0 } ], "criteria": { "the red leg is now green": "healed on the fast lane, commit 679af8442051065e36513e7a76c94fedc3f0bbff" }, "summary": "Listmonk masks every secret on GET /api/settings and restores the stored one only on an empty field, so the newsletters-smtp and newsletters-brand GET-merge-PUT reconcilers wrote the bullets over the real security.oidc.client_secret and the door 401'd at the token exchange; added one shared blanking rewrite that all three reconcilers run over the object they just read.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#1611
No description provided.