Integration with Silo
Replacing the newObjectLayer() constructor in Silo is only the first step of integrating a PostgreSQL backend. Although Silo routes object and configuration storage through ObjectLayer, several startup routines, background workers, HTTP handlers, and IAM entry points in cmd/ implicitly assume a distributed erasure-coded (erasureServerPools) deployment.
This page documents the coupling points identified during the Stage 0 source audit and how pgsilo resolves each one without breaking erasure-coded mode.
Startup, DSN parsing, and concurrency budgets
Subsystem in cmd/ | Original erasure-coded assumption | PostgreSQL backend adaptation |
|---|---|---|
Command-line / env argument parsing (server-main.go, common-main.go) | Requires positional disk directory arguments or MINIO_VOLUMES; normalizes arguments as filesystem paths | Detects SILO_PG_DSN or a single postgres:// / postgresql:// URI before disk parsing; rejects mixing disk paths with PostgreSQL mode; redacts DSN passwords from debug output |
Peer RPC grid (grid.go, internal/grid) | Unconditionally initializes peer-to-peer WebSocket grids and distributed lock grids across globalEndpoints | Skips grid and lock-grid initialization when globalIsPGBackend is set; gateways coordinate solely through PostgreSQL transactions and LISTEN/NOTIFY |
Default request concurrency (handler-api.go: apiConfig.init) | When api requests_max <= 0, computes memory limits using slices.Max(setDriveCounts)—which panics on an empty drive-count slice in PostgreSQL mode | Bounds concurrent S3 requests by min(SILO_PG_MAX_CONNS, memlimit / (2 * SILO_PG_SEGMENT_SIZE), api requests_max) coupled with the SILO_PG_QUEUE_TIMEOUT admission queue |
Bucket metadata batch loader (bucket-metadata-sys.go) | Computes batch step as globalEndpoints.ESCount() * 10, causing an infinite 0-step loop when ESCount() == 0 | Enforces max(1, ...) batch sizing so empty and non-empty bucket catalogs load cleanly on startup |
Deployment identity and readiness (erasure-server-pool.go, server-main.go) | Generates deployment UUID inside newErasureServerPools and logs single-drive parity warnings | Persists a stable deployment_id in silo.meta, publishes setObjectLayer after schema check/migration, suppresses erasure parity warnings, and separates /minio/health/cluster/read from /minio/health/cluster |
Guarding the 20 .(*erasureServerPools) type assertions
A static audit of cmd/ found 20 .(*erasureServerPools) type assertions across 9 files (admin-handlers-pools.go, admin-handlers.go, background-newdisks-heal-ops.go, data-usage.go, erasure-multipart-listing.go, global-heal.go, notification.go, peer-rest-server.go, and site-replication.go), plus several non-assertion handlers that reference erasure-only state:
- Pool decommission, rebalance, and drive healing: all pool status, decommission, rebalance, and heal endpoints return
NotImplementedat the handler boundary in PostgreSQL mode rather than reaching uninitializedglobalAllHealStatepointers. - Replication and remote tiering: background replication resync, site replication, and remote tier transition workers are not started in PostgreSQL mode, while global wrapper pointers remain nil-safe when
DeleteBucketor metrics handlers run. - Admin server and storage info (
madmin):StorageInfoand/minio/metrics/v3/pgreport PostgreSQL database usage, logical bucket quotas, andminio_pg_capacity_known = 0(Unknownexclusive disk capacity in Console) instead of fabricating fake erasure drives.
.minio.sys persistence in silo.sys_files
Silo stores server configuration (config.json and configuration history), IAM users/groups/policies/service accounts, and per-bucket metadata (.minio.sys/buckets/<bucket>/.metadata.bin) as objects inside the reserved .minio.sys bucket.
In PostgreSQL mode, operations on .minio.sys route to silo.sys_files:
- Exact prefix-object delete vs. subtree delete:
deleteConfigpassesDeletePrefix=true, DeletePrefixObject=trueto delete an exact configuration key without deleting adjacent keys sharing that string prefix (avs.ab). - Asynchronous
Walkfor IAM startup:IAMObjectStore.listIAMConfigItemsinvokesObjectLayer.Walkand reads from the returned channel;pgsiloimplements ordered prefix walking oversilo.sys_files(including IAM tombstones) and closes the channel on completion or cancellation. - Read-only standby startup: on a read-only gateway (
SILO_PG_READ_ONLY=onorpg_is_in_recovery() = true), startup loads existing.minio.sysrecords in read-only mode without writing default configuration files or IAM format markers.
SelectObjectContent multi-seek snapshot consistency
In Silo’s SelectObjectContentHandler, the handler first calls GetObjectInfo to inspect the object and then passes a NewObjectReadSeekCloser to the S3 Select engine (especially for Parquet and CSV streams), which invokes GetObjectNInfo repeatedly across seek callbacks without pinning a VersionID.
On an erasure-coded cluster, an in-process read lock prevents local overwrites during the query. In PostgreSQL mode, however, another gateway or a silo_api SQL transaction can overwrite the key or replace a null version between seeks. To prevent S3 Select from splicing bytes from two different object generations, pgsilo pins a single REPEATABLE READ READ ONLY transaction snapshot before the initial metadata lookup and reuses that snapshot across all subsequent seek callbacks until the request closes.
Why iam_and_pg cannot use globalAuthZPlugin directly
Early architecture notes proposed implementing PostgreSQL native authorization (iam_and_pg) by registering an in-process globalAuthZPlugin. Auditing cmd/iam.go (IAMSys.IsAllowed) revealed a critical security flaw with that approach:
When globalAuthZPlugin is non-nil, IAMSys.IsAllowed short-circuits and returns the plugin’s boolean immediately—skipping built-in owner checks, service-account parent and inline policy intersections (IsAllowedServiceAccount), STS session policy restrictions (IsAllowedSTS), and explicit IAM Deny statements.
To preserve full S3 IAM semantics, pgsilo evaluates PostgreSQL native role privileges as an additional AND gate after built-in IAM evaluation succeeds:
- The request must first pass full S3 IAM evaluation (including explicit
Deny, bucket policies, service-account restrictions, and STS session policies). - When
silo.set_native_auth_mode('iam_and_pg')is active, the gateway resolves the authenticated S3 principal (or the parent IAM user for a service account / STS token) insilo.native_auth_principalsand verifies that the bound PostgreSQL role holds the required privilege (SELECT,INSERT,UPDATE,DELETE, orEXECUTEonsilo_api.create_bucket) on the target bucket’ssilo_bucketACL relation. - Both checks must return
allow; a PostgreSQLGRANTnever overrides an S3 IAMDeny.
