Skip to content

feat(packaging): make maild's secrets key at first start (ADR-0047) - #129

Merged
bketelsen merged 3 commits into
mainfrom
feat/secrets-key-unit
Oct 28, 2026
Merged

bketelsen merged 3 commits into
mainfrom
feat/secrets-key-unit

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Core plan 0010, Phase 3 brief, point (b) (core#172), and Brian's answer B1 (T313b): frostmail's .deb makes the secrets key on the host at first start. Snosi's sysext maild waits for this change in v0.1.1.

What changes

  • ADR-0047 (new) amends ADR-0044. Before, the install made the key once, by hand. Now frostmail-secrets-key.service makes it at first start. ADR-0044's status line says it is amended in part. ADR-0047's status is Accepted with Brian's decision of 2026-10-27; say so if you want it Proposed instead.
  • packaging/lodge/frostmail-secrets-key.service (new) is a oneshot:
    • ConditionPathExists=!/etc/credstore.encrypted/frostmail-secrets-key;
    • Type=oneshot, RemainAfterExit=yes, After=tpm2.target;
    • light hardening that keeps /etc writable and the TPM visible (ProtectSystem=yes, no PrivateDevices=);
    • no [Install] section: nothing upholds or enables it, so its condition is a clean skip.
  • /usr/libexec/frostmail/make-secrets-key (new, from packaging/lodge/make-secrets-key.sh) seals 32 random bytes with systemd-creds encrypt --with-key=auto --name=frostmail-secrets-key, as seal-mail-secrets.sh --apply does:
    • it seals in a private temporary directory beside the key, and publishes the key with ln, so it never replaces a key and a partial file never passes for one;
    • it prints only paths and outcomes.
  • frostmail.service gets Requires=frostmail-secrets-key.service and After=frostmail-secrets-key.service.
  • stage.sh stages the unit (0644) and the helper (0755). The .deb gets them from the staged tree.

The packaging tests

  • packaging/deb-check.py --line PATH LINE fails unless a regular file in the .deb has that exact line. make deb-check (run by make deb, in CI's "Snapshot .deb" job and in the release) checks these things in the real .deb:
    • the unit and the helper (mode 0755);
    • the condition and Type=oneshot;
    • Requires= and After= in frostmail.service.
  • internal/lodge/package_test.go checks the same rules on the staged tree:
    • only the upheld units (frostmail.socket, frostmail.service) must have no Condition*=, and the key unit has exactly its one condition;
    • the key unit has no [Install], WantedBy=, RequiredBy= or UpheldBy=;
    • Requires= and After= are parsed as lists;
    • systemd-analyze verify runs on all 3 units.
  • internal/lodge/debcheck_test.go has new bad packages that must fail: a missing line, a line on a missing file, and a partial line.
  • internal/lodge/secretskey_test.go runs the helper with a stub systemd-creds (the stub never sees or writes key bytes):
    • it makes the directory 0700 and the key 0600, the stub reads 32 bytes, and no temporary file stays;
    • it keeps an existing key, and does not call the stub;
    • when the stub fails, no key and no temporary file stay.

Docs

specs/lodge-app.md, design/accounts.md, plan 0011, AGENTS.md, the docs index, and the hint in move-mail-to-lodge.sh.

Checks

  • make check passes under umask 022. Under umask 077, TestFileRefusesReadableFile fails on a clean main too.
  • go test ./internal/lodge/ ./scripts/ -count=1 passes.
  • shellcheck 0.11.0 and sh -n pass on make-secrets-key.sh and stage.sh.
  • CI builds the snapshot .deb and runs deb-check. No pnpm, node or cargo ran on the host.

Next steps (Brian)

  • Merge.
  • Then tag v0.1.1 with make bump. The release attests frostyard-maild_0.1.1_amd64.deb.
  • Snosi pins it, and lists /usr/lib/systemd/system/frostmail-secrets-key.service and /usr/libexec/frostmail/make-secrets-key in its required-paths.txt.

The .deb ships frostmail-secrets-key.service, a oneshot with
ConditionPathExists=!/etc/credstore.encrypted/frostmail-secrets-key. It runs
/usr/libexec/frostmail/make-secrets-key as root, which seals 32 random bytes
with systemd-creds --with-key=auto, in a private directory beside the key,
and publishes it with ln, so it never replaces a key. frostmail.service has
Requires= and After= on it. The oneshot has no [Install] section: it is
pulled, never upheld, so its condition is a clean skip.

ADR-0047 amends ADR-0044 (core plan 0010, Phase 3 brief, point (b)).
deb-check gains --line PATH LINE; make deb-check checks the unit, the helper,
the condition and the ordering in the .deb. The staged-layout test checks
the same, and systemd-analyze verify runs on the 3 units. A test runs the
helper with a stub systemd-creds.
…a signal (cross-review)

The pipe's status is systemd-creds', so a failed head could let it seal
fewer than 32 bytes, and the condition would then skip every later run. A
failed head now leaves a marker, and the helper exits 1 before it publishes.
dash runs no EXIT trap when a signal ends it, so HUP, INT and TERM now exit
1 and the EXIT trap removes the private directory. Tests: a missing random
source, and SIGTERM to the process group during the encrypt.
…eview)

A reader that closed the FIFO at once could end the stub with SIGPIPE before
the test's SIGTERM. The test now reads and checks the line, then signals.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Oct 28, 2026
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Cross-review (openai/gpt-6.1-sol; coder anthropic claude-sonnet-5.5 with small edits by claude-opus-5.5): Ready at 1312fdd, Blocking: none, after 1 review and 2 re-reviews. Fixed findings: a failed head could publish a short key (now a marker, exit 1 before ln); dash skipped the EXIT trap on SIGTERM (now HUP/INT/TERM exit 1); the signal test's FIFO reader could cause SIGPIPE (now it reads the line first). CI green at this head. Next step after merge: Brian tags v0.1.1 (make bump).

@bketelsen
bketelsen merged commit 0424a73 into main Oct 28, 2026
11 checks passed
@bketelsen
bketelsen deleted the feat/secrets-key-unit branch October 28, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants