Cluster coordination
When several KMS nodes share one PostgreSQL or MySQL/MariaDB database (see High availability and deployment profiles), they coordinate through that database:
- each background job runs on one node at a time;
- each node publishes a heartbeat, so the cluster can list its live nodes;
GET /cluster/statusshows the live nodes andGET /healthreports the state of the database, of each HSM and of the KMIP socket server.
No configuration is needed: coordination starts as soon as two nodes use the same database.
How the nodes coordinate
The nodes never talk to each other: everything goes through the shared database.
Scheduled jobs
Each node runs the same background jobs on a timer. For the jobs that change shared data, a node first tries to take a database lock named after the job:
| Job | Lock name | Runs on |
|---|---|---|
| Key auto-rotation and renewal warnings | auto-rotation | one node at a time (leader region only, see Multi-region deployments) |
| CRL refresh | crl-refresh | one node at a time (leader region only) |
| Object counter reconciliation | metrics-reconcile | one node at a time |
Metrics gauges refresh (kms.keys.active.count, kms.objects.total) | none | every node (each node exports its own gauges) |
| KV secret TTL expiry | kv-ttl | one node at a time |
The lock prevents overlapping runs, not repeated ones: each node keeps its own timer, so over time every node runs each job, one after the other. This is harmless for jobs that find nothing to do the second time (rotation, CRL refresh, counter reconciliation, TTL expiry). Key-renewal warnings are de-duplicated in each node's memory, so with several nodes the same warning can be emitted once per node.
How the locks work:
- PostgreSQL uses a session-level advisory lock (
pg_try_advisory_lock); MySQL/MariaDB uses a named lock (GET_LOCKwith a zero timeout). Neither blocks: a node that does not get the lock skips the run. - The lock name includes the database name, so KMS deployments that use different databases on the same server do not block each other.
- If a node process stops during a job, its database connection closes and the database releases the lock. If the node's machine or network fails instead, the lock is released once the database detects the dead connection.
- Each node keeps a small dedicated pool of database connections for these locks, so a long job never delays the heartbeat.
Heartbeat and leader
Every 5 seconds, each node writes its row in the cluster_nodes
table: a node ID generated when the process starts, its KMS version, and the time of the heartbeat. Rows older than
15 seconds are deleted.
One node is marked as leader. The leader is for display only: no job and no request depends on it.
What to expect:
- A node stops: its row expires after 15 seconds and it disappears from
/cluster/status. If it was the leader, another node becomes leader at its next heartbeat, so about 15 to 20 seconds later. Client requests are not affected during this time. - A node restarts: it gets a new node ID, so it appears as a new node and does not take the leader role back from the current leader.
- Clocks: heartbeat times come from each node's own clock. Keep the node clocks synchronized (for example with NTP): a node whose clock is about 10 seconds or more behind the others can be shown as gone, or appear and disappear from the list. This only affects the status display.
Multi-region deployments
In a multi-region active-active deployment, each region has its own database, so the coordination above stays inside a region:
- a job lock excludes a job running in the same region only. Key auto-rotation and its renewal warnings therefore
run on the leader region (
region_role = "leader") only: a follower skips them, as it skips the CRL refresh; /cluster/statusandkms.cluster.nodesshow the nodes of the region that answers: thecluster_nodestable is not replicated between regions;- the leader-only features that are not locked jobs (CRL generation, Crypto Officer ceremonies) are listed with the jobs in Scheduled jobs and cluster coordination;
/healthis per region: check each region with its own load balancer.
Supported databases
| Database | Job locks | Heartbeat and /cluster/status |
|---|---|---|
| PostgreSQL | yes | yes |
| MySQL / MariaDB | yes | yes |
Galera: Percona XtraDB Cluster (default pxc_strict_mode=ENFORCING), MariaDB Galera | yes: the server refuses GET_LOCK, so the job lock is a replicated TTL lease in kms_cron_leases, which excludes the KMS nodes of every Galera node | yes |
| SQLite | not needed (single node) | yes, shows one node |
| Redis with Findex (non-FIPS only) | no: every node runs every job | no: /cluster/status returns an empty node list |
When the database refuses GET_LOCK (Percona XtraDB Cluster strict mode, MariaDB Galera), the server logs one
message and takes a lease on a row of the kms_cron_leases table instead. The lease is committed, so Galera
replicates it: each job runs once across the whole cluster, whichever database node the KMS nodes use.
- The lease lasts 300 seconds and the running job renews it every 100 seconds. A node that dies mid-job loses the lease after at most 300 seconds, then another node takes the job over. A job cancelled by a shutdown keeps its lease until it expires.
- Expiry uses the clock of the database node that runs each statement: keep the Galera nodes' clocks synchronised (NTP). A skew larger than the 100-second renewal margin can let a second node take over a running job.
- During a rolling upgrade from a release before 6.0, nodes of different versions do not exclude each other (the
older ones still use
kms_cron_locks): the coordination is degraded until every node runs 6.0.
Monitoring
GET /health
This endpoint is public (no authentication), so a load balancer can use it as a health check. It reports a global status and the state and latency of each dependency:
| Global status | HTTP code | Meaning |
|---|---|---|
UP | 200 | The database, every configured HSM and the KMIP socket server (when enabled) are fine. |
DEGRADED | 200, or 503 with ?strict=true | The database answers, but at least one HSM does not, or the KMIP socket server has stopped. |
DOWN | 503 | The database check fails, or does not answer within 2 seconds. |
Example response from a node with one HSM and the KMIP socket server enabled:
{"status":"UP","latency_ms":3,"dependencies":{"database":{"name":"postgres","status":"UP","latency_ms":2},"hsm":[{"name":"hsm","status":"UP","latency_ms":0}],"kmip":{"name":"kmip","status":"UP","latency_ms":0}}}
By default a DEGRADED node answers 200, so with the HAProxy configuration of the
HAProxy and Keepalived page (http-check expect status 200) it stays in the load-balancing
pool and keeps serving the requests that do not use the failing HSM. To take such a node out of the pool, check
GET /health?strict=true instead: it answers 503 for a DEGRADED node as well as for a DOWN one. The body is the
same, so the failing dependency is still visible. In a test with HAProxy (inter 1s fall 2 rise 2), a node whose HSM
returned an error answered 200 (DEGRADED) and stayed in the pool when HAProxy checked GET /health; when HAProxy
checked GET /health?strict=true, the node was taken out of the pool about 2 seconds later, and the same happened to a
node whose database stopped answering. A node came back in the pool about 2 seconds after its dependency answered
again. During the database test, key creations through HAProxy kept succeeding.
The kmip entry only appears when the KMIP socket server is enabled. It reports whether the socket server is still
running: it does not open a connection to the KMIP port, so it does not detect a firewall or network problem in front
of the port.
Each HSM slot is probed with a bounded wait: a slot that does not answer within 2 seconds is reported DOWN (with the
message no answer within 2000 ms), so /health never hangs and the node is DEGRADED. The answer of a slot is reused
for 2 seconds, and at most one probe per slot runs at a time: while a probe is still waiting for the HSM, later
/health calls report the slot DOWN without starting another one, so repeated health checks cannot exhaust the
server's threads.
The message of a DOWN dependency never carries the detail of the error (database driver text, host, user, PKCS#11
return code): the public endpoint could otherwise show it to anyone who can reach the port, and the detail is written
to the server log instead. The message is one of these fixed texts, and an HSM message is prefixed with slot <id>::
| Message | Meaning |
|---|---|
database check failed (details in the server log) | the database check returned an error |
the HSM returned an error (details in the server log) | an HSM call returned an error |
no answer within 2000 ms | the database or the HSM slot did not answer in time |
the previous probe is still waiting for the HSM | an earlier probe of the slot has not ended yet |
the KMIP socket server is not running (details in the server log) | the socket server task has ended |
Look for log lines containing health check: to see the detail.
The HSM check asks each configured slot for its list of mechanisms. Some PKCS#11 libraries (for example Crypt2pay) answer from local data and do not report an HSM that has become unreachable: such a failure then only shows when a cryptographic operation fails.
GET /cluster/status
This endpoint lists the live nodes. It requires authentication, like the other KMS API endpoints (without credentials
the server answers 401). For example, with a TLS client certificate:
curl --cacert <CA_CERT_FILE> --cert <CLIENT_CERT_AND_KEY_PEM> https://<KMS_HOST>:9998/cluster/status
Example response from a two-node cluster:
{"nodes":[{"node_id":"b5f214cf-49d2-48db-8237-8d570db10143","version":"5.29.0","last_heartbeat":1794931360,"leader":false},{"node_id":"e73bb874-75c9-404e-a579-f1145ee9bce2","version":"5.29.0","last_heartbeat":1794931357,"leader":true}],"leader":"e73bb874-75c9-404e-a579-f1145ee9bce2"}
| Field | Description |
|---|---|
nodes[].node_id | Node ID, generated when the KMS process starts. |
nodes[].version | KMS version of the node. |
nodes[].last_heartbeat | Time of the last heartbeat, in Unix seconds. |
nodes[].leader | Whether this node is the leader shown for the cluster. |
leader | Node ID of the leader, or null when there is none yet (just after start-up, or in the seconds after the leader stopped). |
Web UI
The Server Health page of the Web UI (Server Health in the menu, or /ui/server-health) shows the same
information as the two endpoints above: the global status, each dependency and the live nodes. The footer of every page
shows the status as a marker (🟢 UP, 🟡 DEGRADED, 🔴 DOWN or unreachable) that links to the page. The page
refreshes when you press Refresh, or at the period chosen in Auto-refresh (every 5, 10 or 30 seconds, or every
minute; manual by default). The chosen period is remembered by the browser, and the refresh pauses while the browser tab
is hidden.
Each refresh sends two requests (GET /health, public, and GET /cluster/status, authenticated), and the server
logs and audits each of them. The refresh does not extend the Web UI session: its cookie has a fixed lifetime of
24 hours.
Metric
When OpenTelemetry metrics are enabled, each node exports the gauge kms.cluster.nodes: the number of live nodes,
refreshed every 5 seconds. It is always 0 with Redis with Findex, which has no heartbeat.