SQL API design
The public silo_api SQL interface and silo_bucket ACL relations are Preview features in the MVP release.
Storing objects inside PostgreSQL unlocks a capability that external object stores cannot provide: applications can read, write, copy, and delete S3 objects inside the same Read Committed SQL transaction as ordinary relational tables. This page explains how pgsilo exposes that SQL interface without compromising the internal version state machine or tenant isolation.
Three-schema separation (silo, silo_api, silo_bucket)
Early design drafts placed public SQL functions directly in the silo schema. Implementation reviews separated the database surface into three schemas:
| Schema | Purpose | Access policy |
|---|---|---|
silo | Private storage tables (buckets, objects, object_segments, sys_files, bucket_acl) and internal SECURITY INVOKER state-machine helpers (commit_version, delete_version, lock_key) | Owned by silo_owner; REVOKE ALL FROM PUBLIC; never granted to application roles |
silo_api | The 11 public SECURITY DEFINER functions (put_object, get_object, read_object, stat_object, list_objects, delete_object, copy_object, create_bucket, bucket_info, list_buckets, drop_bucket) | REVOKE ALL FROM PUBLIC at creation; administrators explicitly GRANT USAGE and per-function EXECUTE to application SQL logins |
silo_bucket | Per-bucket ACL relations (silo_bucket.b_<bucket_id>) created automatically when a bucket is created | Non-updatable security_barrier views carrying SELECT, INSERT, UPDATE, and DELETE grants |
Public silo_api functions return flat RETURNS TABLE (...) columns or bytea rather than composite types from silo.*, so application roles never need USAGE on the private silo schema.
Per-bucket ACL relations (silo_bucket.b_<bucket_id>)
Why represent bucket permissions with a view named b_<bucket_id> in silo_bucket?
- Identifier length and collision safety: S3 bucket names can be up to 63 bytes (and internal table columns allow up to 255 bytes) with dots and hyphens, whereas PostgreSQL identifiers are capped at 63 bytes (
NAMEDATALEN - 1). Naming the relationsilo_bucket.b_<bucket_id>avoids truncation collisions whilesilo.bucket_aclmaps each immutablebucket_idto its exactrelation_oid(regclass). - Non-updatable
security_barrierviews: eachsilo_bucket.b_<bucket_id>view is asecurity_barrier = truejoin oversilo.objectsandsilo.bucketswithoutINSTEAD OFtriggers. GrantingINSERTorDELETEon the view serves purely as an authorization bit checked viahas_table_privilege(session_user_oid, relation_oid, priv) IS TRUE; an application role cannot execute rawINSERT,UPDATE, orDELETEstatements against the view to bypass the version state machine. - Clean lifecycle on bucket recreation: dropping a bucket drops its
silo_bucket.b_<bucket_id>view in the same transaction. Recreating a bucket with the same name allocates a newbucket_idand a new ACL relation with no stale grants carried over.
Caller identity (session_user) and SECURITY DEFINER hardening
Inside a SECURITY DEFINER function, current_user and current_role resolve to the function owner (silo_owner), not the caller. Checking privileges against current_user would grant every caller full owner access.
To prevent privilege escalation:
- Fixed
session_userprincipal: everysilo_apientry point authenticatessession_user(resolved to its role OID) and explicitly verifieshas_function_privilege(session_user_oid, '<function_signature>'::regprocedure, 'EXECUTE') IS TRUE. - Rejecting
SET ROLEand owner logins: ifcurrent_setting('role')is not'none', or ifsession_useris the installation owner (silo_owner) or a member of it, the function rejects the call withSQLSTATE 42501. An unprivileged user cannot wrap asilo_apicall inside their ownSECURITY DEFINERfunction or useSET ROLEto impersonate another role. - Locked
search_path: allsilo_apifunctions setsearch_path = pg_catalog, pg_tempand schema-qualify every table, function, and operator reference so user-created objects inpg_temporpubliccannot hijack execution. - Immediate
REVOKEvisibility: cached PL/pgSQL plans do not always process PostgreSQL catalog invalidation messages before evaluatinghas_table_privilege. Everysilo_apicall first runs a lightweight dynamicEXECUTE 'SELECT 1 FROM silo.meta LIMIT 0'to force syscache invalidation acceptance, ensuring a committedREVOKEtakes effect on the very next statement.
Transactional semantics and synchronized bucket policies
Read Committedwrite contract:put_object,delete_object,copy_object,create_bucket, anddrop_bucketrequireRead Committedisolation. UnderRepeatable ReadorSerializable, a transaction waiting onsilo.lock_keywould still see its pre-lock snapshot and miss a concurrent latest version; write functions therefore reject higher isolation levels withSQLSTATE 0A000.- Deadlock-safe
copy_object:silo_api.copy_objectacquiresFOR SHAREon the source and destination bucket rows in ascendingbucket_idorder, reads the source metadata, segments, and annotations from a single snapshot without holding a source key lock across the destination write, and publishes the destination version atomically. - Policy synchronization (
policy_ready): S3 stores bucket configuration in.minio.sys/buckets/<bucket>/.metadata.bin, while SQL functions inspect structured columns onsilo.buckets(versioning,object_lock,default_sse,policy_ready). Whenever a gateway updates.metadata.bin, it decodes and updates those structured columns in the sameFOR UPDATEtransaction. SQL write functions requirepolicy_ready = true, enforce default Object Lock retention and hard bucket quotas, and reject plaintext writes to buckets with default SSE enabled.
