pgsql: Perform logical replication actions as the table owner.

Поиск
Список
Период
Сортировка
От Robert Haas
Тема pgsql: Perform logical replication actions as the table owner.
Дата
Msg-id E1pjj4n-001LNj-Bl@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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
cec57b1a0fbcd3833086ba686897c5883e0a2afc 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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1e10d49b65d6c26c61fee07999e4cd59eab2b765

Modified Files
--------------
doc/src/sgml/logical-replication.sgml      |  25 ++---
src/backend/commands/tablecmds.c           |  20 +++-
src/backend/replication/logical/worker.c   |  22 +++-
src/backend/utils/init/Makefile            |   3 +-
src/backend/utils/init/meson.build         |   3 +-
src/backend/utils/init/usercontext.c       |  92 ++++++++++++++++
src/include/commands/tablecmds.h           |   3 +-
src/include/utils/usercontext.h            |  26 +++++
src/test/subscription/t/027_nosuperuser.pl | 165 ++++++++++++++---------------
9 files changed, 250 insertions(+), 109 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: Add missing XML ID attributes
Следующее
От: Robert Haas
Дата:
Сообщение: pgsql: Add a run_as_owner option to subscriptions.