Skip to content

MH7: table-mode start checks and cross-host transport - #738

Merged
Yoshiofthewire merged 3 commits into
mainfrom
feat/multihost-mh7
Nov 25, 2026
Merged

Yoshiofthewire merged 3 commits into
mainfrom
feat/multihost-mh7

Conversation

@Yoshiofthewire

Copy link
Copy Markdown
Member

In one line: In table mode (multi, or a migrated install; neither can start yet), a replica no longer needs one Docker host. It refuses to start while anything shared would sit on its own disk or cross hosts in clear text.

What changed

  • In table mode the boot-ID and volume-ID host checks are skipped and replica-volume.id is not written. Single mode keeps both checks byte for byte, and TestTopologyGuard is unchanged.
  • The volume-free assertion runs before anything registers or listens. Table mode refuses to start today, by design: 9 stores are still written to the host's disk (native-mailbox.json, the push/APNs relay keys, bulk-backup.repo, the Cloudflare receiving files, tuning.md, admin.env, first-run-password.txt). The spec lists each with its write site.
  • Table mode refuses, at start:
    • a plain listener;
    • a database URL without sslmode=verify-full, or a session that keeps a dead connection longer than 60 s idle or 30 s with unacknowledged data (tcp_user_timeout), unless every database host is loopback;
    • http Ollama, push relays or KyIdentity off loopback, allowInsecureIssuer, and ALLOW_INSECURE_SMTP.
  • The volume-free test diffs the three data roots while every org-bound route's cases run on table documents. Only per-host files may change.
  • The spec's unverified "Encryption in transit" rows are settled by reading the code. The peers, KyRecovery and the native SMTP relay already refuse clear text; Ollama, the DB URL, push relays and KyIdentity did not.
  • The docs gain the table-mode refusals: RUNNING.md, replica/AGENTS.md, and the spec's "MH7 start checks and transport as built".

Review this

Safe to skip: the docs, and the CHANGELOG line.

Checked:

  • 17 of 17 mutations are killed: each check removed in turn makes its test fail.
  • SQLite -race on every package. app and replica were rerun in place after the PGSSLMODE fix.
  • PostgreSQL 17 (C locale, own container) -race: the CI stores-leg packages, plus api -run 'Table|Tenancy|CrossOrg|Replica|Org'.
  • gofmt, vet, golangci-lint (0 issues) and deadcode are clean.

Not checked:

  • The full api suite on PostgreSQL (CI's api-1/api-2 legs).
  • The volume-free test's flows beyond the cross-org matrix: directory provisioning, mail receipt and send, DKIM rotation, a scheduled send, a pickup link, an import and a backup. These are unproven.
  • The in-process two-host test and the multi-host Compose profile (not built).
  • app.Run's call to checkTableTransport has no test of its own; the function is tested directly.

Decided for you:

  • The checks key on table mode, as the spec's MH7 step says, not on multi mode alone.
  • Empty directories are not compared in the volume-free test: stores MkdirAll per-user and imports/ directories, which carry no data.
  • The keepalive bound is checked at start rather than set by the app, so single installs' connections are untouched. The bound is 60 s total; the spec says "about 30 s".

You need to: nothing for this PR. multi stays refused. The 9 on-disk stores above must move before K PR 7 can accept multi.

Detail

Host checks. replica.Process.Table is set from users.TableMode. In table mode recordedVolume reads meta replica_volume_id, minting it on first use, so instance rows keep one schema. ErrReceiver still refuses. Test: TestTableModeLiftsHostChecks (two "hosts" with their own roots and boot IDs are admitted, no ID file is written, both instance rows carry the recorded ID).

Volume-free assertion. tenancy.Targets gives each fileClass name one target: database, documents, key, fence, absent, host or file. tenancy.HostFiles lists state/imports/*/upload-*, state/mail-bulk.json, state/recovery.pub and state/recovery-pin.generation. TestEveryStoreIsClassified now also fails when:

  • a class has no target, or a target has no class;
  • a per-host store has no pattern, or a pattern names no per-host store.

recovery.pub and recovery-pin.generation are newly inventoried. app.startReplica calls assertVolumeFree in table mode, which refuses (tenancy.ErrHostFiles) when:

  • the config or state root is not on the documents table;
  • any store's target is file.

Tests: TestAssertVolumeFree and TestTableModeStartRunsTheVolumeFreeAssertion. The second shows a refused start registers no instance and writes no replica-volume.id, and that each root check refuses on its own.

Volume-free test. api.TestTableModeWritesNothingOnTheHostsDisk (PostgreSQL) runs runCrossOrgMatrix on table documents and compares every file's mode and SHA-256 under config, state and private. Exceptions:

  • Key files are allowed, because this fixture provisions none. MH5's RefuseCreate refuses creating a key in table mode.
  • file-target stores are allowed, because the start check already refuses them.

The first run, before the directory and key exceptions, reported only empty user/imports directories and scheduled-send.key. Without mountServerDocuments, the test fails.

Transport. app.checkTableTransport runs in app.Run right after startDocuments in table mode. MH8's migration must call the same function. It requires:

  • TLS_CERT_FILE and TLS_KEY_FILE that load as a pair (the api binds every interface);
  • ALLOW_INSECURE_SMTP not set;
  • Ollama over https, or over http on loopback;
  • relay URLs that pass processor.ValidateRelayURL;
  • an https KyIdentity issuer with no allowInsecureIssuer;
  • dbbackend.CheckTableTransport: verify-full off loopback, and the session's tcp_keepalives_* and tcp_user_timeout within bounds.

Tests:

  • TestTableTransportRefusesEachCleartextHop, one case per refusal;
  • TestTableTransportNeedsVerifyFull, with 10 URL forms and PGSSLMODE;
  • TestDeadConnectionBounds, including the Linux defaults;
  • TestSessionBoundsReadTheServer, against a real PostgreSQL session.

PGSSLMODE is classified per host (TestEveryEnvironmentVariableIsClassified).

Mutations (each one fails its test):

  • the p.Table branch;
  • the assertVolumeFree call, and its root check;
  • AssertVolumeFree's file case, and its pattern check;
  • the TLS block, and the key-pair load;
  • the SMTP opt-out, Ollama and relay checks;
  • the issuer scheme and allowInsecureIssuer checks;
  • the sslmode check and the loopback exemption;
  • each dead-connection bound;
  • the test's documents mount.

Run log:

  • SQLite -race ./...: Every K host was busy, so it ran on Major. TestEveryEnvironmentVariableIsClassified failed (PGSSLMODE, fixed in 1330cf0), and app failed with output past the captured tail. app and replica then pass in place (ok app 181s, ok replica 5.6s). The k83 rerun failed only on files outside backend/ that kjob does not copy (.env.example, receiving-worker/senders.json).
  • PostgreSQL -race: every stores-leg package passed except processor, in a run whose container kept the default 100 connections. Alone with max_connections=400 (CI's value), processor passes (ok 65s). api filtered: ok 252s.

🤖 Generated with Claude Code

Yoshiofthewire and others added 2 commits November 25, 2026 12:18
In table mode (multi, or a migrated install; neither can start yet):
- skip the boot-ID and volume-ID host checks; the instance records the
  database's volume ID and no replica-volume.id is written;
- run the volume-free assertion before anything registers or listens:
  tenancy.Targets gives every inventoried file store its table-mode target,
  tenancy.HostFiles the per-host patterns, and a store still written to the
  host's disk refuses the start (several still are; listed in the spec);
- refuse a plain listener, a database URL without sslmode=verify-full or
  with loose keepalive/tcp_user_timeout bounds off loopback, cleartext
  Ollama, push relays and KyIdentity, and ALLOW_INSECURE_SMTP.

The volume-free test diffs the three roots across every org-bound route's
cases with table documents mounted. Single mode is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The table-mode database check reads it as pgx does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kypost-server-738, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire
Yoshiofthewire merged commit de1a679 into main Nov 25, 2026
28 checks passed
@Yoshiofthewire
Yoshiofthewire deleted the feat/multihost-mh7 branch November 25, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant