Setting it up
From nothing to a dashboard
Docker, seven variables, three containers, and the first sign-in.
ContactMesh runs as three containers on one host. Getting to a signed-in dashboard is seven lines in a
file and one command. Nothing is created by hand first — no certificate, no secrets/ directory, no
account.
The Microsoft side comes after this page and needs none of it in place. You can reach a working dashboard before anybody has touched Entra.
What the host needs
Section titled “What the host needs”Docker with Compose, and the repository. That is the list. The containers are Linux containers: on Windows Server they run in a Linux VM or in WSL 2, as Running on Windows Server describes.
The build is multi-stage and self-contained: the .NET SDK and Node come from the build images, so the host needs no SDK and no npm. Leave room for three containers — the API and the worker are each capped at 1 GB of memory, and PostgreSQL shares the host with them.
The seven variables
Section titled “The seven variables”.env.example ships with seven lines uncommented for this stack. Two of them are :? in
compose.yaml, which means Compose stops before it creates a container rather than starting one
half-configured. Four are refused by the API itself, a few seconds later. One falls back, and says so.
| Variable | What it is | Unset |
|---|---|---|
POSTGRES_PASSWORD | The database password: its owner’s, a superuser’s | Compose refuses, naming the variable |
CONTACTMESH_DB_APP_PASSWORD | The password of the role the API and the worker log in as | They log in as the owner instead, and warn |
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 API refuses to start; it also refuses a placeholder and a key under 128 bits |
CONTACTMESH_AUTH_MODE | How somebody signs in: Password or EntraId | Compose refuses |
PUBLIC_ORIGIN | The address the dashboard is opened at | The API refuses to start |
CONTACTMESH_ADMIN_USERNAME | The first administrator’s name, in Password mode | The API refuses to start |
CONTACTMESH_ADMIN_PASSWORD | Their first password, in Password mode | The API refuses to start |
POSTGRES_PASSWORD — openssl rand -base64 36. PostgreSQL needs it before any row exists, which
is why it is here and not in the database like everything else.
CONTACTMESH_DB_APP_PASSWORD — openssl rand -hex 32. The API and the worker log in with it as
contactmesh_app, a role that reads and writes ContactMesh’s data and can change nothing else, so the
superuser’s password stays with PostgreSQL and the step that creates the tables. That step, migrate,
creates the role and sets this password at every start. Left empty, the two log in as the superuser, as
releases before 1.9.0 did, and Help & support marks Database role.
CHECKPOINT_PROTECTION_KEY — openssl rand -hex 32. It is the key to everything else: each
tenant’s Graph credential is held encrypted in the database with it, which is what makes adding
the fifth tenant a form rather than a file edit and a restart, and so is each database source’s
password. The API refuses to start if it is still one of the placeholder values published in this
repository, because a key printed here protects nothing: anybody with a copy of the database and of
this repository could read every credential back. For the same reason, saving a credential or a
database password is refused while the key is unset or a placeholder, and nothing is stored.
It also has to carry at least 128 bits. ContactMesh reckons a key’s bits from its length and the
characters it uses: 4 a character for hexadecimal, about 6.6 for a mix of letters, digits and signs,
less for lowercase letters or digits alone, and nothing for a key that keeps repeating itself. So 32
hexadecimal characters are the least that pass, and the 64 openssl rand -hex 32 makes pass twice
over. What the reckoning cannot see is a sentence: words with dashes between them pass by their length
and carry a fraction of it, so make the key with the command rather than by hand.
To keep the key out of .env, leave CHECKPOINT_PROTECTION_KEY empty and set
CHECKPOINT_PROTECTION_KEY_FILE to a file holding it, such as a Docker secret. The file is mounted
read-only into both containers, wins when it holds a key, and has to be readable by the containers’
user, uid 1654: sudo chown 1654 secrets/protection-key && sudo chmod 400 secrets/protection-key.
CONTACTMESH_AUTH_MODE — Password needs nothing at all from Microsoft and seeds one
administrator. EntraId needs the dashboard app registration and four more variables, and is
described in Microsoft 365 setup. This page uses Password. There is a
third value, None, for an isolated demo with no sign-in, and the API refuses to start with it against
a real tenant: an open API there serves every contact, every recipient and every tenant control to
anything that can reach the port.
PUBLIC_ORIGIN — the https address of the reverse proxy in front of the dashboard, such as
https://contactmesh.example.com. It makes the session cookie one a browser sends over HTTPS only and
to this host alone, tells browsers to use HTTPS from then on, and is the address a change in the
dashboard has to come from. Plain HTTP is accepted on this host’s loopback only: for a first start
before the proxy exists, http://localhost:5080 works, and the value changes to the https address
once the proxy is in place.
CONTACTMESH_ADMIN_USERNAME — a name of your choosing, such as your own. There is no default:
admin was one, and a name everybody knows is the one a guesser aims the sign-in lock at. admin,
administrator, root and the like are refused.
CONTACTMESH_ADMIN_PASSWORD — at least fifteen characters, and not one an attacker would try early,
such as a well-known password or a word with a year. There is no default and none is invented:
a self-hosted tool with a guessable first account is worse than one that will not start.
.env.example leaves a seventh line uncommented, MICROSOFT365_USE_FAKE_GRAPH. This stack ignores it —
compose.yaml pins Graph to the real thing. Only the development stack reads it.
Start to finish
Section titled “Start to finish”-
Get the repository.
Terminal window git clone https://git.kruede.com/lukas/ContactMesh.gitcd ContactMesh -
Make the environment file.
Terminal window cp .env.example .envchmod 600 .envopenssl rand -base64 36 # POSTGRES_PASSWORDopenssl rand -hex 32 # CONTACTMESH_DB_APP_PASSWORDopenssl rand -hex 32 # CHECKPOINT_PROTECTION_KEYFill in the seven values. Compose reads
.envfrom the repository root by itself, so there is no file to point at on the command line.Put each value on its own line and leave the comments above it. Compose strips an inline comment only when a real value comes first, so
POSTGRES_PASSWORD= # hintsets the password to the hint text — and because that text is not empty, the guard that exists to refuse a half-configuration is satisfied by it. -
Start it.
Terminal window docker compose up -d --build--buildbuilds both images from this working tree, which is what a first install needs. LeaveCONTACTMESH_API_IMAGEandCONTACTMESH_WORKER_IMAGEunset and they default to:local, which is what the build produces. Expect a few minutes the first time and seconds afterwards.Built this way, the images call themselves
1.0.0-devand name no commit.scripts/build-images.shis the same build with its version and commit named, which Help & support then shows: run it, thendocker compose up -dwithout--build. Upgrading has the published images. -
Wait for all three to read healthy.
Terminal window docker compose psThe API runs its database migrations before it starts listening, so nothing answers HTTP while it does. Its health check allows five minutes for that before calling the container unhealthy.
-
Confirm which Graph it is talking to.
Terminal window docker compose logs api | grep 'Graph mode'It must say
Graph mode: Microsoft 365.Demo (in-memory)is the development stack, and nothing it shows you is real. -
Open http://localhost:5080, or the address
PUBLIC_ORIGINnames once a proxy is in front.The API serves the dashboard, the HTTP API and this documentation on that one port.
-
Sign in with the name in
CONTACTMESH_ADMIN_USERNAMEand the password inCONTACTMESH_ADMIN_PASSWORD. -
Choose a new password. The dashboard does not appear yet: the seeded account is created owing a password change, and the change screen replaces everything until it is done. Give the current password again, then the new one twice, and Set password.
The dashboard that follows is empty, and correctly so — no tenant has been added yet. That is the next page.
The three containers
Section titled “The three containers”| What it is | Published | |
|---|---|---|
postgres | PostgreSQL 17, built with ICU (the image is; names sort by language rules with it). All of the state: configuration, mappings, the work queue, the audit trail | Nothing |
api | The HTTP API, the dashboard, and this documentation at /docs | 127.0.0.1:5080 |
worker | The loops that read the source, write to mailboxes, and verify what was written | Nothing |
A fourth, migrate, runs before the API and the worker at every start and then exits: it brings the
database up to date and keeps the role the two log in as. docker compose ps -a lists it as exited (0),
which is what it should say. The API and the worker are the same build against the same database, and
start once it has finished.
PostgreSQL is published on no host interface at all — not even loopback. Nothing outside the Compose
project can reach it, and docker compose exec postgres is how you get a psql.
The dashboard port is CONTACTMESH_PORT, and CONTACTMESH_BIND decides which host interface it is
published on. The default is 127.0.0.1, so reaching it from another machine is a deliberate act: an
SSH tunnel, or a reverse proxy in front. Set CONTACTMESH_BIND in .env rather than editing
compose.yaml — that file is tracked, and an edited port line becomes a merge conflict on the next
git pull, on the one line that decides who can reach the dashboard.
The first administrator
Section titled “The first administrator”The account is created once, on the first start, from CONTACTMESH_ADMIN_USERNAME and
CONTACTMESH_ADMIN_PASSWORD. It is an Admin, and it is created owing a password change.
That change asks for the current password as well as the new one. Re-verifying is deliberate: a stolen session cannot silently take over the account. Setting the password also ends every other session this account holds.
Seeding never runs again. Once any account exists the variable is ignored, so changing
CONTACTMESH_ADMIN_PASSWORD in .env later does nothing — change the password in the dashboard, and
add further accounts on the Accounts tab of Access, which the navigation offers wherever people sign in.
Five failed sign-in attempts lock the account for fifteen minutes, except in a browser it has signed in
from before, and the log says so. A wrong username and a wrong password give the same message, so
accounts cannot be enumerated. If the only administrator cannot get in at all,
docker compose run --rm api reset-access <username> on the host gives the account back; see
Accounts and roles.
When a container does not come up
Section titled “When a container does not come up”Two commands answer almost all of it:
docker compose psdocker compose logs apiThe refusals are deliberate and each one names itself.
| What you see | What it means | What to do |
|---|---|---|
Nothing starts; Compose names a variable and repeats a hint such as Set POSTGRES_PASSWORD in .env — openssl rand -base64 36 | One of the two :? variables is unset | Set it in .env |
Security:ProtectionKey (CHECKPOINT_PROTECTION_KEY, or the file CHECKPOINT_PROTECTION_KEY_FILE) is not set | Neither the key nor its file holds one | openssl rand -hex 32 into CHECKPOINT_PROTECTION_KEY |
Security:ProtectionKey (CHECKPOINT_PROTECTION_KEY) is still one of the placeholder values published in the ContactMesh repository | The key came from an example | A new key, with the old one in CHECKPOINT_PROTECTION_PREVIOUS_KEYS so what it sealed still opens |
Security:ProtectionKey (CHECKPOINT_PROTECTION_KEY) is too weak to protect stored credentials | The key carries fewer than 128 bits | A new key from openssl rand -hex 32, with the old one in CHECKPOINT_PROTECTION_PREVIOUS_KEYS; remove it once Settings › Security counts nothing under it |
Configured secret file '…' does not exist | A key file is named and not mounted | The path in CHECKPOINT_PROTECTION_KEY_FILE |
PUBLIC_ORIGIN is required for a deployment that reaches a real Microsoft 365 tenant | PUBLIC_ORIGIN is unset | The address the dashboard is opened at |
PUBLIC_ORIGIN '…' is plain HTTP on a host other than this one | An http:// address that is not loopback | The proxy’s https:// address |
Authentication:Mode is Password but no account exists yet | Password mode, no first administrator’s name or password, and no account in the database | Set CONTACTMESH_ADMIN_USERNAME and CONTACTMESH_ADMIN_PASSWORD |
Authentication__Seed__Username '…' is a name anybody would try first | admin, administrator, root or the like | Another name, such as your own |
Authentication__Seed__Password is not acceptable | Shorter than the minimum of fifteen characters, or one an attacker would try early | A longer password, such as several unrelated words |
Authentication:Mode is None while this deployment is configured for a real Microsoft 365 tenant | CONTACTMESH_AUTH_MODE=None | Password or EntraId |
api unhealthy for the first few minutes | Migrations run before it listens | Wait. The check allows 300 seconds |
| Compose reports the port already allocated | Something else holds 5080 | Set CONTACTMESH_PORT |
worker unhealthy while the process is still running | Its loop stopped turning | docker compose logs worker |
The worker’s health check is not a process check. It has no HTTP surface and its real heartbeat lives in PostgreSQL, which a check running inside that container cannot reach — so the loop touches a file every thirty seconds and the check reads the file’s age. It answers “is the loop turning”, which is the failure that otherwise looks identical to a busy worker.
To start over, docker compose down -v removes the database volume with the containers. The next
start migrates a fresh schema and seeds the administrator again.
The Microsoft side
Section titled “The Microsoft side”Everything above runs without a tenant, and does nothing useful without one. Next is the app registration, the two Exchange RBAC scopes that keep its reach narrow, and the credential.