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

Multi-region active-active deployment

This page explains how Eviden KMS runs active-active across regions on PostgreSQL logical multi-master replication: what the topology looks like, what is replicated, how conflicting writes converge, and what the limits are. Operator settings are summarized here; the full reference stays in Multi-region active-active PostgreSQL; the MySQL variant is below.

Two regions with local read-write PostgreSQL and async replication

Why active-active

A single-writer PostgreSQL (primary plus hot standbys) forces every region to write to one place. In an active-active deployment each region runs its own KMS instance group and its own local PostgreSQL node: reads and writes are served locally for low latency, and the nodes converge asynchronously. The implementation is generic and is validated against pgEdge Community (Spock) as the reference; other logical multi-master extensions (EDB Postgres Distributed, Postgres-BDR) are expected to behave the same way but are not part of the CI validation.

What is Spock

Spock is a PostgreSQL extension, developed by pgEdge, for multi-master replication: every node accepts writes and replicates them to the others. Native PostgreSQL logical replication can already run in both directions, but it has no conflict resolution: two regions changing the same row make replication fail or the nodes diverge. Spock adds conflict resolution and conflict-free counters (delta-apply). Eviden KMS does not embed or call Spock: it relies on the guarantees below, and the operator installs and wires the extension. Spock needs wal_level = logical, track_commit_timestamp = on (conflict resolution compares commit timestamps) and shared_preload_libraries = 'spock'; the validated image is pgedge/pgedge-postgres with Spock 5 on PostgreSQL 16. See the Spock documentation and its configuration guide.

Spock conceptMeaningWhere it matters for the KMS
NodeOne PostgreSQL database taking part in the groupOne per region
SubscriptionA one-way logical replication link from a provider node to a subscriber nodeOne in each direction makes a two-region group (a full mesh with more regions)
Replication setThe list of tables a node publishesEvery public table except cluster_nodes (see Which tables are replicated)
Conflict resolution (last_update_wins)When two regions change the same row, the version with the latest commit timestamp is keptObject payload, attributes and tags; lifecycle states need another mechanism (see Object-state conflict merge)
Delta-applyA numeric column is replicated as an increment instead of a new valuegcm_invocations.count, so the AES-GCM counts of the regions add up

Replication is asynchronous: a commit succeeds locally and reaches the other regions after the replication lag. The KMS creates its lifecycle triggers as ENABLE ALWAYS so that they also fire on rows applied by replication. mise run test:db:multi-region-guards checks the extension, the node, the subscriptions and these settings on every node.

MySQL has no Spock: the Galera alternative is described below.

Which tables are replicated

What "public" means

On PostgreSQL, public is the default schema (namespace) of a database; it is not a visibility setting. The KMS never qualifies a schema name (no CREATE SCHEMA, SET SCHEMA or search_path in its code): its tables are created in the database named in the connection URL, in the first existing schema of the connection's search_path. With the PostgreSQL default ("$user", public) that is public, so in a database dedicated to the KMS "the public tables" are all the KMS tables. The audit store of a PostgreSQL audit backend is a separate database and is not part of this replication.

Warning

If a schema named like the KMS role exists (for example kms), or the URL or the role sets search_path, the tables are created there instead, repset_add_all_tables('default', ARRAY['public']) replicates nothing of the KMS, and mr_guard_replication_set_complete (which only looks at public) cannot see it. Check on every node, as the KMS role: SELECT schemaname, tablename FROM pg_tables WHERE tablename = 'objects'; must return public. If the database holds other applications' tables in public, repset_add_all_tables also adds them: dedicate the database to the KMS.

Table (PostgreSQL)Replicated by SpockWhy
objects, tags, read_access, parametersYesObject store, last-update-wins
object_state_events, object_state_event_tombstonesYesInsert-only lifecycle log (see Object-state conflict merge)
crypto_officer_activations, crlsYesWritten by the leader region, read by every region
gcm_invocationsYes, with delta-applyThe AES-GCM counts of the regions add up
ui_session_revocationsYesA Web UI logout is honored by every region
cluster_nodesNoHeartbeats and elected leader are per region

kms_migration_lock and kms_cron_locks exist on MySQL only. The full list and the purpose of each table is in Database tables.

How Spock selects the tables

Spock does not replicate a schema: it replicates the tables that belong to a replication set, and a subscription receives the rows of the tables of the sets it subscribes to. A Spock node comes with the sets default (insert, update, delete, truncate), default_insert_only and ddl_sql; the KMS tables are added to default.

spock.repset_add_all_tables('default', ARRAY['public']) is the command that ties the two notions together: it adds to the default set every table that exists in the public schema when the command runs. It is a one-time snapshot, not a rule that stays active, so:

  • A table created afterwards is not replicated until it is added with spock.repset_add_table('default', '<table>'). This is what an upgrade that adds a table needs on every node (for example ui_session_revocations on a deployment set up before it existed).
  • Spock replicates rows, not schema changes (spock.enable_ddl_replication is off by default): every node creates the table itself. The KMS does it at startup with CREATE TABLE IF NOT EXISTS, so each region has the table as soon as its KMS is upgraded, whether or not the table is replicated.
  • Updates and deletes are replicated through the row's REPLICA IDENTITY, in practice the PRIMARY KEY; every KMS table has one (checked by mr_guard_primary_keys).
  • cluster_nodes is removed from the set on purpose (spock.repset_remove_table).

To list the tables of the public schema that a node does not publish (an empty result is correct; cluster_nodes is excluded on purpose):

SELECT t.tablename
FROM pg_tables t
WHERE t.schemaname = 'public'
  AND t.tablename <> 'cluster_nodes'
  AND NOT EXISTS (SELECT 1 FROM spock.replication_set_table r
                  WHERE r.set_reloid = format('public.%I', t.tablename)::regclass);

mise run test:db:multi-region-guards runs this check (mr_guard_replication_set_complete) and fails with the repset_add_table command to run.

How Galera selects the tables

Galera has no replication set and no schema filter, and MySQL has no public schema: every committed change to an InnoDB table with a primary key, in any database of the cluster, is replicated to every node (the system mysql.* tables and non-InnoDB tables aside). The KMS tables are all InnoDB, in the kms database. The rules that matter:

  • A new table is replicated from its creation: CREATE TABLE is replicated as a schema change (total order isolation, the default of wsrep_OSU_method, shown as TOI by SHOW VARIABLES LIKE 'wsrep_OSU_method'), so the KMS startup on one node creates it everywhere and there is no operator step on upgrade.
  • Tables of another storage engine are not replicated (wsrep_replicate_myisam = OFF); the KMS creates none.
  • Every table needs a PRIMARY KEY; Percona XtraDB Cluster in strict mode (pxc_strict_mode = ENFORCING) refuses writes to a table without one. mr_guard_mysql_primary_keys checks it.
  • A table cannot be excluded, which is why cluster_nodes is replicated on Galera.

Global architecture

Three rules shape everything else:

  • Every region writes locally. There is no proxying between regions.
  • One global leader. region_role = "leader" (the default) or "follower"; exactly one region is the leader. There is no election: the role changes only when an operator changes the topology.
  • Only data that cannot be merged is leader-gated. CRL generation and Crypto Officer ceremony activation/revocation are accepted on the leader only; a follower rejects them with an HTTP 422 telling the client to retry against the leader region. Background key auto-rotation runs on the leader only, a follower skips it. Everything else is written in any region.

What converges, and how

DataWritten byConvergence
Object payload, attributes, tagsany regionWhole-row last-update-wins (Spock last_update_wins)
Object lifecycle Stateany regionDeterministic join over an insert-only event log (see below)
Grants (read_access)any regionWhole-row last-update-wins; a concurrent grant and revoke on the same object and user can drop one side
CRLs (crls)leader onlyReplicated to followers, which serve it from the public CDP endpoint
Ceremony activationsleader onlyReplicated; a mismatched ceremony_secret fails secure
AES-GCM invocation counts (gcm_invocations)any regionReplicated and merged by delta-apply, so the counts of the regions add up
Node heartbeats (cluster_nodes)every region, for its own nodesNot replicated: each region lists its own nodes only

The replicated tables carry real primary keys, created automatically and idempotently at startup (see Internals: Database Tables).

Object-state conflict merge

Two regions can change the state of the same object at nearly the same time, for example one region destroys a key while another deactivates it. Whatever the commit order, a Destroyed or Compromised object must never be silently moved back to a less restrictive state.

Concurrent Destroyed and Deactivated events converge on Destroyed

Why not a column on objects

Spock's last_update_wins compares commit timestamps and discards an incoming row older than the local row before any trigger runs. A state column guarded by a trigger therefore cannot converge: the older Destroyed row is simply dropped on the node that wrote Deactivated later.

The event log

On PostgreSQL every state change is appended to object_state_events and never updated, so two regions never write the same row and nothing can conflict. Triggers marked ENABLE ALWAYS (so they also fire in replication apply sessions) derive objects.state from the events:

Object state derived from insert-only events and tombstones by triggers

The derived state is the join of all live events:

$$\text{PreActive} < \text{Active} < \text{Deactivated} ;/; \text{Compromised} < \text{Destroyed}$$

with a sticky compromised flag, so Compromised joined with Destroyed yields Destroyed_Compromised.

The Destroyed event also carries the zeroized object written by the Destroy operation, in the same transaction. A concurrent payload write from another region therefore cannot bring key material back on a destroyed object.

Backward transitions

A few operations legitimately move the state backwards (KMIP batch Undo, import with replace). They tombstone only the events their region has observed and append a new one. A higher transition made concurrently in another region and not yet received still wins when it arrives.

Scheduled jobs and cluster coordination

The nodes of a region coordinate through their local database (see Cluster coordination): job locks and heartbeats never cross a region. This has three consequences.

Per-region job locks and heartbeats; selected tables replicate across regions

Which region runs each job, and which features the leader region keeps to itself:

Job or featureLock nameRuns on, in a multi-region deployment
Key auto-rotation and renewal warningsauto-rotationone node at a time, leader region only
CRL refreshcrl-refreshone node at a time, leader region only
CRL generation (generate-crl)noneleader region only; a follower answers HTTP 422
Crypto Officer ceremony activation and revocationnoneleader region only; a follower answers HTTP 422
Object counter reconciliationmetrics-reconcileone node at a time, in every region
Metrics gauges refresh (kms.keys.active.count, kms.objects.total)noneevery node of every region (each node exports its own gauges)
KV secret TTL expirykv-ttlone node at a time, in every region (repeating it converges)
Every other KMIP operation and REST routenoneevery region, locally; except that a follower's KV v2 and SSH CA/role requests return a retry error until the leader's kv_metadata_uid_key has replicated (see Operating notes)
  • A job lock excludes a job in its own region only. Two regions would run the same job at the same time, so a job that must run once runs on the leader region only: key auto-rotation and its renewal warnings (a follower skips them, like the CRL refresh). Enable auto_rotation_check_interval_secs on the leader region; it has no effect on a follower. A job that is safe to repeat runs in every region: KV secret TTL expiry (destroying a version twice converges through the lifecycle event log) and the metrics refresh.
  • GET /cluster/status and kms.cluster.nodes show the local region. The cluster_nodes table is excluded from replication and each region elects its own display leader. Replicated, the heartbeat rows of the regions would overwrite each other every time a leader is elected (the election rewrites every row).
  • AES-GCM invocation counts add up across regions. The count kept per key against the cap of NIST SP 800-38D ยง8.3 is a counter updated in every region. With whole-row last-update-wins the regions would overwrite each other's increments, and the counts would be too low. Spock delta-apply on gcm_invocations.count applies each region's increment instead. The cap is still checked against the local value: with replication lag, a key can exceed the cap by what the other regions reserved during the lag. Each node leases invocations from the store in blocks of 4,096 and records the whole block when it leases it, so the overshoot during the lag is counted in whole blocks, and the unused part of a block counts as used.
  • Read-modify-write on an object is regional. KMIP Usage Limits counters and Vault KV v2 check-and-set versions are updated with a version check on the object row. Two regions both pass their local check and last-update-wins keeps one row: a key with Usage Limits can be used up to its limit in each region, and a check-and-set write can succeed in two regions.

Configure these two tables on every node, after adding the public tables to the replication set:

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);

mise run test:db:multi-region-guards checks both settings.

On an existing deployment upgraded to a release that adds the ui_session_revocations table (Web UI logout revocation), repset_add_all_tables has already run: add the new table on every node with SELECT spock.repset_add_table('default', 'ui_session_revocations');, otherwise a logout in one region is not seen by the others.

Operating notes

  • Set region_role once per region (--region-role or KMS_REGION_ROLE); never configure two leaders.
  • Do not enable clear_database on a multi-region node: the deletes replicate to every region.
  • Use identical ceremony_secret values in every region.
  • The leader initializes the shared KV/SSH identifier key (kv_metadata_uid_key in parameters) at startup. Followers only read the replicated value; until it arrives, KV and SSH CA/role requests return a retry error instead of creating a competing key. No leader-side API request is needed to bootstrap it. Existing deployments that already generated different keys in separate regions require operator reconciliation before enabling traffic; startup does not rewrite existing records.
  • Check GET /health?strict=true of each region separately: a region's health is its own database, HSMs and KMIP socket server.
  • The validated topology is two nodes. In a three-node or larger full mesh, an objects update that reaches a node before its insert is discarded together with its whole transaction (Spock transdiscard), which can drop that transaction's lifecycle events on that node.
  • Lifecycle events are never compacted; compaction would need cross-region coordination.
  • SQLite and Redis-with-Findex are not multi-region targets: a region_role = "follower" on them is rejected at startup.
  • Objects stored in an HSM do not replicate, including HSM-backed sub-CA keys: a region that signs CRLs or OCSP responses with such a key needs the same HSM keys.
  • Auto-rotation of HSM-resident keys runs on the leader region only, like every auto-rotation: the new key is created in the leader region's HSM, which does not replicate. The other regions' HSMs are not rotated by the job, and a rotated hsm:: identifier replicated with the object metadata must be provisioned in each region's HSM before that region uses it.
  • A certificate revoked on a follower does not regenerate the CRL (the follower's automatic regeneration is refused). The leader republishes it at the next run of its CRL refresh scheduler (every crl_refresh_check_hours, default 1 h, when kms_public_url is set), which regenerates a stored CRL near its nextUpdate (crl_refresh_overlap_hours, default 24 h) or whose revoked certificates changed. To publish a revocation at once, revoke on the leader region, or run ckms certificates generate-crl on the leader after revoking on a follower.
  • The OCSP response cache is per KMS process: a revocation evicts the cached response of the node that served it only, and the other nodes of every region answer nonce-less requests from their cache until ocsp_cache_ttl_secs (default 86400 s) elapses. Keep ocsp_cache_ttl_secs low in a multi-region deployment.
  • Upgrade 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. See Database tables for the downgrade procedure and round-trip limits. On Galera, start the first node alone before the others.
  • To check a deployment, run mise run test:db:multi-region-guards: it verifies the primary keys, the ENABLE ALWAYS triggers, the Spock wiring (PostgreSQL), the Galera wiring (MySQL) and the operator configuration (exactly one leader, PostgreSQL or MySQL backend identical across regions, identical ceremony secret).

MySQL with Galera

A region can instead run on a MySQL Galera cluster spanning the regions (Percona XtraDB Cluster is the validated flavor, tested with two nodes; MariaDB Galera and MySQL Group Replication in multi-primary mode are expected to work but are not validated). Galera certifies each transaction on every node and aborts a conflicting commit (error 1213), which the KMS already retries, so there is no last-update-wins merge to guard against:

DataConvergence on Galera
Object payload, attributes, tagsCertification: a conflicting commit is retried
Object lifecycle StateThe KMS joins the stored state with the new one in the writing transaction (Destroyed and Compromised never regress); a batch Undo writes the state explicitly
Key material of a Destroyed objectAn update of the payload leaves the zeroized payload in place
AES-GCM invocation countsExact: the counter row is locked, no delta-apply is needed
GrantsRead-modify-write: a concurrent grant and revoke can drop one side, as on PostgreSQL
Usage Limits counters, KV v2 check-and-setExact: certification aborts the concurrent commit, which retries on the fresh row
Node heartbeats (cluster_nodes)Replicated: Galera cannot exclude a table, so GET /cluster/status lists the nodes of every region

Operating notes:

  • Point all the KMS nodes of a region at the same database node, and run an arbitrator (garbd) in a third site.
  • Scheduled jobs: Percona XtraDB Cluster in strict mode (and MariaDB Galera) refuses GET_LOCK. The KMS then takes a committed lease on a row of kms_cron_leases (300 seconds, renewed every 100 seconds while the job runs, on the clock of the database node: keep the nodes NTP-synchronised), which Galera replicates: a job runs once across the cluster. A rolling upgrade from a release before 6.0 is degraded until every node runs 6.0. Key auto-rotation is leader-region only anyway.
  • region_role = "follower" is accepted on PostgreSQL and MySQL only.
  • A node still running the previous release keeps plain state writes until every region is upgraded.

Warning

Grants use whole-row last-write-wins. Re-check the effective permissions of an object after a concurrent grant and revoke in two regions.