# Integration with Silo

> Where Silo assumes erasure coding, and why IAM and native authorization both apply.

---

LLMS index: [llms.txt](/llms.txt)

---

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 {#startup-and-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` |
{.wide}

## Guarding the 20 `.(*erasureServerPools)` type assertions {#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 `NotImplemented` at the handler boundary in PostgreSQL mode rather than reaching uninitialized `globalAllHealState` pointers.
- **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 `DeleteBucket` or metrics handlers run.
- **Admin server and storage info (`madmin`)**: `StorageInfo` and `/minio/metrics/v3/pg` report PostgreSQL database usage, logical bucket quotas, and `minio_pg_capacity_known = 0` (`Unknown` exclusive disk capacity in Console) instead of fabricating fake erasure drives.

## `.minio.sys` persistence in `silo.sys_files` {#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`:

1. **Exact prefix-object delete vs. subtree delete**: `deleteConfig` passes `DeletePrefix=true, DeletePrefixObject=true` to delete an exact configuration key without deleting adjacent keys sharing that string prefix (`a` vs. `ab`).
2. **Asynchronous `Walk` for IAM startup**: `IAMObjectStore.listIAMConfigItems` invokes `ObjectLayer.Walk` and reads from the returned channel; `pgsilo` implements ordered prefix walking over `silo.sys_files` (including IAM tombstones) and closes the channel on completion or cancellation.
3. **Read-only standby startup**: on a read-only gateway (`SILO_PG_READ_ONLY=on` or `pg_is_in_recovery() = true`), startup loads existing `.minio.sys` records in read-only mode without writing default configuration files or IAM format markers.

## `SelectObjectContent` multi-seek snapshot consistency {#s3-select-snapshots}

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 {#authz-intersection}

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:

```go
if authz := newGlobalAuthZPluginFn(); authz != nil {
    ok, err := authz.IsAllowed(args)
    return ok
}
```

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**:

1. The request must first pass full S3 IAM evaluation (including explicit `Deny`, bucket policies, service-account restrictions, and STS session policies).
2. 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) in `silo.native_auth_principals` and verifies that the bound PostgreSQL role holds the required privilege (`SELECT`, `INSERT`, `UPDATE`, `DELETE`, or `EXECUTE` on `silo_api.create_bucket`) on the target bucket's `silo_bucket` ACL relation.
3. Both checks must return `allow`; a PostgreSQL `GRANT` never overrides an S3 IAM `Deny`.

---

Backlinks:

- [Design](/docs/s3/design/)
