Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sovereign, high-performance data protection

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/status shows the live nodes and GET /health reports 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.

KMS nodes behind a load balancer coordinate through a shared 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:

JobLock nameRuns on
Key auto-rotation and renewal warningsauto-rotationone node at a time (leader region only, see Multi-region deployments)
CRL refreshcrl-refreshone node at a time (leader region only)
Object counter reconciliationmetrics-reconcileone node at a time
Metrics gauges refresh (kms.keys.active.count, kms.objects.total)noneevery node (each node exports its own gauges)
KV secret TTL expirykv-ttlone node at a time

Two nodes compete for a job lock; one runs the job and the other skips it

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

Heartbeat loop: write own row and elect a leader when none is alive

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/status and kms.cluster.nodes show the nodes of the region that answers: the cluster_nodes table 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;
  • /health is per region: check each region with its own load balancer.

Supported databases

DatabaseJob locksHeartbeat and /cluster/status
PostgreSQLyesyes
MySQL / MariaDByesyes
Galera: Percona XtraDB Cluster (default pxc_strict_mode=ENFORCING), MariaDB Galerayes: 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 nodeyes
SQLitenot needed (single node)yes, shows one node
Redis with Findex (non-FIPS only)no: every node runs every jobno: /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 statusHTTP codeMeaning
UP200The database, every configured HSM and the KMIP socket server (when enabled) are fine.
DEGRADED200, or 503 with ?strict=trueThe database answers, but at least one HSM does not, or the KMIP socket server has stopped.
DOWN503The 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>::

MessageMeaning
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 msthe database or the HSM slot did not answer in time
the previous probe is still waiting for the HSMan 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.

HSM status depends on the PKCS#11 library

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"}
FieldDescription
nodes[].node_idNode ID, generated when the KMS process starts.
nodes[].versionKMS version of the node.
nodes[].last_heartbeatTime of the last heartbeat, in Unix seconds.
nodes[].leaderWhether this node is the leader shown for the cluster.
leaderNode 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.

Note

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.