Skip to content

Setting it up

Deploying

What runs, what it needs, and what has to be backed up.

Three containers: PostgreSQL, the API (which also serves the dashboard and this documentation), and the worker.

postgres the whole state — configuration, mappings, queue, audit
api the dashboard, the HTTP API, and /docs
worker the loops that read, write and verify

The API and the worker are the same build and share the same database. Either can be scaled; the worker is the one that usually needs it, and several workers coordinate through the queue’s leases rather than through anything they share directly.

Two things, kept apart: PostgreSQL, and the protection key. Everything else is rebuildable from the image.

Losing the database is not losing the contacts — those are in real mailboxes — but it is losing the mapping between a source contact and the card that represents it, which is what lets the product recognise its own work. scripts/backup-postgres.sh and scripts/restore-postgres.sh exist for this.

A backup holds no permissions. After a restore, docker compose up -d runs the migrate step before the API and the worker start, and it gives the role they log in as its permissions again; contactmesh restore does the same.

CHECKPOINT_PROTECTION_KEY seals every tenant’s Graph credential, every database source’s password, every delta checkpoint and the keys that sign the session cookies. The database holds them sealed and pg_dump does not hold the key, which is what makes a stolen backup worth nothing — and a backup restored without the key worth little more.

Back it up apart from the database, in two places:

  • A password manager the administrators already use, as an entry named for this deployment, with the day the key was made.
  • An offline copy, printed or on a removable drive in a safe, where a compromise of the server or of the password manager does not reach.

Keep every key until nothing is sealed under it. After a rotation the old key stays in both places until Settings → Security → Protection key counts nothing under it.

scripts/recovery-drill.sh restores a dump into a throwaway container, checks its tables, and — given the key as it was backed up — proves that every kind of stored secret opens with it:

Terminal window
scripts/recovery-drill.sh /secure/backup/contactmesh.dump /secure/keys/protection-key

Give it the copy you would restore from: the password manager’s entry saved to a file, or the offline one typed back in. A third argument is a file of previous keys, one a line, for a backup taken during a rotation. A key that opens nothing fails the drill and names what it could not open. The same check runs against the live database with docker compose run --rm api check-protection-key.

Only the API publishes a port, and by default only on the loopback interface: put a reverse proxy in front of it with a certificate. The documentation is served under /docs by the same container, on the same port, for exactly that reason — a second published port is a second firewall rule on a host whose rules are already the subtle part.

Keep the proxy’s read timeout at 60 seconds or above (proxy_read_timeout 300s; is comfortable). Rounds, checks, re-reads, Read changes, directory refreshes and the permission probe started from the dashboard are handed to the worker, but the views that show a mailbox as it is now still read Graph inside the request, and a request the proxy cuts off is cancelled with it.

Let the proxy pass request bodies of 2 MB (client_max_body_size 2m; in nginx, whose default is 1 MB). ContactMesh itself takes at most 1 MB in a request, and 2 MB for a tenant’s certificate, which is the one file the dashboard uploads; anything larger is refused as too large. A push source takes up to 8 MB a push under /push/: where your jobs push, let the proxy pass 9 MB there.