mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Perform logical replication actions as the table owner.
Up until now, logical replication actions have been performed as the
subscription owner, who will generally be a superuser. Commit
cec57b1a0f
documented hazards
associated with that situation, namely, that any user who owns a
table on the subscriber side could assume the privileges of the
subscription owner by attaching a trigger, expression index, or
some other kind of executable code to it. As a remedy, it suggested
not creating configurations where users who are not fully trusted
own tables on the subscriber.
Although that will work, it basically precludes using logical
replication in the way that people typically want to use it,
namely, to replicate a database from one node to another
without necessarily having any restrictions on which database
users can own tables. So, instead, change logical replication to
execute INSERT, UPDATE, DELETE, and TRUNCATE operations as the
table owner when they are replicated.
Since this involves switching the active user frequently within
a session that is authenticated as the subscription user, also
impose SECURITY_RESTRICTED_OPERATION restrictions on logical
replication code. As an exception, if the table owner can SET
ROLE to the subscription owner, these restrictions have no
security value, so don't impose them in that case.
Subscription owners are now required to have the ability to
SET ROLE to every role that owns a table that the subscription
is replicating. If they don't, replication will fail. Superusers,
who normally own subscriptions, satisfy this property by default.
Non-superusers users who own subscriptions will need to be
granted the roles that own relevant tables.
Patch by me, reviewed (but not necessarily in its entirety) by
Jelte Fennema, Jeff Davis, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoaSCkg9ww9oppPqqs+9RVqCexYCE6Aq=UsYPfnOoDeFkw@mail.gmail.com
This commit is contained in:
@ -1729,19 +1729,6 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER
|
||||
<sect1 id="logical-replication-security">
|
||||
<title>Security</title>
|
||||
|
||||
<para>
|
||||
A user able to modify the schema of subscriber-side tables can execute
|
||||
arbitrary code as the role which owns any subscription which modifies those tables. Limit ownership
|
||||
and <literal>TRIGGER</literal> privilege on such tables to trusted roles.
|
||||
Moreover, if untrusted users can create tables, use only
|
||||
publications that list tables explicitly. That is to say, create a
|
||||
subscription
|
||||
<link linkend="sql-createpublication-for-all-tables"><literal>FOR ALL TABLES</literal></link>
|
||||
or <link linkend="sql-createpublication-for-tables-in-schema"><literal>FOR TABLES IN SCHEMA</literal></link>
|
||||
only when superusers trust every user permitted to create a non-temp table
|
||||
on the publisher or the subscriber.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The role used for the replication connection must have
|
||||
the <literal>REPLICATION</literal> attribute (or be a superuser). If the
|
||||
@ -1784,12 +1771,18 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To create a subscription, the user must be a superuser.
|
||||
To create a subscription, the user must have the privileges of the
|
||||
the <literal>pg_create_subscription</literal> role, as well as
|
||||
<literal>CREATE</literal> privileges on the database.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The subscription apply process will run in the local database with the
|
||||
privileges of the subscription owner.
|
||||
The subscription apply process will, at a session level, run with the
|
||||
privileges of the subscription owner. However, when performing an insert,
|
||||
update, delete, or truncate operation on a particular table, it will switch
|
||||
roles to the table owner and perform the operation with the table owner's
|
||||
privileges. This means that the subscription owner needs to be able to
|
||||
<literal>SET ROLE</literal> to each role that owns a replicated table.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
Reference in New Issue
Block a user