Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ updates:
interval: weekly
cooldown:
default-days: 3
# PostgreSQL majors move data (docs/RUNNING.md, "PostgreSQL 18"): a new major needs a
# written migration, and the 17 dump one-shot must stay on 17.
ignore:
- dependency-name: "postgres"
update-types: ["version-update:semver-major"]
groups:
actions:
patterns: ["*"]
Expand All @@ -150,15 +155,25 @@ updates:
interval: weekly
cooldown:
default-days: 3
# PostgreSQL majors move data (docs/RUNNING.md, "PostgreSQL 18"): a new major needs a
# written migration, and the 17 dump one-shot must stay on 17.
ignore:
- dependency-name: "postgres"
update-types: ["version-update:semver-major"]
commit-message:
prefix: "chore(deps)"

# Pinned images in the optional compose files (rspamd).
# Pinned images in the optional compose files (rspamd, the replica overlay's PostgreSQL).
- package-ecosystem: docker-compose
directory: /
schedule:
interval: weekly
cooldown:
default-days: 3
# PostgreSQL majors move data (docs/RUNNING.md, "PostgreSQL 18"): a new major needs a
# written migration, and the 17 dump one-shot must stay on 17.
ignore:
- dependency-name: "postgres"
update-types: ["version-update:semver-major"]
commit-message:
prefix: "chore(deps)"
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ jobs:

# The store, backup, restore and migration suites, the poller, and internal/api (held and
# scheduled sends live in its global state store), again with every store on a
# Postgres 17 service (UTF8, C locale, as docs/RUNNING.md requires). Each test opens
# Postgres 18 service (UTF8, C locale, as docs/RUNNING.md requires). Each test opens
# a schema of its own (dbbackend's test hook); tests about SQLite files skip, visibly
# in -v output. internal/api is sharded by test name as in backend-api-test.
backend-postgres-test:
Expand All @@ -287,7 +287,7 @@ jobs:
leg: [stores, api-1, api-2]
services:
postgres:
image: postgres:17@sha256:3b0cda93be7c8dba2ed484d19393d93845dc3dafb88973e248ba8e6d99d784e1
image: postgres:18.7-trixie@sha256:c699303802144847d238196173655dbbecf7a96aeca1565f2b02eb671a1f0b6b
env:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_INITDB_ARGS: --locale=C --encoding=UTF8
Expand Down Expand Up @@ -769,6 +769,12 @@ jobs:
- name: replica cutover (SQLite -> PostgreSQL -> two replicas)
run: bash scripts/check-replica-cutover.sh kypost-server:ci

# The replica overlay's PostgreSQL, seeded on 17 with the previous compose files, moves
# to 18 on the next up -d over the running 17; a dump beside a live 17 refuses; passwords
# from another container; rollback, rerun, a bad dump and a fresh install. Needs no image.
- name: replica PostgreSQL 17 -> 18 upgrade
run: bash scripts/test-postgres-17-to-18.sh

- name: container logs
if: always()
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ non-prerelease version.
## Unreleased

- In table mode (not startable yet), skip the one-host boot-ID and volume-ID checks and refuse to start instead while any store still lives on the host's disk; refuse a plain listener, a database URL without `sslmode=verify-full` or with unbounded dead-connection keepalives off loopback, cleartext Ollama, push relays or KyIdentity, and `ALLOW_INSECURE_SMTP`. Ordinary installs are unchanged.
- Move the replica overlay's database to PostgreSQL 18. An install on 17 moves by itself on the next `up`: a one-shot dumps the 17 volume, which is kept for rollback, and 18 restores it once before starting. Needs about twice the data in free space; see [PostgreSQL 18](docs/RUNNING.md#postgresql-18). CI now tests on PostgreSQL 18.
- CI now runs the poller and health tests on PostgreSQL, and fails when a package whose tests use the database is left out of the PostgreSQL job. The quiet-mailbox tests now check that PostgreSQL mailboxes are polled on every pass, as documented, instead of expecting the SQLite-only skip.
- Share the proof-of-work escalation across table-mode replicas, and run one mail import or export per organization at a time across replicas on a multi-tenant server. Single installs are unchanged.
- In table mode, claim each incoming message across hosts before the poller works on it, so a daemon resuming after a freeze and the new owner never both label, record and push one message; the own-address send-as probe is mailed once. Ordinary installs are unchanged.
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ if a job is genuinely flaky, that is a bug to fix in the job.
|---|---|
| `ci-backend-api` | `gofmt -l`, `go vet`, two builds of the release binary that must be byte-identical, `golangci-lint`, `govulncheck`, `deadcode` (nothing unreachable from `cmd/` beyond `backend/deadcode.allow`), `go test -race ./internal/api/...`, then again with `GODEBUG=fips140=on` ([strong-key profile](docs/STRONG-CRYPTO.md)) |
| `ci-backend-other` | Same lint gates, `go test -race` on every other backend package, again with `GODEBUG=fips140=on`, then 20-second fuzz runs for rules, redaction, reply threading and IMAP header records |
| `ci-backend-postgres` | `go test -race` on the store, backup, restore and migration packages, the poller (`internal/processor`), `internal/health` and `internal/api` (two shards) with every store on a digest-pinned `postgres:17` service (UTF8, C locale) through `KYPOST_TEST_DATABASE_URL`; the stores leg fails when a package whose tests import `dbbackend` is not on its list; green only when every leg (`ci-backend-postgres (stores)`, `(api-1)`, `(api-2)`) passed |
| `ci-backend-postgres` | `go test -race` on the store, backup, restore and migration packages, the poller (`internal/processor`), `internal/health` and `internal/api` (two shards) with every store on a digest-pinned `postgres:18` service (UTF8, C locale) through `KYPOST_TEST_DATABASE_URL`; the stores leg fails when a package whose tests import `dbbackend` is not on its list; green only when every leg (`ci-backend-postgres (stores)`, `(api-1)`, `(api-2)`) passed |
| `ci-frontend` | `npm audit --omit=dev --audit-level=low` (blocking), `tsc --noEmit`, ESLint (rules-of-hooks errors block), `vitest`, `vite build` |
| `ci-relay` | Typecheck both relay Workers, `node --test` on the relay and one-message receiving Worker behaviour suites, disposable workerd/R2 capture and pickup qualification |
| `ci-scripts` | Shell syntax and shellcheck, CI Go/Node pins equal the Dockerfile builder tags, the `.env.example`-reaches-Compose and `supervisord.conf` log-file checks, setup-wizard definition-only input/dotenv/Compose checks, receiver launcher refusal checks, pinned Rspamd effective-config/socket/clean/GTUBE/privacy qualification, the `update-host` and model-installer self-checks, `compose config`, the strong-key overlay changing nothing but `GODEBUG`, the cumulative Supervisor shutdown budget, the live-main publish-gate regression, and the workflow shape assertions that keep the release and `:main` publish gates from being quietly deleted |
| `ci-docker` | `docker build`, private-root real-entrypoint regression, real Supervisor serial-drain regression, container reaches `healthy` with the optional receiver stopped by default, and the entrypoint still refuses a non-loopback cleartext bind |
| `ci-docker` | `docker build`, private-root real-entrypoint regression, real Supervisor serial-drain regression, container reaches `healthy` with the optional receiver stopped by default, the entrypoint still refuses a non-loopback cleartext bind, the replica cutover, and the replica overlay's PostgreSQL 17 → 18 move on real data (`scripts/test-postgres-17-to-18.sh`) |

Notes that trip people up:

Expand Down
2 changes: 1 addition & 1 deletion backend/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ This list is the CI gate. `ci-backend-checks` runs the static steps, the release
- `go list -deps -test ./... | grep '^golang.org/x/crypto/openpgp'` must print nothing (`ci-backend-checks`). `osv-scanner.toml` ignores GO-2026-5932 (x/crypto/openpgp unmaintained) only because of this; PGP uses `github.com/ProtonMail/go-crypto`. Never import x/crypto/openpgp; if that changes, drop the ignore
- `go tool -modfile=../tools/go.mod deadcode -test=false ./cmd/...` (`ci-backend-checks`) must report exactly the functions `deadcode.allow` lists. Delete code nothing in `cmd/` reaches; test-only code goes in a `_test.go` file or a `*test` package (`pgpmail/pgpmailtest`, `sso/ssotest`). The allow list is only for hooks other packages' tests call to reach unexported state
- `go build -buildvcs=false ./...` must succeed with zero errors
- With a throwaway `postgres:17` (UTF8, C locale), `KYPOST_TEST_DATABASE_URL=postgres://postgres@localhost:5432/postgres?sslmode=disable go test -race -count=1 -timeout=30m -p 2 ./internal/dbbackend/... ./internal/state/... ./internal/mailbox/... ./internal/ingress/... ./internal/cfreceiving/... ./internal/sso/... ./internal/backup/... ./internal/app/... ./internal/worker/... ./internal/replica/... ./internal/mfa/... ./internal/captcha/... ./internal/kycalendar/... ./internal/suitepair/... ./internal/tenancy/... ./internal/vol/... ./internal/volumes/... ./internal/users/... ./internal/contacts/... ./internal/processor/... ./internal/health/...` must pass, and so must `go test -race -count=1 -timeout=30m ./internal/api/` with the same variable (`ci-backend-postgres`, which shards `internal/api` in two, and fails its stores leg when a package whose tests import `dbbackend` is missing from that list): every store runs on Postgres, one schema per test path; tests about SQLite files, WAL or restore staging skip and say so in `-v` output. Without the variable those Postgres-only tests skip.
- With a throwaway `postgres:18` (UTF8, C locale), `KYPOST_TEST_DATABASE_URL=postgres://postgres@localhost:5432/postgres?sslmode=disable go test -race -count=1 -timeout=30m -p 2 ./internal/dbbackend/... ./internal/state/... ./internal/mailbox/... ./internal/ingress/... ./internal/cfreceiving/... ./internal/sso/... ./internal/backup/... ./internal/app/... ./internal/worker/... ./internal/replica/... ./internal/mfa/... ./internal/captcha/... ./internal/kycalendar/... ./internal/suitepair/... ./internal/tenancy/... ./internal/vol/... ./internal/volumes/... ./internal/users/... ./internal/contacts/... ./internal/processor/... ./internal/health/...` must pass, and so must `go test -race -count=1 -timeout=30m ./internal/api/` with the same variable (`ci-backend-postgres`, which shards `internal/api` in two, and fails its stores leg when a package whose tests import `dbbackend` is missing from that list): every store runs on Postgres, one schema per test path; tests about SQLite files, WAL or restore staging skip and say so in `-v` output. Without the variable those Postgres-only tests skip.
- `go test -race -count=1 -timeout=20m ./...` must pass. The sorter parity test and the poller's hybrid tests skip unless `EMBED_MODEL_DIR` points at the pinned model; the `ci-backend-other` legs download it using the Dockerfile's `EMBED_*` ARG pins, so set it locally too or those tests prove nothing. The `-timeout` is not optional: `internal/api` alone exceeds Go's default 600s under `-race`, which is why CI splits it into its own shards and passes `-timeout=20m`. Running plain `go test -race ./...` locally reports a timeout that CI would not see

- `GOTOOLCHAIN=go1.26.9 go test -race ./internal/sso ./internal/api -run '^TestReleaseFloor' -count=1` checks monotonic durable release floors, the refusal rule, snapshot validation, webhook refusal of stale activations while queued deletions apply, direct allocation refusal, unchanged active rows passing, and the worker quietly refusing administrator provisioning, unpublished allocation and reallocation of a repaired account while the disable path converges.
Expand Down
36 changes: 33 additions & 3 deletions docker-compose.replicas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,31 @@ services:
ollama:
condition: service_started

# PostgreSQL 17 installs move to 18 on the next `up`: this one-shot dumps the 17 volume
# (kypost_pgdata, only read) into the 18 volume once, and the 18 service restores it before
# it starts (docs/RUNNING.md, "PostgreSQL 18"). Fresh installs have nothing to dump.
postgres-17-dump:
image: postgres:17.12-alpine3.24@sha256:f9cf3e1f0066f0eb0c48707d864f0ac5941e9ff454a072077d97a4d278d07d73
restart: "no"
network_mode: none
# A SIGKILLed 17 leaves postmaster.pid, which the dump then refuses.
stop_grace_period: 2m
entrypoint: ["bash", "/ky/postgres-17-to-18.sh", "dump"]
environment:
POSTGRES_USER: kypost
OLD: /var/lib/postgresql/data
NEW: /pg18
volumes:
- kypost_pgdata:/var/lib/postgresql/data
- kypost_postgres:/pg18
- ./scripts/postgres-17-to-18.sh:/ky/postgres-17-to-18.sh:ro

postgres:
image: postgres:17-alpine@sha256:526f86d93c6ea08fd3f1fe5605650cacc781b2c6013169a0ad8f42c7d3d84f32
image: postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71
restart: unless-stopped
stop_grace_period: 2m
# Restores the 17 dump once, if there is one, then runs the image's own entrypoint.
entrypoint: ["bash", "/ky/postgres-17-to-18.sh", "restore"]
environment:
POSTGRES_USER: kypost
POSTGRES_PASSWORD: ${KYPOST_POSTGRES_PASSWORD:?Set KYPOST_POSTGRES_PASSWORD in .env; there is no default}
Expand All @@ -66,15 +88,21 @@ services:
# Room for KYPOST_REPLICAS times the per-replica budget in docs/RUNNING.md.
command: ["postgres", "-c", "max_connections=${KYPOST_POSTGRES_MAX_CONNECTIONS:-400}"]
volumes:
- kypost_pgdata:/var/lib/postgresql/data
- kypost_postgres:/var/lib/postgresql
- ./scripts/postgres-17-to-18.sh:/ky/postgres-17-to-18.sh:ro
healthcheck:
# The entrypoint's temporary initialization server has only a Unix socket.
# The entrypoint's temporary initialization and restore servers have only a Unix socket.
test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "kypost", "-d", "kypost"]
interval: 2s
timeout: 2s
retries: 15
# A restore from 17 takes time in proportion to the data.
start_period: 1h
networks:
- database
depends_on:
postgres-17-dump:
condition: service_completed_successfully

ollama:
image: ollama/ollama:0.40.17@sha256:ccc42bcd3d5fcf7ab0d532b300382154e1a4da56fc666bdb313b78ebdd912754
Expand Down Expand Up @@ -112,7 +140,9 @@ services:
ipv4_address: ${KYPOST_PROXY_IP:?Set KYPOST_PROXY_IP to the proxy address inside KYPOST_REPLICA_SUBNET}

volumes:
# PostgreSQL 17's data, kept for rollback; remove it by hand once 18 checks out.
kypost_pgdata:
kypost_postgres:

networks:
replicas:
Expand Down
55 changes: 55 additions & 0 deletions docs/RUNNING.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,61 @@ change: stop every replica, then run
once with the new settings, and start again. The full list is in
[CONFIGURATION.md](CONFIGURATION.md#replicas).

### PostgreSQL 18

The overlay's database is PostgreSQL 18. An install that ran 17 (its data is in the
`kypost_pgdata` volume) moves to 18 by itself on the next `up` after `git pull`; the script
it uses, `scripts/postgres-17-to-18.sh`, is mounted from your checkout. Run the usual upgrade,
`docker compose pull && docker compose stop kypost-server && docker compose up -d --wait`:

1. The one-shot `postgres-17-dump` service (the 17 image, no network) starts 17 on
`kypost_pgdata` with a private socket, runs `pg_dumpall` into the new `kypost_postgres`
volume (`upgrade-from-17/dump.sql`) and stops 17. It writes nothing into `kypost_pgdata`;
17 may replay its own log while it starts.
2. The `postgres` service (18) restores that dump into `18/docker.part`, renames it to
`18/docker` once complete and then starts as usual. Roles, passwords and the C/UTF8
locale come across, so `KYPOST_DATABASE_URL` stays the same. The replicas wait until it
is healthy.

Each step runs once: later `up`s see `18/docker` and do nothing. `docker compose ps -a` then
lists `postgres-17-dump` as `Exited (0)`, which is its healthy, finished state. A fresh install has nothing
to move and initialises 18 directly (the `kypost_pgdata` volume then stays empty).

- **Disk:** about twice the 17 data free on the volumes' filesystem (the dump plus the new
cluster). With less, the dump stops with a message naming both sizes and writes nothing;
free space and `up` again.
- **Time:** a full dump, a reload and `ANALYZE`, so it grows with the data. The healthcheck
allows an hour before a failure counts; follow it with `docker compose logs -f postgres`.
- **If it fails:** the 18 service never starts on an empty or half-restored database. A
restore cut short is redone from the start on the next start. The logs name the error, and
`kypost_pgdata` is unchanged, so you can roll back. If 17 is still running on
`kypost_pgdata`, or was killed without a clean stop, the dump finds its `postmaster.pid`
and refuses: `up` stops 17 itself first, and both services get two minutes to shut down.
After a crash, start 17 once with the previous release and stop it, then `up` again.
- **Rollback:** stop every replica and `docker compose stop postgres`, check out the release
you came from (its `docker-compose.replicas.yml` runs 17 on `kypost_pgdata`) and
`docker compose up -d --wait`. Anything written on 18 is not in the 17 data.
- **Back to 18 after a rollback:** once 17 has run, the next `up` with this release stops
before 18 starts: the dump (`docker compose logs postgres-17-dump`) says 17 has run since
the move, because 18 lacks what 17 wrote since. This holds after the clean-up of the dump
too: the move's record, `18/moved-from-17.checkpoint`, sits beside the 18 cluster. Nothing
is deleted. Choose one, then `docker compose down` (keeps volumes) and `up` again:
- **Move 17 again** (keeps what 17 wrote, loses what was written on 18 before the
rollback): rename the old 18 cluster aside, `docker compose run --rm --no-deps
--entrypoint sh postgres -c 'mv /var/lib/postgresql/18 /var/lib/postgresql/18.replaced &&
mv /var/lib/postgresql/upgrade-from-17 /var/lib/postgresql/upgrade-from-17.replaced'`
(leave out the second `mv` if you already removed the dump). The next `up` dumps and
restores 17 as the first time did.
- **Keep 18 as it is** (what 17 wrote since stays only in `kypost_pgdata`):
`docker compose run --rm --no-deps --entrypoint rm postgres /var/lib/postgresql/18/moved-from-17.checkpoint`.
- **Clean-up**, your choice, once 18 has checked out (sign in, read mail, run **Back up
now**): stop the stack (`docker compose down`, which keeps volumes), then remove the dump,
`docker compose run --rm --no-deps --entrypoint rm postgres -r /var/lib/postgresql/upgrade-from-17`,
which is safe and keeps rollback. Removing the 17 volume (`docker volume rm
<project>_kypost_pgdata`) is a separate step; once it is gone, rollback means restoring a
backup. Nothing removes either automatically, nor the `18.replaced` and
`upgrade-from-17.replaced` directories a second move leaves (`rm -r` them the same way).

### Restoring a replica deployment

Restore into a new, empty database beside the old one, which stays untouched until the
Expand Down
Loading
Loading