High availability¶
LiMDM runs as several identical server instances behind a load balancer, all connected to one PostgreSQL database. Any instance answers any request; no sticky sessions are needed. PostgreSQL itself is made highly available with the usual tools (see PostgreSQL).
console (HTTPS, L7) agents (TCP 8444, passthrough)
│ │
┌────────┴──────── load balancer ───────────┴────────┐
│ │
┌───────┴───────┐ ┌───────────────┐ ┌─────────┴─────┐
│ limdm-server 1│ │ limdm-server 2│ ... │ limdm-server n│
└───────┬───────┘ └───────┬───────┘ └───────┬───────┘
└──────────── PostgreSQL primary (+ standby) ──────┘
shared CA directory (read mostly)
Requirements¶
- Every instance runs the same version (except during a rolling upgrade) with
the same environment:
LIMDM_DATABASE_URL,LIMDM_SESSION_KEY,LIMDM_PUBLIC_URL,LIMDM_AGENT_URL, OIDC and syslog settings. Different session keys make sessions and sealed secrets unreadable on the other instances. - The same CA directory (
LIMDM_CA_DIR) on every instance. It holds the device CA, the network CA, the command key (command and item signatures, audit chain key),keys.json(active and retiring key names),audit-keys(audit key segments of earlier command keys) and theaudit-keyed-fromswitch point. Two ways, both supported: - a shared volume (NFS, CephFS, a cluster file system), mounted on every instance with
mode 0700 for the
limdmuser; the files are written at the first start and by key rotations, and only read otherwise, or - start the first instance once, then copy the directory (
rsync -a, encrypted channel) to the others before starting them.
The first instance records the fingerprints of both CAs and the command key in the
database. An instance with different key material refuses to start ("differs from the
one the other server instances use"), and so does an instance whose directory lacks
audit-keyed-from after the audit chain switched to keyed hashes. Concurrent first
starts are serialized by an advisory lock, so only one instance creates keys.
A key rotation (Keys and HSM) updates the recorded fingerprints at rotate and
finish: during the overlap an instance with the old or the new directory starts; after
finish only the updated directory does, so copy it to every instance before restarting.
* LIMDM_RELEASE_DIR stays local: every instance downloads and verifies the agent packages
of the five newest releases itself and serves them from its own directory. For older
versions still pinned to devices, copy the directory from an existing instance.
* The console port of each instance has TLS (LIMDM_TLS_CERT) or a local reverse proxy;
without a certificate the console listens on loopback only.
What the instances share¶
| State | How |
|---|---|
| Devices, configuration, audit log, approvals, exceptions, sessions of local accounts, lockout counters | PostgreSQL |
| Console sessions, OIDC state, nonce and PKCE verifier | sealed cookies (LIMDM_SESSION_KEY), valid on every instance |
| Desktop login (device code flow) | runs between the device and the identity provider; the server only hands out the configuration |
| Console settings | stored in PostgreSQL; a trigger sends NOTIFY limdm_settings, every instance reloads within milliseconds. Saves are serialized across instances (advisory lock) and load a newer change first, so two admins saving on different instances do not undo each other |
| Audit chain | appends take the advisory lock 7363, so ids and hashes stay in order with any number of instances. A check in appends its entries (command results, tamper events, escrow, compliance actions) at its commit, so the lock is held for the append only and check ins of different devices run in parallel; no transaction takes a second pool connection while it holds the lock |
| Result of the last full audit verification | PostgreSQL (settings key audit_verification), shown on the audit page and in /metrics of every instance |
| SCIM read, modify and write | advisory lock across instances |
| Remote shell | relayed between instances, see below |
| Background jobs | leader election per job, see below |
| Rate limits (sign in, enrollment, API tokens, SCIM, CRL, device endpoints), the cap on audited OIDC failures | per instance, in memory. With n instances an address gets up to n times the budget. Accepted: the lockout of local accounts (5 failures, 15 minutes) is stored in the database and counts across instances, API and SCIM tokens are 256 bit random values. Counters expire an hour after their last hit; beyond 200,000 throughput keys (devices, tokens) the least recently used are dropped, failure counters (sign in, enrollment, token, SCIM, CRL) never before their window ends |
| Fleet overview cache, Flathub search cache, agent rollout (policy and approved releases for polls) | per instance, one minute, one hour and 30 seconds |
/metrics request counters |
per instance; scrape every instance (limdm_http_requests_total), the fleet gauges are the same on all |
Background jobs¶
Each periodic job runs on exactly one instance, the holder of its PostgreSQL advisory lock:
directory sync, history (fleet snapshot, full audit verification, audit and data retention,
expiry of approvals), catalog icons, syslog forwarding and sealing values again after a
session key rotation. The other instances try to take
over every 15 seconds. The leader checks its lock connection every 15 seconds; if it breaks
(database failover, network), the job stops before another instance can start it.
Notifications from these jobs (audit.broken) are therefore sent once. Notifications caused
by a request or a device check in are sent by the instance that handled it, also once.
Syslog forwarding stores its position in the table syslog_cursor. A new leader continues
after the last entry the previous one sent: no gaps, at most the last batch twice after a
crash. Device events that commit out of id order can still be skipped, as before.
Agent package downloads run on every instance (see LIMDM_RELEASE_DIR above), and so does
the retry of an OIDC discovery that failed at startup. Which instance leads which job is
logged ("leading background loop").
Remote shell¶
A session lives on the instance where the console user started it: watcher, timeouts and
transcript. The device (POST /api/v1/shell/<id>) and the console WebSocket may reach any
instance. An instance that does not hold the session finds its home instance in the table
shell_sessions (column instance, liveness in server_instances) and relays the stream
over PostgreSQL NOTIFY limdm_shell: output and input in chunks of 4 KiB, each direction
sent in order. No connection between the instances is needed, so there are no further
ports, certificates or trust relationships; the database connection (TLS,
sslmode=verify-full for remote hosts) carries the relay.
- Keystrokes and output pass through PostgreSQL's notification queue (memory, spilled to
pg_notifyfiles under load), not tables or the WAL. Transcripts are stored as before. - A relay that falls behind by more than 1024 messages (4 MiB) ends the session with "the relay between server instances fell behind".
- When the home instance stops, relayed legs notice within 15 seconds. A clean stop ends
the session and stores the transcript; after a crash the session shows as
interrupted.
Shutdown and leader handover¶
On SIGTERM an instance:
- stops its background jobs at once and releases their locks; another instance takes over within 15 seconds,
- answers
/readyzwith 503 forLIMDM_DRAIN_SECONDS(default 5), so the load balancer stops sending new requests, - ends the remote shells it holds or relays and stores them,
- closes the listeners and waits up to 15 seconds for running requests,
- removes itself from
server_instances.
Set LIMDM_DRAIN_SECONDS to at least the load balancer's health check interval times its
fall count, and systemd TimeoutStopSec (default 90 s) above LIMDM_DRAIN_SECONDS plus 30.
Upgrades¶
Schema changes apply at start inside one transaction under an advisory lock: instances that
start at the same time wait for each other, the first applies the schema, the others find
it current. The schema is applied only when it changed: each applied version is recorded by
its hash (schema_applied), and an instance whose schema is recorded already starts without
taking the advisory lock or any table lock. A rolling restart of the same version therefore
never queues ACCESS EXCLUSIVE lock requests in front of the running instances; only the first
instance of a new version takes them (bounded by a 30 s lock wait). Startup work on key material (signing existing items, sealing secrets) is
serialized the same way.
Rolling upgrade (default for releases whose notes do not say otherwise):
- Back up the database (Backup in short).
- Stop one instance (SIGTERM, it drains), upgrade the package or image, start it.
- Wait for
/readyz200 on it, then continue with the next instance.
The schema is additive within a release line, so older instances keep working while newer
ones run. server_instances.version shows which version each instance runs:
SELECT id, version, seen_at FROM server_instances.
Full stop is required when the release notes say so, at least for:
- 0.15 to 0.16: the audit chain switches to keyed hashes (HMAC) at the first start of
0.16. A 0.15 instance still running afterwards would append plain hashes behind the
switch point and break the chain. Stop all instances, start one 0.16 instance, wait for
/readyz, then distribute the CA directory (it now containsaudit-keyed-from) and start the others. The other changes of this upgrade: Upgrading from 0.15 to 0.16. - 0.16 to 0.17: 0.16 instances write device packages into
devices.packages, which 0.17 moved intodevice_packages(devices whose package list does not change are not sent again), and save device users and enroll devices without the user list signature (agents then get no user list until it is saved again). The first 0.17 start also partitionsdevice_metricsand moves the package lists while it holds the schema locks. Stop all instances, start one 0.17 instance, wait for/readyz, then start the others. - changes of
LIMDM_SESSION_KEY(sealed secrets would be unreadable on the other instances) and key rotations of the CA directory.