Skip to content

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.

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.

.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.

VariableWhat it isUnset
POSTGRES_PASSWORDThe database password: its owner’s, a superuser’sCompose refuses, naming the variable
CONTACTMESH_DB_APP_PASSWORDThe password of the role the API and the worker log in asThey log in as the owner instead, and warn
CHECKPOINT_PROTECTION_KEYSeals every tenant’s Graph credential, every database source’s password, every delta checkpoint and the keys that sign the session cookiesThe API refuses to start; it also refuses a placeholder and a key under 128 bits
CONTACTMESH_AUTH_MODEHow somebody signs in: Password or EntraIdCompose refuses
PUBLIC_ORIGINThe address the dashboard is opened atThe API refuses to start
CONTACTMESH_ADMIN_USERNAMEThe first administrator’s name, in Password modeThe API refuses to start
CONTACTMESH_ADMIN_PASSWORDTheir first password, in Password modeThe 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.

  1. Get the repository.

    Terminal window
    git clone https://git.kruede.com/lukas/ContactMesh.git
    cd ContactMesh
  2. Make the environment file.

    Terminal window
    cp .env.example .env
    chmod 600 .env
    openssl rand -base64 36 # POSTGRES_PASSWORD
    openssl rand -hex 32 # CONTACTMESH_DB_APP_PASSWORD
    openssl rand -hex 32 # CHECKPOINT_PROTECTION_KEY

    Fill in the seven values. Compose reads .env from 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= # hint sets 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.

  3. Start it.

    Terminal window
    docker compose up -d --build

    --build builds both images from this working tree, which is what a first install needs. Leave CONTACTMESH_API_IMAGE and CONTACTMESH_WORKER_IMAGE unset 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-dev and name no commit. scripts/build-images.sh is the same build with its version and commit named, which Help & support then shows: run it, then docker compose up -d without --build. Upgrading has the published images.

  4. Wait for all three to read healthy.

    Terminal window
    docker compose ps

    The 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.

  5. 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.

  6. Open http://localhost:5080, or the address PUBLIC_ORIGIN names once a proxy is in front.

    The API serves the dashboard, the HTTP API and this documentation on that one port.

  7. Sign in with the name in CONTACTMESH_ADMIN_USERNAME and the password in CONTACTMESH_ADMIN_PASSWORD.

  8. 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.

What it isPublished
postgresPostgreSQL 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 trailNothing
apiThe HTTP API, the dashboard, and this documentation at /docs127.0.0.1:5080
workerThe loops that read the source, write to mailboxes, and verify what was writtenNothing

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 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.

Two commands answer almost all of it:

Terminal window
docker compose ps
docker compose logs api

The refusals are deliberate and each one names itself.

What you seeWhat it meansWhat to do
Nothing starts; Compose names a variable and repeats a hint such as Set POSTGRES_PASSWORD in .env — openssl rand -base64 36One of the two :? variables is unsetSet it in .env
Security:ProtectionKey (CHECKPOINT_PROTECTION_KEY, or the file CHECKPOINT_PROTECTION_KEY_FILE) is not setNeither the key nor its file holds oneopenssl rand -hex 32 into CHECKPOINT_PROTECTION_KEY
Security:ProtectionKey (CHECKPOINT_PROTECTION_KEY) is still one of the placeholder values published in the ContactMesh repositoryThe key came from an exampleA 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 credentialsThe key carries fewer than 128 bitsA 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 existA key file is named and not mountedThe path in CHECKPOINT_PROTECTION_KEY_FILE
PUBLIC_ORIGIN is required for a deployment that reaches a real Microsoft 365 tenantPUBLIC_ORIGIN is unsetThe address the dashboard is opened at
PUBLIC_ORIGIN '…' is plain HTTP on a host other than this oneAn http:// address that is not loopbackThe proxy’s https:// address
Authentication:Mode is Password but no account exists yetPassword mode, no first administrator’s name or password, and no account in the databaseSet CONTACTMESH_ADMIN_USERNAME and CONTACTMESH_ADMIN_PASSWORD
Authentication__Seed__Username '…' is a name anybody would try firstadmin, administrator, root or the likeAnother name, such as your own
Authentication__Seed__Password is not acceptableShorter than the minimum of fifteen characters, or one an attacker would try earlyA longer password, such as several unrelated words
Authentication:Mode is None while this deployment is configured for a real Microsoft 365 tenantCONTACTMESH_AUTH_MODE=NonePassword or EntraId
api unhealthy for the first few minutesMigrations run before it listensWait. The check allows 300 seconds
Compose reports the port already allocatedSomething else holds 5080Set CONTACTMESH_PORT
worker unhealthy while the process is still runningIts loop stopped turningdocker 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.

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.