IAM control plane
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:
| Pool | Default size | Configurable range | Responsibilities |
|---|---|---|---|
Control pool (SILO_PG_CONTROL_CONNS) | 4 | 1–64 | Atomic IAM snapshot reloads, bucket metadata refreshes, revision polling, and /minio/health/cluster* probes |
Coordination pool (SILO_PG_COORD_CONNS) | 2 | 2–64 | One dedicated LISTEN silo_control_rev connection plus serialized IAM control-plane write transactions |
Data pool (MAX - CONTROL - COORD) | 26 | >= 2 | Streaming 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 COMMITTEDtransaction, takes a fixed global IAM transaction advisory lock, performs the compare/merge andsilo.sys_filesupdates inside that single transaction, and bumpssilo.sys_revisionbeforeCOMMIT. 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 ONLYtransaction on the control pool, readssilo.sys_revisionand all IAM records fromsilo.sys_filesin 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:
- 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. - 1-second polling +
LISTEN/NOTIFYhints: gateways pollsilo.sys_revisionevery 1 second and also subscribe toLISTEN silo_control_rev. ANOTIFYwakes the poller immediately, but notifications are never trusted as a durable stream; listener connect or reconnect always forces a full snapshot reload. - 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
503rather 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_revisionor 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 msfrom 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:
- Suppose the primary is at
revision = 42. An administrator revokes a user’s policy (revision = 43), and Gateway A cachesrevision = 43. - Before WAL for
revision = 43replicates to the standby, the primary crashes and the standby is promoted atrevision = 42. - On the newly promoted primary, an unrelated control-plane change (such as creating a bucket) increments
revisionfrom42to43. - Gateway A polls the new primary, sees
revision = 43(equal to its cached integer43), 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
revisionandrevision_tokenmatch the installed snapshot andin_recoveryhas not changed. - After an asynchronous failover, even if the promoted primary reaches the same integer
revision = 43, itsrevision_tokenUUID differs, immediately forcing every gateway to discard its old timeline cache and perform a fullREPEATABLE READreload.
