Honor inherited ownership when finishing prepared transactions
Honor inherited ownership when finishing prepared transactions
От:
Kirill Reshke <reshkekirill@gmail.com>
Дата:
Recently started to use 2pc support in SPQR [0] for transactions that need to modify data on several postgres(shards). So, for partially committed 2pc we have a separate watchdog which finishes all half-done transactions. And we want a separate role for this watchdog. But this just fails to finish transactions that were prepared. The reason is a two phase check that compares user oid with tx owner oid with ==. This was the original security restriction from [1] (valid at time), but didn't change after [2]. Before [2], server had logic that only user himself can do something with his object, for example dropping the table was ONLY for owner. After [2], it use role membership etc. So, can we use same in 2pc (prepared) tx? Is [1] sec restriction still true? I have simple patch for this, didn't posted yet, want to hear back [1]Discussion: https://www.postgresql.org/message-id/15495.1097685302@sss.pgh.pa.us [2]Discussion: https://www.postgresql.org/message-id/26627.1119985659@sss.pgh.pa.us [0] https://github.com/pg-sharding/spqr -- Best regards, Kirill Reshke
Re: Honor inherited ownership when finishing prepared transactions
От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
Hi Kirill, On November 2, 2026, Kirill Reshke wrote: > So, can we use same in 2pc (prepared) tx? I agree that prepared transactions should follow the same inherited ownership rules as other objects. has_privs_of_role() seems the right check, including INHERIT TRUE, SET FALSE. In the roles discussion you linked, Tom explicitly suggested retaining this check. I think it is worth revisiting that decision. One implementation detail. LockGXact() currently checks ownership while holding TwoPhaseStateLock. Membership expansion can read pg_auth_members and acquire a relation lock on a cache miss. Could we reserve the GXACT, release the LWLock, then check permission, using the existing abort cleanup if permission is denied? Could you post the patch? Thank you! Best regards, Andrey Borodin.
Re: Honor inherited ownership when finishing prepared transactions
On Mon, 9 Nov 2026 at 15:30, Andrey Borodin wrote: > > Hi Kirill, > > On November 2, 2026, Kirill Reshke wrote: > > So, can we use same in 2pc (prepared) tx? > > I agree that prepared transactions should follow the same inherited > ownership rules as other objects. has_privs_of_role() seems the right > check, including INHERIT TRUE, SET FALSE. > > In the roles discussion you linked, Tom explicitly suggested retaining > this check. I think it is worth revisiting that decision. Sure. Maybe it was some sort of safety measure back then - but I don't get the exact vulnerability. > One implementation detail. LockGXact() currently checks ownership while > holding TwoPhaseStateLock. Membership expansion can read pg_auth_members > and acquire a relation lock on a cache miss. Could we reserve the GXACT, > release the LWLock, then check permission, using the existing abort > cleanup if permission is denied? > > Could you post the patch? > > Thank you! > > > Best regards, Andrey Borodin. > PFA -- Best regards, Kirill Reshke
Re: Honor inherited ownership when finishing prepared transactions
От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
Hi Kirill, I verified that a blocked role check does not hold TwoPhaseStateLock. After cancellation, another session can still finish the prepared transaction. So the problem I expected seems to be solved. On 9 Nov 2026, Kirill Reshke wrote: > SET ROLE regress_prepare_setonly; > SET ROLE regress_prepare_owner; session_user is still the regression superuser, so the second SET ROLE does not check the member's SET permission. Maybe use SET SESSION AUTHORIZATION instead? Thank you! Best regards, Andrey Borodin.