Summary
pg_partman allows a role with partman_user access to request relocation of retained child tables into a schema where that role would not normally have CREATE privileges. Because the background worker performs the operation with its configured role privileges, the authorization boundary may be bypassed and tables may be moved between schemas without proper permission.
Affected context
The issue occurs in pg_partman deployments where the retention configuration supplies a nonempty target schema for partition cleanup operations. It is relevant when drop_partition_id() or drop_partition_time() are invoked through the background worker and that worker operates with privileges greater than those of the requesting partman_user role.
Exploit preconditions
- Attack surface: pg_partman partition-retention functions and their background-worker execution path
- Required access: A database role with
partman_useraccess and the ability to influence or invoke the relevant retention operation - Trigger point: Execution of
drop_partition_id()ordrop_partition_time()using a configured retention schema - Why exploitation is possible: The target schema is accepted when nonempty, while the relocation is performed with background-worker privileges rather than the requesting role's normal authorization context
Why this happens
The underlying flaw is an authorization-context mismatch in schema relocation. pg_partman uses the configured retention_schema as the destination for ALTER TABLE SET SCHEMA without ensuring that the requesting role is authorized to create objects or perform the corresponding relocation in that schema.
This maps to CWE-862: Missing Authorization, because a privileged execution path performs a state-changing database operation without adequately enforcing the permissions that would apply to the initiating role.
Potential impact
- Unauthorized relocation of retained child tables between schemas
- Exposure of tables to users or applications with access to the destination schema
- Disruption of schema-based access-control assumptions
- Possible data governance, isolation, or availability impacts
General mitigation guidance
Mitigation generally focuses on preserving the initiating role's authorization boundary and restricting schema relocation targets.
Common defensive patterns include:
- Enforcing explicit authorization checks for the requesting role before changing table schemas
- Allowing only approved, policy-controlled retention schemas
- Avoiding execution of user-influenced DDL under broad superuser privileges
- Running background workers with the minimum database privileges required
- Separating retention maintenance permissions from general schema-management permissions
- Auditing schema changes and retaining an immutable record of the initiating identity and target schema
How teams detect issues like this
Organizations can detect this class of issue through:
- Static analysis and code review checks for privileged DDL executed on behalf of less-privileged roles
- Review of functions that use configured schema names as dynamic
ALTER TABLE SET SCHEMAtargets - Database audit logging for schema changes performed by background-worker or superuser identities
- Policy checks requiring explicit allowlists for maintenance destinations
- Tests that compare the permissions of the initiating role with those used by asynchronous workers
- Monitoring for unexpected movement of partition child tables across schema boundaries

