High availability and deployment profiles
KMS nodes are stateless: all data lives in the database. They can be scaled horizontally from a single node up to any number of nodes, simply by connecting them all to the same database and putting a single entry point in front of them. A deployment is therefore two choices: which database, and how clients reach the nodes. This page lists the usual profiles, from the simplest to the most available, and what each one gives and does not give. To serve clients from several regions, each with its own database, see Profile 6.
The connection from the nodes to PostgreSQL and MySQL/MariaDB can be secured with TLS: see Securing database connections.
How the nodes share background jobs and report their state (/health, /cluster/status) is described in
Cluster coordination.
Choosing a profile
| # | Profile | Nodes | Clients reach the KMS through | When a node fails | Typical use |
|---|---|---|---|---|---|
| 1 | Single node | 1 | the address of the node | the service stops | development, tests, small sites, a Cosmian confidential VM |
| 2 | Cloud load balancer | 2+ | a managed load balancer | the balancer stops sending requests to it | cloud |
| 3 | Round-robin DNS | 2+ | a DNS name with one record per node | nothing automatic: requests keep going to it until it leaves the DNS | simple load spreading |
| 4 | Keepalived only | 2+ | a virtual IP (VIP) shared by the nodes | the VIP moves to another node in a few seconds | on premises, nodes on one network |
| 5 | HAProxy, with or without Keepalived | 2+, plus 1 or 2+ load balancers | one HAProxy, or a VIP over several HAProxy | HAProxy stops sending requests to it | on premises, load spread over all nodes |
| 6 | Multi-region active-active | 1+ per region, in two regions | the nearest region (geo DNS or a global load balancer), each region with profile 2 to 5 inside | the other region keeps serving; clients of the failed region move to it | local reads and writes in two regions, with asynchronous convergence |
Profiles 2 to 5 need a PostgreSQL or MySQL/MariaDB database shared by all the nodes (see Rules common to profiles 2 to 5). The availability of the database itself is a separate choice, described in Database availability. Profile 6 repeats one of them in each region, with its own database in each region: a PostgreSQL database per region replicated with Spock, or a node per region of a MySQL Galera cluster spanning the regions (see MySQL with Galera).
cosmian_kms configure asks these questions first, then restricts the database choice to the profile,
writes region_role for profile 6 and prints the profile's operating notes.
Rules common to profiles 2 to 5
- All the nodes use the same database: PostgreSQL or MySQL/MariaDB. SQLite supports one node only. Several nodes on Redis with Findex are not supported for now: its scheduled jobs are not coordinated (see Cluster coordination).
- All the nodes expose the same server certificate, and its name is the name clients use: the DNS name of the load balancer, of the VIP, or of the DNS record.
- The nodes must listen on an address reachable from the clients. The HTTPS server listens on
0.0.0.0by default (on Linux and macOS). The KMIP socket server listens on127.0.0.1by default: setsocket_server_hostnameto0.0.0.0if clients use KMIP on port 5696.
If audit logging is enabled (--audit-enable), each KMS node must write to its own
audit file, not a shared/network volume. The file backend uses a local lock to serialize
writes; it only prevents corruption on a single node (e.g. during a rolling restart), not
across nodes. Pointing several replicas at the same audit file means only one of them will
ever actually write to it — the others sit idle, so you silently lose their events.
A centrally consolidated, multi-writer-safe audit trail requires the
PostgreSQL audit backend instead.
What the nodes share
Because the KMS nodes are stateless, the shared database is the source of truth: ensure you have regular database backups (and periodically test restores) using your database engine's recommended procedures. In-memory object caches validate lifecycle state and security-sensitive attributes against the shared database using a short bounded revalidation interval (2 seconds by default). This preserves hot-path cache performance while bounding cross-node propagation lag when keys are revoked, deactivated, or destroyed on any node.
What /health tells a load balancer
Every profile except the first uses GET /health on the HTTP(S) port (9998 by default) to decide whether a node is usable:
| Situation on the node | GET /health | GET /health?strict=true | Effect |
|---|---|---|---|
| The database is down, or silent for more than 2 seconds | 503 (DOWN) | 503 | the node leaves the pool |
| An HSM does not answer | 200 (DEGRADED) | 503 | with strict=true the node leaves the pool; without, it stays and the requests that need the HSM fail on it |
| The KMIP socket server has stopped, the HTTPS server answers | 200 (DEGRADED) | 503 | same as above, for KMIP clients |
Use ?strict=true when a node that cannot serve all its requests must not receive any. The body of the answer is the same
in both cases. See Cluster coordination for the details.
Profile 1: single node
One KMS and one database, SQLite included. Clients connect to the address of the node. There is no failover: restore the node or its database from a backup. See Getting started.
In a Cosmian confidential VM, the KMS runs in one VM with its own encrypted Redis database (Redis with Findex): see Deploying in a Cosmian Confidential VM. Several Cosmian VMs, each with the default Redis with Findex database, are not supported for now.
Profile 2: cloud load balancer
Use a managed load balancer of your cloud provider, in front of the nodes:
- forward the KMIP port (
5696) and the HTTPS port (9998) as plain TCP, so that TLS ends on the nodes and every node presents the same certificate; - check the nodes with
GET /health?strict=trueand keep a node in the pool only on200.
Adding or removing a node does not change the address clients use.
Profile 3: round-robin DNS
Publish one DNS record per node under a single name, with a short TTL. Clients resolve the name and spread over the nodes.
This profile has no failover: DNS does not know that a node is down. The failed node keeps receiving requests until it is removed from the DNS and the TTL has expired, unless the client library tries the next address by itself, which depends on the client. Use it for load spreading in a lab or when a failure of a node is acceptable, or add health checks at the DNS provider.
Profile 4: Keepalived only
The Keepalived instances of the nodes talk to each other with VRRP to agree on which node holds the VIP.
Keepalived runs on the KMS nodes themselves, with no HAProxy. The nodes share a VIP: the MASTER node holds it and
answers the clients, the other nodes wait. Each Keepalived checks the KMS of its own node with
GET /health?strict=true; when the check fails, that node gives up the VIP and another node takes it.
Requirements:
- the nodes are on the same network (layer 2), and VRRP traffic (IP protocol 112) is allowed between them;
- Keepalived is installed on every node, and the VIP is free on that network;
- the KMS listens on all addresses (see Rules common to profiles 2 to 5), and the server certificate carries the DNS name of the VIP.
The same configuration is used on every node. Change only priority and the two unicast addresses on each node (the
highest priority starts as MASTER):
global_defs {
enable_script_security
script_user keepalived_script # An unprivileged user, created beforehand
}
vrrp_script chk_kms {
script "/usr/bin/curl -skf -m 2 -o /dev/null https://127.0.0.1:9998/health?strict=true"
interval 2
fall 2 # 2 failed checks: the node leaves the VIP
rise 2 # 2 good checks: the node can hold the VIP again
}
vrrp_instance KMS {
state BACKUP # BACKUP on every node: the priority decides
interface eth0 # Adapt to your network interface name
virtual_router_id 51 # Identical on all nodes
priority 101 # 101 on node 1, 100 on node 2, ...
advert_int 1
unicast_src_ip 192.168.1.11 # Address of this node
unicast_peer {
192.168.1.12 # Addresses of the other nodes
}
virtual_ipaddress {
192.168.1.100/24 # VIP: the address clients use
}
track_script {
chk_kms
}
}
In a lab with two nodes and one PostgreSQL database, the VIP moved to the other node about 3 seconds after the KMS
process of the MASTER stopped, and about 3 seconds after the MASTER lost its network. When the first node came
back, it took the VIP again, without failed requests on a client that opens a new connection for each request. Add
Keepalived's nopreempt option if you prefer that the VIP stays where it is.
When the database stopped, /health stopped answering 200 on both nodes, both gave up the VIP, and the VIP came
back by itself when the database was back.
Limits of this profile:
- Active/passive: only the node holding the VIP serves clients; the others are spare. To spread the load, use profile 2 or 5.
- An open KMIP connection is cut when the VIP moves: the client has to reconnect.
- The check follows what
/healthtells a load balancer: the script above uses?strict=true, so a node whose HSM fails, or whose KMIP socket server has stopped, gives up the VIP. - It does not work on AWS: in a test, an address added to an instance's network interface was not reachable from the other instances of the same subnet. Use profile 2 there. Other public clouds were not tested.
Profile 5: HAProxy
HAProxy spreads the requests over all the nodes and stops sending requests to a node that fails its health check:
- one HAProxy in front of the nodes: load spreading and failover between nodes, but HAProxy is a single point of failure;
- two or more HAProxy with Keepalived: the same, with a VIP over the HAProxy nodes, so that no component is a single point of failure.
The configuration of both is described in HAProxy and Keepalived. Check the nodes with
GET /health?strict=true to also take out the nodes that /health reports as DEGRADED (see
What /health tells a load balancer).
Profile 6: multi-region active-active
Each region runs its own group of KMS nodes and its own database node: either a PostgreSQL node per region, the PostgreSQL nodes replicating to one another with a logical multi-master extension (validated with pgEdge Spock), or a node per region of a MySQL Galera cluster spanning the regions (validated with Percona XtraDB Cluster). Clients use the nearest region, which serves reads and writes locally. Inside a region, use one of profiles 2 to 5 for the nodes.
What differs from profiles 2 to 5:
- One database per region, not one for all the nodes. The rules common to profiles 2 to 5 apply inside each region.
- One
region_role = "leader"region, all the othersfollower. CRL generation, Crypto Officer ceremonies and background key auto-rotation run on the leader region only; a follower rejects the first two with an HTTP 422 (the client retries on the leader region) and skips the third. Everything else is served by every region. - Cluster coordination stays inside a region: job locks, heartbeats,
GET /cluster/statusandGET /healthdescribe the region that answers (see Multi-region deployments). Point the health check of each regional entry point at its own nodes, with?strict=trueif a degraded node must leave the pool. On Galera, the heartbeats replicate, soGET /cluster/statuslists the nodes of every region. - Convergence is eventual: a change made in a region reaches the others after the replication lag. Object lifecycle states converge to the most restrictive one (a destroyed key stays destroyed in every region).
- The validated topology has two regions. The database is PostgreSQL with Spock (one database per region) or a
MySQL Galera cluster spanning the regions (see
MySQL with Galera). All the regions use the same
ceremony_secret.
Operating profile 6
- Upgrade the KMS release one region first, then the others in the same window, stopping every older node before starting the new release. On PostgreSQL, release 5.29.0 starts on the upgraded database, but lifecycle triggers override its direct state writes. No mixed-version rolling restart is supported on PostgreSQL. See Database tables for downgrade recovery and limits. On Galera, start the first node alone before the others. The storage changes themselves are applied at startup; no migration command is needed.
- Move an existing deployment to profile 6: a region must run PostgreSQL or MySQL; a node with
region_role = "follower"on SQLite or Redis-with-Findex is rejected at startup. The existing region keeps the defaultregion_role = "leader". The replication setup of the new region is in Multi-region active-active deployment. - If the leader region is lost, the followers keep serving reads and writes, but CRL generation, Crypto Officer
ceremonies and auto-rotation stop. There is no automatic election: set
region_role = "leader"on one surviving region and restart its nodes, and make sure the lost region cannot come back as a leader (never two leaders). - Objects in an HSM do not replicate: each region needs the same HSM keys.
The full list of operating notes and limits is in Multi-region active-active deployment.
The topology, what converges and how, the replication set to configure and the limits are in Multi-region active-active deployment; the settings are in Database configuration.
Database availability
In profiles 1 to 5, all nodes depend on one database: if it is down, no node can serve requests. In profile 6, this dependency is local to each region; another region can continue serving against its own database. Make each database highly available with the tools of your database:
- PostgreSQL: streaming replication with an HA manager such as Patroni or pg_auto_failover, or a managed multi-zone service;
- MySQL / MariaDB: the replication or cluster solution of your platform.
Point database_url of all the nodes to the address that follows the primary (a VIP or the endpoint of the managed
service). The details and the constraints of each engine are in
Database configuration. Back up the database regularly and test the
restores: it is the source of truth of the whole cluster.