Skip to content

IAM control plane

Pools, advisory locks, the 5-second bound and the revision token added in schema 14.

In a multi-gateway pgsilo deployment, gateways cache IAM users, groups, policies, service accounts, STS sessions, and bucket metadata in memory so ordinary S3 requests do not query .minio.sys tables on every packet. However, an unbounded or loosely synchronized cache creates a security gap: a revoked credential or deleted policy could remain usable on another gateway for minutes.

This page explains how pgsilo bounds IAM and control-plane cache staleness to 5 seconds, isolates control traffic from slow object streams, validates standby gateways, and prevents split-brain cache renewal after asynchronous PostgreSQL failover (schema 14).

1. Three-pool connection isolation

If S3 object uploads, IAM refreshes, health checks, and LISTEN notifications shared a single database connection pool, a burst of slow 256 MiB uploads could exhaust all connections and starve health checks or credential revocations.

pgsilo splits each gateway’s connection budget (SILO_PG_MAX_CONNS, default 32) into three isolated pools:

PoolDefault sizeConfigurable rangeResponsibilities
Control pool (SILO_PG_CONTROL_CONNS)41–64Atomic IAM snapshot reloads, bucket metadata refreshes, revision polling, and /minio/health/cluster* probes
Coordination pool (SILO_PG_COORD_CONNS)22–64One dedicated LISTEN silo_control_rev connection plus serialized IAM control-plane write transactions
Data pool (MAX - CONTROL - COORD)26>= 2Streaming S3 object reads, writes, multipart uploads, and 2-connection CopyObject reservations

Data-pool saturation never borrows connections from the control or coordination pools.

2. Serialized IAM mutations and atomic snapshot reloads

Silo’s upstream IAMObjectStore loads users, groups, policy mappings, and STS tokens across separate file reads and merges partial maps in memory. Against a shared PostgreSQL database, separate reads could observe a half-applied multi-file IAM update.

pgsilo replaces both sides of the IAM persistence lifecycle:

  • Serialized IAM writes: every administrative IAM mutation acquires a connection from the coordination pool, begins a READ COMMITTED transaction, takes a fixed global IAM transaction advisory lock, performs the compare/merge and silo.sys_files updates inside that single transaction, and bumps silo.sys_revision before COMMIT. If the connection drops, the lock and file mutations roll back together.
  • Single-snapshot IAM reload: when a gateway reloads IAM state, it opens a REPEATABLE READ READ ONLY transaction on the control pool, reads silo.sys_revision and all IAM records from silo.sys_files in one consistent snapshot (bounded by file count and byte limits), decodes the complete identity and policy graph, and swaps the in-memory IAM cache atomically.

3. The 5-second freshness lease

Every gateway enforces a hard 5-second lease on its installed IAM snapshot:

  1. Monotonic start-of-query anchor: the 5-second timer starts at the monotonic wall-clock instant before the gateway sends its database observation query (SELECT revision, revision_token, pg_is_in_recovery() ...), not when a slow query finishes.
  2. 1-second polling + LISTEN/NOTIFY hints: gateways poll silo.sys_revision every 1 second and also subscribe to LISTEN silo_control_rev. A NOTIFY wakes the poller immediately, but notifications are never trusted as a durable stream; listener connect or reconnect always forces a full snapshot reload.
  3. Fail-closed expiration: before authorizing any IAM-dependent S3 or admin request, the middleware checks whether the current snapshot lease is still valid. If the lease has expired and a shared refresh cannot verify database authority within the deadline, the gateway fails closed with HTTP 503 rather than evaluating stale permissions.

4. Physical standby freshness and the 500 ms clock contract

Polling silo.sys_revision on a physical PostgreSQL standby is not sufficient by itself: if streaming replication is paused or lagging by 10 minutes, the standby still returns a valid-looking old revision row.

To bound staleness on read-only standby gateways (SILO_PG_READ_ONLY=on):

  • A writable gateway connected to the primary periodically writes a timestamped authority heartbeat row that replicates through WAL without incrementing silo.sys_revision or triggering full IAM reloads.
  • Primary and standby host clocks must stay synchronized within 500 milliseconds.
  • When a standby gateway polls its replica database, it subtracts (now - heartbeat_timestamp) + 500 ms from the 5-second lease budget. If replication stalls, the primary writable gateway stops, or clock skew exceeds bounds, the standby lease expires within 5 seconds and IAM-authenticated requests fail closed (503).

5. Schema 14: revision_token for divergent failover histories

Testing asynchronous PostgreSQL failover exposed a subtle split-brain edge case with integer revisions:

  1. Suppose the primary is at revision = 42. An administrator revokes a user’s policy (revision = 43), and Gateway A caches revision = 43.
  2. Before WAL for revision = 43 replicates to the standby, the primary crashes and the standby is promoted at revision = 42.
  3. On the newly promoted primary, an unrelated control-plane change (such as creating a bucket) increments revision from 42 to 43.
  4. Gateway A polls the new primary, sees revision = 43 (equal to its cached integer 43), and—if it checked only the integer—would renew its lease while holding a divergent IAM state from the old timeline.

The Schema 14 fix (revision_token):

Schema 14 adds a revision_token uuid column to the singleton silo.sys_revision row, updated by a BEFORE UPDATE trigger to a fresh random UUID (gen_random_uuid()) whenever revision changes.

  • Gateways record (revision, revision_token, in_recovery) alongside every installed IAM snapshot.
  • A poll renews the 5-second lease only if both revision and revision_token match the installed snapshot and in_recovery has not changed.
  • After an asynchronous failover, even if the promoted primary reaches the same integer revision = 43, its revision_token UUID differs, immediately forcing every gateway to discard its old timeline cache and perform a full REPEATABLE READ reload.
Scan to open this page
https://mimus.pgsty.com/docs/s3/design/iam-control-plane/