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
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
timeout-minutes: 20
services:
postgres:
image: postgres:17.6-alpine@sha256:ef257d85f76e48da1c64832459b59fcaba1a4dac97bf5d7450c77753542eee94
image: postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71
env:
POSTGRES_USER: ci
POSTGRES_PASSWORD: ci
Expand All @@ -154,6 +154,22 @@ jobs:
KY_TEST_POSTGRES_DSN: postgres://ci:ci@127.0.0.1:5432/ci_test?sslmode=disable
run: go test -race -count=1 ./...

# The Matrix overlay's automatic PostgreSQL 17 -> 18 move, on real 17 data seeded with the last
# 17 Compose files (the commit the script names).
postgres-upgrade:
name: PostgreSQL 17 to 18 upgrade (Matrix Compose)
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
cache: true
- run: git fetch --no-tags --depth=1 origin "$(sed -nE 's/^PG17_REF=\$\{PG17_REF:-([0-9a-f]{40})\}.*/\1/p' scripts/test-postgres-17-to-18.sh)"
- run: scripts/test-postgres-17-to-18.sh

web:
name: Frontend typecheck & build
if: github.event.pull_request.draft != true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ jobs:
REQUIRED: |
Go build, vet & tests (SQLite)
Go tests (PostgreSQL)
PostgreSQL 17 to 18 upgrade (Matrix Compose)
Frontend typecheck & build
Browser regressions (production server)
Matrix acceptance (encrypted storage, closed server)
Expand Down
12 changes: 10 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ When the user requests a durable behavior change, record it here or in the relev
`postgres_password`, never created by Docker (a `/dev/null` mask inside a read-only bind
breaks `docker cp`). The role does not bound the app: the configs it backs up hold the owner
passwords and shared secrets;
the image's `postgresql17-client` major must equal the Postgres tag, which the check enforces), and
the image's `postgresql18-client` major must equal the Postgres tag, which the check enforces), and
it hands the app the `KY_MATRIX_*` locations and MAS admin settings: the internal
`matrix-admin` network (only app and mas; alias `mas-admin`) and the admin secret as a Compose secret.
It requires `KY_KYIDENTITY_HMAC_SECRET`, as config does with Matrix set. `scripts/check-compose-matrix.sh` checks it
Expand All @@ -183,6 +183,14 @@ When the user requests a durable behavior change, record it here or in the relev
stock (owner decision 2026-10-02): exactly that file at `/app/config.json:ro`, which its image
copies at start, so a rename shows after `docker compose restart element`; the check refuses
any `/dev/null`, `/tmp/element-web-config` or `/docker-entrypoint` mount on Element.
Postgres is 18 on the whole `matrix-postgres` volume at `/var/lib/postgresql` (the image's
`18/docker`, no `PGDATA`), beside the 17 data in `pgdata/`, which nothing deletes or writes
(owner decision 2026-11-25). A 17 stack moves on its next `up`: the one-shot `postgres-17-dump`
(17 image, no network, read-only root) dumps `pgdata/` once, and postgres's entrypoint
restores it before the stock one; both run `scripts/postgres-17-to-18.sh`, Ky's shared kit,
byte for byte (the check holds its checksum; fix it upstream in the kit, never only here).
`scripts/test-postgres-17-to-18.sh` (CI job `postgres-upgrade`) proves the move on 17 data
seeded with the last 17 Compose files; operator steps in `docs/CHAT-SETUP.md` "PostgreSQL 18".
`restore-matrix` (profile `restore`, `docker compose run --rm restore-matrix`) runs the app image as
`KY_MATRIX_UID:KY_MATRIX_GID` with no capability on `matrix-db` only; it is the only
read-write media mount besides Synapse, and its `./data`, `./backups` and `./matrix` are
Expand Down Expand Up @@ -246,7 +254,7 @@ When the user requests a durable behavior change, record it here or in the relev
CI (`.github/workflows/ci.yml`) runs on every push and every non-draft pull request (drafts skip until marked ready):
- `make lint` equivalent: gofmt, `go vet`, `go mod tidy`/`verify`, `scripts/check-compose-proxy.sh`, `scripts/check-compose-matrix.sh` and `scripts/check-compose-podman.sh`
- `release binary is repeatable` (Go job): builds `./cmd/server` the way the Dockerfile does (`-trimpath`, from `git archive` copies, committed `web/dist`) in two directories and requires identical bytes. Keep the Dockerfile's `go build` and that step in step; `docs/VERIFYING-RELEASES.md` gives users the same command for both release images
- `go test -race` with coverage on SQLite, and the same suite against PostgreSQL 17
- `go test -race` with coverage on SQLite, and the same suite against PostgreSQL 18
- The same SQLite suite under `GODEBUG=fips140=on`, then `docs/check-strong-crypto-compose.py`
(nine Compose chains; `docker-compose.strong-crypto.yml` may add only the app's `GODEBUG`).
`docs/STRONG-CRYPTO.md` is the key-size table: update it with any key, secret or TLS client change
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
are gone.

### Changed
- Matrix's database moves to PostgreSQL 18.7. An existing PostgreSQL 17 stack upgrades by
itself on the next `docker compose up -d`: a one-shot dumps the 17 data once and Postgres
restores it into a new `18/docker` directory on the same volume. The 17 data is kept for a
rollback until you remove it. It needs about twice the database's size free
([Chat setup](docs/CHAT-SETUP.md#postgresql-18)). The app image's `pg_dump`/`pg_restore` are
now PostgreSQL 18, and capsules taken on 17 still restore.
- A SCIM account with the admin role signs in to the console through KyIdentity only when
`KY_SCIM_ALLOW_ADMIN=true`, and SCIM turning an inactive admin back on needs it too. An
empty `roles` from SCIM now removes the admin role.
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ RUN CGO_ENABLED=0 GOOS=linux go build -trimpath \

# Stage 3: Minimal Production Container
FROM alpine:3.24@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf
# postgresql17-client: pg_dump/pg_restore for Matrix backups; its major must equal the
# postgresql18-client: pg_dump/pg_restore for Matrix backups; its major must equal the
# postgres service's (scripts/check-compose-matrix.sh).
RUN apk --no-cache add ca-certificates tzdata postgresql17-client
RUN apk --no-cache add ca-certificates tzdata postgresql18-client
WORKDIR /app
COPY --from=backend-builder /app/kymessages /app/kymessages
# /app/backups is the optional mount for sealed local capsules; KY_BACKUP_DIR is set by the
Expand Down
9 changes: 7 additions & 2 deletions docker-compose.matrix-podman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
# KY_MATRIX_UID to the same host user, so these services read the 0600 files matrix-init wrote
# and the volume owner set by synapse-media-owner is the user Synapse runs as. matrix-init's
# Podman command (docs/CHAT-SETUP.md) gives ./matrix the shared container SELinux label;
# restore-matrix relabels the restored ./data, ./backups and ./matrix it reads.
# restore-matrix relabels the restored ./data, ./backups and ./matrix it reads. Both Postgres
# services label the PostgreSQL 17 -> 18 script they run, which lives outside ./matrix.
services:
postgres: {userns_mode: keep-id}
postgres-17-dump:
userns_mode: keep-id
volumes:
- &pg-upgrade {type: bind, source: ./scripts/postgres-17-to-18.sh, target: /ky/postgres-17-to-18.sh, read_only: true, bind: {create_host_path: false, selinux: z}}
postgres: {userns_mode: keep-id, volumes: [*pg-upgrade]}
synapse-media-owner: {userns_mode: keep-id}
synapse: {userns_mode: keep-id}
mas: {userns_mode: keep-id}
Expand Down
44 changes: 37 additions & 7 deletions docker-compose.matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,57 @@ services:
- {<<: *matrix-ro, source: ./matrix/secrets/kyidentity_client_secret, target: /matrix/secrets/kyidentity_client_secret}
- matrix-media:/matrix-media:ro

# PostgreSQL 18 keeps its data in 18/docker of the same volume, beside the 17 data in pgdata/,
# which stays untouched (docs/CHAT-SETUP.md "PostgreSQL 18"). A 17 stack moves on its first
# start: this one-shot dumps pgdata/ once into upgrade-from-17/, then the postgres service
# restores that dump before it starts. Without 17 data it does nothing.
postgres-17-dump:
image: postgres:17.12-alpine3.24@sha256:f9cf3e1f0066f0eb0c48707d864f0ac5941e9ff454a072077d97a4d278d07d73
user: "${KY_MATRIX_UID:?}:${KY_MATRIX_GID:?}"
entrypoint: ["bash", "/ky/postgres-17-to-18.sh", "dump"]
environment:
OLD: /v/pgdata
NEW: /v
network_mode: none
restart: "no"
# A clean stop removes postmaster.pid, without which the next dump refuses.
stop_grace_period: 2m
read_only: true
tmpfs: [/tmp]
security_opt: ["no-new-privileges:true"]
cap_drop: [ALL]
volumes:
- matrix-postgres:/v
- &pg-upgrade {type: bind, source: ./scripts/postgres-17-to-18.sh, target: /ky/postgres-17-to-18.sh, read_only: true, bind: {create_host_path: false}}

postgres:
<<: *hardening
image: postgres:17.6-alpine@sha256:ef257d85f76e48da1c64832459b59fcaba1a4dac97bf5d7450c77753542eee94
image: postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71
user: "${KY_MATRIX_UID:?Set KY_MATRIX_UID (printed by matrix-init)}:${KY_MATRIX_GID:?Set KY_MATRIX_GID (printed by matrix-init)}"
# Restores postgres-17-dump's dump once, then runs the image's own entrypoint.
entrypoint: ["bash", "/ky/postgres-17-to-18.sh", "restore"]
command: [postgres]
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
# A subdirectory: the volume root belongs to the image's postgres user, and initdb must
# own its directory.
PGDATA: /var/lib/postgresql/data/pgdata
secrets: [postgres_password]
networks: [matrix-db]
volumes:
- matrix-postgres:/var/lib/postgresql/data
- matrix-postgres:/var/lib/postgresql
- ./matrix/postgres:/docker-entrypoint-initdb.d:ro
# TCP, not the socket: during first-run init the entrypoint's temporary server listens on
# the socket only, so this passes once init.sql has run and the real server is up.
- *pg-upgrade
depends_on:
postgres-17-dump: {condition: service_completed_successfully}
# Time for a clean shutdown, so a rollback to 17 or a restore never meets a crashed cluster.
stop_grace_period: 2m
# TCP, not the socket: during first-run init or the restore the temporary server listens on
# the socket only, so this passes once the real server is up. The restore takes about as
# long as a pg_dumpall restore of the data, hence the long start period.
healthcheck:
test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "postgres", "-d", "postgres"]
interval: 5s
timeout: 5s
retries: 30
start_period: 1h

# The media volume starts root-owned (the image's /media); hand it to the Synapse user once
# per start. Only CAP_CHOWN, no network.
Expand Down
2 changes: 1 addition & 1 deletion docs/ASSURANCE-CASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ encrypt.
## Evidence

- **Tests:** the security tests named above and the whole suite under the race detector, on SQLite
and on PostgreSQL 17; Vitest; Chromium and Firefox regressions against the built server; the
and on PostgreSQL 18; Vitest; Chromium and Firefox regressions against the built server; the
Matrix acceptance job (encrypted storage, closed server); backup acceptance and the smoke test,
on every push and pull request.
- **Static analysis:** `go vet`, `govulncheck`, strict TypeScript (`tsc`), `shellcheck` on the
Expand Down
29 changes: 29 additions & 0 deletions docs/CHAT-SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,35 @@ Upgrading a stack from before Matrix backups:
`KY_BACKUP_MEDIA_FULL_KEEP`.
4. `docker compose up -d`. The first scheduled run then backs up Matrix.

## PostgreSQL 18

Matrix's database runs PostgreSQL 18. A stack set up on PostgreSQL 17 moves on the first
`docker compose up -d` after you update the checkout, with nothing to run by hand:

- `postgres-17-dump`, a one-shot on the 17 image with no network, dumps the 17 data in the
`matrix-postgres` volume (`pgdata/`) once into `upgrade-from-17/` on the same volume. Postgres
then restores that dump into `18/docker` and starts 18. The roles and their passwords come
from the dump, so Synapse, MAS and backups connect as before. The 17 data is only read; it is
never deleted or rewritten. On later starts both steps see the move is done and do nothing.
A fresh install has nothing to move and initialises 18 directly.
- **Space:** about twice the database's size free on the volume's disk (the dump plus the new
cluster). With less, `postgres-17-dump` refuses and writes nothing: free space, then
`docker compose up -d` again. `docker compose logs postgres-17-dump` says which. It also
refuses while `pgdata/postmaster.pid` exists, that is, while 17 still runs on the data or
if 17 did not stop cleanly. Stop it, or start the previous release once and stop it, then
`docker compose up -d` again.
- **Time:** about as long as a dump and restore of the database. Postgres is unhealthy until
the restore finishes, so Synapse and MAS wait; its health check allows an hour. Watch with
`docker compose logs -f postgres`. A restore interrupted half-way starts again from scratch
on the next start. A dump that fails to restore never leaves an empty database: Postgres
stops with the error instead.
- **Roll back** by checking out the previous release (Compose files and app image together)
and `docker compose up -d`: 17 starts on its untouched data. Anything written while on 18
is not in it. Going forward again reuses the 18 cluster.
- **Clean up**, once you are satisfied and no longer want to roll back, if you choose to:
`docker compose exec postgres rm -r /var/lib/postgresql/pgdata /var/lib/postgresql/upgrade-from-17`.
That frees the space and makes a rollback to 17 impossible.

Element's Home view (no room open) shows "Welcome to KyMessages" and links to the other suite
apps KyIdentity lists, served by the console at `<KY_ADMIN_HOST>/element-home.html` (Element's
`embedded_pages.home_url`). Each app still asks KyIdentity whether the person may open it.
Expand Down
2 changes: 1 addition & 1 deletion docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ and `KY_TRUSTED_PROXIES`; publishes no port; names the network `kymessages-net`)
## Verification

`make ci` runs formatting, module checks, race tests, frontend tests and the running
server smoke checks. `make test-postgres` needs a disposable PostgreSQL 17 instance.
server smoke checks. `make test-postgres` needs a disposable PostgreSQL 18 instance.
See [web/AGENTS.md](../web/AGENTS.md) for production-CSP, keyboard and responsive browser
checks.
The smoke CI job also runs `python3 scripts/backup-acceptance.py`, a three-minute
Expand Down
3 changes: 2 additions & 1 deletion docs/RESTORE.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ restoring her keys from key backup; the server name and signing key were unchang
image (`docker compose pull app`; `restore-matrix` runs the same image and never pulls) or
build it (build overlay).
4. Only if this stack is meant to be replaced: `docker compose down -v`, which deletes its
Matrix database and media. Then `docker compose up -d postgres`, nothing else.
Matrix database and media. Then `docker compose up -d postgres`, nothing else. A capsule
taken while Matrix ran PostgreSQL 17 restores into the PostgreSQL 18 stack.
5. `docker compose run --rm restore-matrix`. Add `-skip-media` only if no media backup
survived; uploads from before the backup are then missing. It runs as `KY_MATRIX_UID`
with no capabilities and restores as the database owners, with no superuser.
Expand Down
2 changes: 1 addition & 1 deletion internal/health/genpins/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestPinsMatchCompose(t *testing.T) {

func TestTagVersion(t *testing.T) {
for image, want := range map[string]string{
"postgres:17.6-alpine@sha256:ef25": "17.6",
"postgres:18.7-alpine3.24@sha256:0115": "18.7",
"ghcr.io/element-hq/synapse:v1.162.0@sha256:6b84": "1.162.0",
"ghcr.io/element-hq/matrix-authentication-service:1.26.0": "1.26.0",
"registry.local:5000/element-web:v1.12.30": "1.12.30",
Expand Down
2 changes: 1 addition & 1 deletion internal/health/pins.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/agent-probe/probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for tool in docker curl jq openssl python3; do
command -v "$tool" >/dev/null || { echo "probe: $tool is required" >&2; exit 2; }
done
img() { grep -m1 -o "image: $1[^ ]*" "$pins" | cut -d' ' -f2; }
pg_image=$(img postgres:)
pg_image=$(img postgres:18)
syn_image=$(img ghcr.io/element-hq/synapse:)
mas_image=$(img ghcr.io/element-hq/matrix-authentication-service:)

Expand Down Expand Up @@ -165,7 +165,7 @@ services:
postgres:
image: $pg_image
environment: {POSTGRES_PASSWORD: "$(openssl rand -hex 16)"}
volumes: [pgdata:/var/lib/postgresql/data, ./pg-init:/docker-entrypoint-initdb.d:ro]
volumes: [pgdata:/var/lib/postgresql, ./pg-init:/docker-entrypoint-initdb.d:ro]
healthcheck: {test: [CMD, pg_isready, -h, 127.0.0.1, -U, postgres], interval: 2s, retries: 60}
mas:
image: $mas_image
Expand Down
Loading