Running your own server
The reference server
cd server && node index.mjs # PORT=8787 HOST=127.0.0.1 by defaultThe server refuses to start without accounts: set TEAMS_USERS_FILE (see below), or pass --insecure-dev for local development only.
| Variable | Meaning |
|---|---|
PORT, HOST | Listen address. Bind 0.0.0.0 only behind TLS. |
TEAMS_TOKEN | If set, sockets take it in the Sec-WebSocket-Protocol header (?token= only as a fallback) and file requests as Authorization: Bearer. |
TEAMS_ORIGINS | Comma-separated allowed Origins for sockets and files. Empty: any origin when a token is set; without a token only loopback origins and clients that send no Origin. |
TEAMS_DATA | Data directory (default ./data): rooms/=<name>.bin snapshots and files/. |
TEAMS_USERS_FILE, TEAMS_SESSION_SECRET | Path to a JSON object of user id to credential, or { credential, role } (enables accounts); the secret that signs sessions, at least 32 characters (openssl rand -hex 32), or unset for a random one per process. |
TEAMS_ENFORCE_AUTHORSHIP | 0 turns off the authorship checks for signed-in users (default on). |
TEAMS_MAX_MESSAGE_CHARS, TEAMS_MAX_REACTIONS_PER_MESSAGE | Longest message text (default 32768) and most reactions on one message (200) the authorship check accepts. |
TEAMS_ADMIN_TOKEN | Enables POST /auth/revoke. |
TEAMS_AUTH_RATE_WINDOW_MS, TEAMS_AUTH_RATE_PER_IP, TEAMS_AUTH_RATE_PER_USER | The /auth/session rate limit: window in ms (default 60000), attempts per address (30) and per user id (10); over it, 429 with Retry-After. |
TEAMS_TRUST_PROXY, --trust-proxy[=N] | Key the auth rate limiter and per-address connection cap on X-Forwarded-For (the Nth trusted proxy's entry, default 1). Off by default; enable only behind a proxy that sets the header, or clients can forge it. |
--insecure-dev | Start with no accounts and no authenticate hook (option insecureDev). Without it the server refuses to start unless TEAMS_USERS_FILE is set. Development only. |
TEAMS_INSECURE | 1 (or --insecure) allows a non-loopback HOST with no token. Otherwise the server refuses to start. |
TEAMS_MAX_CONNECTIONS, TEAMS_MAX_CONNECTIONS_PER_IP | Open sockets overall (default 500) and per remote address (20). |
TEAMS_MAX_ROOMS | Sync rooms and call rooms (default 1000 each). |
TEAMS_MAX_DOC_MB | Largest persisted room document in MB (default 64); updates past it are rejected. |
TEAMS_MAX_UPDATE_STRUCTS | Most structs one update may hold, counted before it is decoded (default one per 4 bytes of the update); a socket sending more is closed. |
TEAMS_MESSAGE_RATE, TEAMS_MESSAGE_BURST | Messages per second (default 100) and burst (200) for each socket; a socket over it is closed. |
TEAMS_USER_QUOTA_MB | Files one person uploads, in MB, across every workspace and chat (default 1024); uploads past it get 507. |
TEAMS_FILES_QUOTA_MB | Ceiling on the whole files directory in MB (default 20480); uploads past it get 507. |
TEAMS_ROOMS_QUOTA_MB, TEAMS_MAX_STORED_ROOMS | Ceiling on all stored rooms in MB (default 10240) and on their number (10000); updates past them are refused. |
TEAMS_MAX_AWARENESS_KB, TEAMS_MAX_ROOM_AWARENESS_KB | Largest presence state of one client (default 64) and all presence in one room (4096), in KB; a socket going past them is closed. |
TEAMS_AWARENESS_RATE_KB, TEAMS_MAX_REFUSALS_PER_MIN | Presence KB per second per socket (default 256); refusals that cost the server a room read or a check, per client per minute (30), after which it gets 429 for the rest of the minute. |
TEAMS_WORKSPACE_QUOTA_MB | Files per workspace in MB (default 1024; a private chat counts for its workspace); uploads past it get 507. |
TEAMS_COMPACT_INTERVAL_MIN | Minutes between room snapshot compactions (default 360, 0 turns the timer off). A room is also compacted when it loads. |
TEAMS_METRICS_TOKEN | Turns on GET /metrics (Prometheus text), served only to Authorization: Bearer <this token>. Off without it. |
TEAMS_LOG_FORMAT, --log-format=json | text (default) or json: one JSON object per line with time, level and msg. |
It serves ws /sync/<room> (y-websocket compatible, one persisted Y.Doc per room), ws /signal/<room> (a JSON relay) and POST|GET /files/<workspace>/<name> (25 MB cap, names sanitised, downloads sent as attachments with Referrer-Policy: no-referrer). With a token, a browser opens files through POST /files/link/<workspace>/<name> (token in the header), which returns a link signed for that one file and valid for five minutes. GET /health reports room and call counts.
Put it behind TLS. Browsers refuse ws:// from an https:// page, and a token or call signaling over plain HTTP is readable on the network. Any reverse proxy that upgrades WebSockets works (nginx, Caddy, Traefik). Caddy example:
teams.example.com {
reverse_proxy 127.0.0.1:8787
}Then point the app at wss://teams.example.com/sync and wss://teams.example.com/signal.
The token is a shared secret stored in the browser: it keeps strangers out of a small team's server, it is not per-user authentication. For real accounts, give the server users (or TEAMS_USERS_FILE) or an authenticate function for your identity provider, and set TEAMS_SESSION_SECRET so sessions survive restarts; see "Accounts and sessions" in the server's README. Keep the same three contracts.
Security model
- One shared token opens every room and every file. Per-user identity exists only when you enable accounts, and per-room permissions only when you pass
authorizeSync. Treat the token like a team password. - All members of a room trust each other. The server only moves Yjs bytes, so any member can edit or delete other people's messages and forge author ids and roles. Do not invite people you would not trust with the whole room.
- The token and session travel in the
Sec-WebSocket-Protocolheader (openteams.session.<session>,openteams.token.<token>, next to a bareopenteams), which stays out of URLs and logs. The shipped client falls back to the query string only for a credential a subprotocol cannot carry. Run the server behind TLS. Files never take the token in a URL: they use theAuthorizationheader or a signed link. - Authorship is enforced for signed-in users: nobody can post as, edit or delete another person's messages, or change channels and tabs they did not create, unless the account has
"role": "moderator"in the users file.TEAMS_ENFORCE_AUTHORSHIP=0turns it off. - Secure by default. Without accounts, an
authenticatehook orauthorizeSyncthe server refuses to start;--insecure-devis the explicit, warned opt-out. A shared token alone is not authentication. With onlyauthorizeSync, nobody can sign in, so the server offers sync alone: sessions, files and call signaling answer 404. - Calls are bound to accounts. With accounts a call socket speaks only as its signed-in user, and a private chat's call admits only that chat's members.
- Sessions end on time. An open socket is closed when its session expires, and the server refuses a session secret shorter than 32 characters.
- Defaults are local. Without a token the server refuses a non-loopback
HOST(unlessTEAMS_INSECURE=1) and accepts only loopback origins, so a website you visit cannot drive a server on your own machine. SetTEAMS_TOKENandTEAMS_ORIGINSfor any shared deployment. - Use short-lived TURN credentials (see below); static ones are visible to everyone who opens the app.
- Limits on connections, rooms, document size, message rate and file storage (the variables above) bound abuse, but they do not replace a reverse proxy's own rate limiting.
- A socket can only speak for the awareness ids and the call peer id it announced itself, and an addressed call signal is delivered to that peer only. An upload never overwrites a file: a name already taken is stored under a new one, returned in the response
url.
Calls across NATs: TURN
Calls are peer to peer. Public STUN works on open networks; behind symmetric NAT or strict firewalls you need a TURN relay, which also carries media only as ciphertext (DTLS-SRTP). A minimal coturn (turnserver.conf):
listening-port=3478
tls-listening-port=5349
realm=turn.example.com
fingerprint
lt-cred-mech
user=teams:CHANGE_ME
no-multicast-peers
cert=/etc/letsencrypt/live/turn.example.com/fullchain.pem
pkey=/etc/letsencrypt/live/turn.example.com/privkey.pemand in the app's server settings, one ICE server per line:
stun:turn.example.com:3478
turn:turn.example.com:3478,turns:turn.example.com:5349 teams CHANGE_MEStatic TURN credentials are visible to anyone who can open the app. For anything public, issue short-lived credentials (coturn use-auth-secret plus a small endpoint that signs them) and pass them in the iceServers you give the element.
Docker
FROM node:22-alpine
WORKDIR /app
COPY server/package.json ./
RUN npm install --omit=dev
COPY server/bin.mjs server/index.mjs server/auth.mjs server/passwords.mjs server/guards.mjs server/rate-limit.mjs server/chat-access.mjs server/validator.generated.mjs server/files.mjs server/metrics.mjs server/room-store.mjs ./
ENV HOST=0.0.0.0 TEAMS_DATA=/data TEAMS_USERS_FILE=/config/users.json
RUN mkdir /data && chown node:node /data
VOLUME /data
EXPOSE 8787
USER node
CMD ["node", "bin.mjs"]Build it from viewers/teams (docker build -t openteams-server . with the file saved there). It copies every module the entry point imports (they are the files of server/package.json; copying only index.mjs fails with a missing module) and installs the four runtime dependencies. The server needs no other file: the data directory is created under TEAMS_DATA, and an accounts file, if you use one, is mounted and named by TEAMS_USERS_FILE. Add server/hash-password.mjs if you want openteams-hash-password inside the image. The recipe was checked by running those files with npm install --omit=dev on Node, not by building the image.
Run it with an accounts file mounted and TEAMS_SESSION_SECRET and TEAMS_ORIGINS set, behind your TLS proxy. Make the secret once with openssl rand -hex 32 > session-secret and keep it; the server refuses a secret shorter than 32 characters.
docker run -d --name openteams -p 127.0.0.1:8787:8787 \
-v openteams-data:/data -v "$PWD/users.json:/config/users.json:ro" \
-e TEAMS_SESSION_SECRET="$(cat session-secret)" -e TEAMS_ORIGINS=https://app.example.com \
openteams-serverWithout the mounted accounts file the container exits with the "refusing to start" message; do not add --insecure-dev to a container that is reachable from a network. Add --trust-proxy to the command (CMD ["node", "bin.mjs", "--trust-proxy"]) only if a reverse proxy sets X-Forwarded-For. docker stop sends SIGTERM, which the server answers by saving every room first (Docker waits ten seconds by default, which is ample). The image creates /data owned by node; with a bind mount, chown the host directory to uid 1000.
Operations
Backup and restore
Everything the server keeps is under TEAMS_DATA (default ./data):
| Path | Holds |
|---|---|
rooms/=<name>.bin | One Yjs snapshot per room: all chat, channels, calendars and tab data. |
rooms/=<name>.members.json | A private chat room's member list, kept with its snapshot so refusals need not read the room; rebuilt from the snapshot when missing. |
files/=<name>/ | Uploaded files. |
file-meta/=<name>.json | Who uploaded each file (decides who may delete it). Back it up with files/. |
session-revocations.json | Session revocation generations (lose it and revoked sessions revive until they expire). |
A stored name is = followed by the lower-case base32 of the exact room or scope name, so names that differ only by case stay apart on every disk. On its first start a 2.0 server renames what an older version stored; back up first, because an older server cannot read the new names. An entry named after a chat id that only 2.0 issues (dm- and 32 hex digits, or a new g- id, in any spelling) is not migrated: it moves to a .quarantine folder beside it and is logged, and the server never reads it.
Also keep what is not in the data directory: your accounts file (TEAMS_USERS_FILE) and TEAMS_SESSION_SECRET. Changing or losing the secret signs everyone out, which is harmless.
To back up, copy the whole data directory. Room snapshots are written to a temporary file and renamed, so a copy never sees a half-written snapshot; a copy taken while the server runs may miss changes from the last half second (writes are debounced by 500 ms) and may capture a file that is newer than its room's neighbours. For a consistent copy, stop the server first (SIGTERM flushes every room before exit), copy, and start it again; or snapshot the volume at the filesystem level.
To restore, stop the server, replace the data directory with the backup (keeping rooms/, files/ and session-revocations.json together), restore the accounts file and secret, and start it. Clients that were connected reconnect and merge: Yjs keeps whatever they hold that the backup lacks, so a restore does not discard work still open in a browser.
Files, compaction and metrics
- File permissions. A file lives under a scope: the workspace id for channel files (any signed-in user of the server) or a private chat's room name (
chat-<hash>-<chat id>), which only that chat's members may list, read, upload to or link. The server checks the chat's member list the same way it does for the chat's sync room. With accounts, every file request must carry the signed session inX-Teams-Session(the client does this); a signed download link is issued only after that check and opens its one file for five minutes. With--insecure-devthe claimedX-Teams-Userstands in, like every claim there. Channel files are not restricted per channel: all users of the server can read them. - Listing and deleting.
GET /files/<scope>answers{ files: [{ name, size, modified, uploader }] }.DELETE /files/<scope>/<name>is allowed to the uploader or a moderator (204, else403). Files uploaded before this version have no recorded uploader, so only a moderator can delete them. - Cleanup. An upload streams to a hidden
.partfile that a failed or aborted upload removes. At start-up the server deletes every leftover.partfile (and stale room temp files), and every 15 minutes any older than an hour. Files that were uploaded but never attached to a message stay until someone deletes them. - Quotas. The limit is per workspace (
TEAMS_WORKSPACE_QUOTA_MB, default 1024), counting the workspace's channel files and its private chats' files, per uploader across every workspace and chat (TEAMS_USER_QUOTA_MB, default 1024) and for the whole directory (TEAMS_FILES_QUOTA_MB, default 20480); deleting frees the space. With accounts, uploads go only to a workspace that exists or to a private chat, so new names add no space. Stored rooms have their own ceilings (TEAMS_ROOMS_QUOTA_MB,TEAMS_MAX_STORED_ROOMS), and a room nobody wrote to is not stored. - Compaction. When a room loads, and every
TEAMS_COMPACT_INTERVAL_MINminutes for every room, the server re-encodes the room as a single Yjs update on a fresh document and writes it only if it is smaller and describes exactly the same state. The write goes to a temporary file, is flushed to disk and renamed over the snapshot, so a crash leaves the old or the new snapshot, never a torn one; interrupted temp files are removed at start-up. Backups made before or after a compaction both restore. - Metrics. Set
TEAMS_METRICS_TOKENand scrapeGET /metricswithAuthorization: Bearer <token>:teams_rooms_open,teams_connections{kind},teams_stored_bytes{kind="rooms|files"},teams_updates_rejected_total{code},teams_auth_failures_total{kind},teams_rate_limited_total{scope}andteams_room_compactions_total. Without the token the endpoint answers 404. Keep it off the public internet like any admin endpoint. - Logs.
--log-format=json(orTEAMS_LOG_FORMAT=json) writes one JSON object per line:{ "time", "level", "msg" }.
Upgrading
- Read the server's
CHANGELOG.mdfor the version range you cross; breaking changes are marked. - Back up the data directory.
- Stop the server (
SIGTERM), install the new version (npx openteams-server@<version>, or rebuild the image), and start it. Room snapshots are plain Yjs updates and older ones are read as they are. - Check
GET /health, then open a room.
Upgrading from a version before the secure default: a server that started without accounts now refuses to. Add accounts (TEAMS_USERS_FILE), an authenticate hook or authorizeSync, or pass --insecure-dev if (and only if) it is a local development server. A shared TEAMS_TOKEN on its own no longer starts the server.
Production hardening checklist
Using a different server
Anything that honours the contracts in the core's docs/teams-area.md works: a stock y-websocket server for sync, any WebSocket fan-out for signaling, any object store for files (give <teams-app> an uploadFile function, or set uploadFile on the element, and attachments go there instead).