Multi-region active-active PostgreSQL (Spock / pgEdge / BDR)
The KMS supports multi-region active-active deployments using PostgreSQL with a logical multi-master replication extension, validated with pgEdge Spock (ghcr.io/pgedge/pgedge-postgres); other extensions are not validated (see Extension requirements). In this topology, each region runs a local KMS instance group connected to a local PostgreSQL node, serving local reads and writes for minimum latency. State converges asynchronously across regions via bidirectional logical replication.
A region can run on a MySQL Galera cluster instead (Percona XtraDB Cluster): see MySQL with Galera. A region_role = "follower" on SQLite or Redis-with-Findex is rejected at startup.
KMS server nodes do not communicate directly with each other over the network. All cross-region state coordination and replication are handled entirely at the database layer:
The validated topology has two PostgreSQL nodes. Larger meshes are not supported by this deployment profile; see the replication limits.
Topology and region_role
To prevent split-brain conflicts on operations requiring global coordination, the deployment defines a topological role per region via the region_role configuration setting:
# /etc/cosmian/kms.toml
region_role = "leader" # exactly one region per deployment
# region_role = "follower" # all other regions
Or via CLI flag --region-role <leader|follower> or environment variable KMS_REGION_ROLE.
Leader-only operations
Exactly one region across the entire deployment MUST be designated leader (region_role = "leader", which is the default). All other regions MUST be configured as follower.
The leader region is the only region permitted to execute:
- X.509 CRL generation and background refresh โ RFC 5280 ยง5.2.3 requires strict per-issuer
crlNumbermonotonicity. Concurrent issuance from uncoordinated writers violates this requirement. - Crypto Officer ceremony activation and revocation โ Key ceremonies rely on dual-control quorum and activation history; safety takes priority over local write availability.
- Background key auto-rotation and renewal warnings โ the job locks of the cluster coordination live in each region's own database, so they cannot keep two regions from rotating the same key. A follower skips the job; enable
auto_rotation_check_interval_secson the leader region.
If a client attempts CRL generation or ceremony activation/revocation against a node configured with region_role = "follower", the request is rejected immediately with an HTTP 422 error instructing the client to target the leader region. Background CRL refresh and auto-rotation cron tasks on followers are automatically skipped.
CRL endpoints and the Crypto Officer ceremony across regions are described in CRL and Crypto Officer ceremony across regions.
Every other operation (key generation, encryption, decryption, access grants, Locate, etc.) executes locally on any region with no leader dependency.
State conflict resolution (lifecycle event log)
In multi-region active-active replication, object State transitions can race across regions (e.g. an object deactivated in region A while destroyed in region B). Spock's commit-timestamp last-write-wins (LWW) drops an incoming row older than the local row before any trigger runs, so a state column on objects cannot converge.
On PostgreSQL the KMS therefore records every lifecycle transition as an insert-only row in object_state_events (a row is never updated, so it never conflicts). ENABLE ALWAYS triggers derive objects.state from the live events, so they also fire in replication apply sessions. The derived state is the join of all events, using the NIST SP 800-57 / KMIP lifecycle phases plus a sticky compromised flag:
$$\text{PreActive} < \text{Active} < \text{Deactivated} ;/; \text{Compromised} < \text{Destroyed}$$
Compromised joined with Destroyed yields Destroyed_Compromised. The zeroized payload written by Destroy is snapshotted in the destroyed event, so a concurrent payload write in another region cannot restore key material on a destroyed object.
A legitimate backward transition (KMIP batch UNDO, import-replace) removes only the events its region has observed (rows in object_state_event_tombstones) and appends a new event. A higher transition made concurrently in another region and not yet received still wins. Events are never compacted, and the validated topology is two nodes.
Permissions and access control (LWW)
Concurrent conflicting modifications to read_access (e.g. concurrent grant on node 1 and revoke on node 2 for the same (object_id, user_id) pair) converge via the underlying replication extension's row-level conflict resolution (last_update_wins). A concurrent grant and revoke on the same object/user pair can result in either state winning.
Extension requirements
The implementation is validated with pgEdge Spock. Another logical multi-master extension needs the same settings
and an equivalent of Spock delta-apply for gcm_invocations.count; it is not validated. Requirements:
-
wal_level = logical -
track_commit_timestamp = on -
Every public KMS table in the replication set except
cluster_nodes, including the lifecycle event tablesobject_state_eventsandobject_state_event_tombstones, and delta-apply ongcm_invocations.count. With Spock, run on every node:SELECT spock.repset_add_all_tables('default', ARRAY['public']); SELECT spock.repset_remove_table('default', 'cluster_nodes'); ALTER TABLE gcm_invocations ALTER COLUMN count SET (log_old_value = true, delta_apply_function = spock.delta_apply);
See Multi-region active-active deployment for why.