Clan-var secrets are newline-free at source and carry an explicit mode #418

Closed
opened 2026-08-10 21:14:46 +00:00 by ben · 1 comment
Owner

Two hygiene gaps in the rendered generators, both invisible to nix eval (see docs/GOTCHAS.md #4):

  1. Trailing newline. Every secret generator writes openssl rand -base64 -out "$out"/<file> 24 (internal/clan/vmguest.go, files.go), which emits a trailing newline. OurCloud has both consumer styles: gatewayEnvExports reads $(cat …) (newline stripped) while adminpassFile/dbpassFile/provision.adminPasswordFile are read verbatim by NixOS modules. No single secret feeds both styles today; the first one that does reproduces the mauke fleet's fleet-wide SigV4 403 SignatureDoesNotMatch (65-byte vs 64-byte secret). Fix at generation: pipe through tr -d '\n'.
  2. Mode. Owner/group are set on every var file; mode is never set anywhere in the tree. Clan vars default 0400 — fine while consumers are root; the first non-root consumer gets permission-denied at runtime with a green deploy behind it.

Acceptance criteria

  • All secret generators emit newline-free files (blanket rule, not per-consumer).
  • Var files consumed by a non-root service set explicit owner/group/mode.
  • Rotation impact assessed and stated in the PR: editing a generator's script makes clan vars generate re-run it, rotating its files (GOTCHAS #5) — say what happens to standing communities (the dev community on benz-HP included) and sequence accordingly.
  • Render tests assert the tr -d '\n' (or equivalent) is present per secret file.

Source: the clan-community (mauke reference fleet) lessons review, docs/research/2026-08-10-clan-community-lessons.md (lands on main this sitting), lesson 7.

Two hygiene gaps in the rendered generators, both invisible to `nix eval` (see `docs/GOTCHAS.md` #4): 1. **Trailing newline.** Every secret generator writes `openssl rand -base64 -out "$out"/<file> 24` (`internal/clan/vmguest.go`, `files.go`), which emits a trailing newline. OurCloud has both consumer styles: `gatewayEnvExports` reads `$(cat …)` (newline stripped) while `adminpassFile`/`dbpassFile`/`provision.adminPasswordFile` are read verbatim by NixOS modules. No single secret feeds both styles *today*; the first one that does reproduces the mauke fleet's fleet-wide SigV4 `403 SignatureDoesNotMatch` (65-byte vs 64-byte secret). Fix at generation: pipe through `tr -d '\n'`. 2. **Mode.** Owner/group are set on every var file; `mode` is never set anywhere in the tree. Clan vars default `0400` — fine while consumers are root; the first non-root consumer gets permission-denied at runtime with a green deploy behind it. **Acceptance criteria** - All secret generators emit newline-free files (blanket rule, not per-consumer). - Var files consumed by a non-root service set explicit owner/group/**mode**. - **Rotation impact assessed and stated in the PR**: editing a generator's script makes `clan vars generate` re-run it, rotating its files (GOTCHAS #5) — say what happens to standing communities (the dev community on benz-HP included) and sequence accordingly. - Render tests assert the `tr -d '\n'` (or equivalent) is present per secret file. _Source: the clan-community (mauke reference fleet) lessons review, `docs/research/2026-08-10-clan-community-lessons.md` (lands on main this sitting), lesson 7._
Author
Owner

Landed on main as 9209ded.

Newline (blanket rule): the random-secret generators now strip openssl's trailing newline at source — openssl rand -base64 24 | tr -d '\n' > "$out"/… — for kanidm-admins (admin, idm_admin; internal/clan/vmguest.go), nextcloud-admin (adminpass) and nextcloud-db (dbpass; internal/clan/files.go). PEM generators (kanidm-tls, front-door-tls) keep their structural trailing newline; only random secrets are stripped.

Mode: every var file with a non-root consumer carries explicit mode = "0400" (the value clan already defaults to, made a contract): kanidm-tls cert/key/ca (kanidm), kanidm-admins admin/idm_admin (kanidm), nextcloud-admin adminpass + nextcloud-db dbpass (nextcloud), front-door-tls cert/key (caddy). The front-door ca stays public (secret = false).

Render tests assert the tr -d per random secret and the mode per file: TestRenderFiles_SecretGeneratorsRendered (files_test.go), TestRenderGatewayGuest_KanidmSecretsNewlineFreeAndModed (vmguest_test.go), and the caddy owner/mode check in frontdoor_private_test.go. Full internal/clan suite + the pre-push go-ci gate are green.

Rotation impact (GOTCHAS #5): the | tr -d edit changes those three generators' scripts, so clan vars generate rotates admin/idm_admin/adminpass/dbpass on next run. The standing dev community on benz-HP re-provisions those credentials on its next deploy (the kanidm provisioning / nextcloud-setup oneshots re-apply the rotated values). The mode-only files (kanidm-tls, front-door-tls) do NOT rotate — mode is activation metadata, not part of the generator script, so the pinned file sets are unchanged.

Landed on main as `9209ded`. **Newline (blanket rule):** the random-secret generators now strip openssl's trailing newline at source — `openssl rand -base64 24 | tr -d '\n' > "$out"/…` — for kanidm-admins (admin, idm_admin; `internal/clan/vmguest.go`), nextcloud-admin (adminpass) and nextcloud-db (dbpass; `internal/clan/files.go`). PEM generators (kanidm-tls, front-door-tls) keep their structural trailing newline; only random secrets are stripped. **Mode:** every var file with a non-root consumer carries explicit `mode = "0400"` (the value clan already defaults to, made a contract): kanidm-tls cert/key/ca (kanidm), kanidm-admins admin/idm_admin (kanidm), nextcloud-admin adminpass + nextcloud-db dbpass (nextcloud), front-door-tls cert/key (caddy). The front-door `ca` stays public (`secret = false`). **Render tests** assert the `tr -d` per random secret and the mode per file: `TestRenderFiles_SecretGeneratorsRendered` (files_test.go), `TestRenderGatewayGuest_KanidmSecretsNewlineFreeAndModed` (vmguest_test.go), and the caddy owner/mode check in frontdoor_private_test.go. Full `internal/clan` suite + the pre-push go-ci gate are green. **Rotation impact (GOTCHAS #5):** the `| tr -d` edit changes those three generators' scripts, so `clan vars generate` rotates admin/idm_admin/adminpass/dbpass on next run. The standing dev community on benz-HP re-provisions those credentials on its next deploy (the kanidm provisioning / nextcloud-setup oneshots re-apply the rotated values). The mode-only files (kanidm-tls, front-door-tls) do NOT rotate — mode is activation metadata, not part of the generator script, so the pinned file sets are unchanged.
ben closed this issue 2026-08-10 22:59:59 +00:00
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#418
No description provided.