Commit 4cfc9484 authored by Peter Eisentraut's avatar Peter Eisentraut

Refine rules for altering publication owner

Previously, the new owner had to be a superuser.  The new rules are more
refined similar to other objects.
Reviewed-by: default avatarPetr Jelinek <petr.jelinek@2ndquadrant.com>
parent 96a7128b
...@@ -48,8 +48,11 @@ ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> DROP TABLE < ...@@ -48,8 +48,11 @@ ALTER PUBLICATION <replaceable class="PARAMETER">name</replaceable> DROP TABLE <
</para> </para>
<para> <para>
To alter the owner, you must also be a direct or indirect member of the To alter the owner, you must also be a direct or indirect member of the new
new owning role. The new owner has to be a superuser owning role. The new owner must have <literal>CREATE</literal> privilege on
the database. Also, the new owner of a <literal>FOR ALL TABLES</literal>
publication must be a superuser. However, a superuser can change the
ownership of a publication while circumventing these restrictions.
</para> </para>
<para> <para>
......
...@@ -670,17 +670,31 @@ AlterPublicationOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId) ...@@ -670,17 +670,31 @@ AlterPublicationOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
if (form->pubowner == newOwnerId) if (form->pubowner == newOwnerId)
return; return;
if (!pg_publication_ownercheck(HeapTupleGetOid(tup), GetUserId())) if (!superuser())
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PUBLICATION, {
NameStr(form->pubname)); AclResult aclresult;
/* New owner must be a superuser */ /* Must be owner */
if (!superuser_arg(newOwnerId)) if (!pg_publication_ownercheck(HeapTupleGetOid(tup), GetUserId()))
ereport(ERROR, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PUBLICATION,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), NameStr(form->pubname));
errmsg("permission denied to change owner of publication \"%s\"",
NameStr(form->pubname)), /* Must be able to become new owner */
errhint("The owner of a publication must be a superuser."))); check_is_member_of_role(GetUserId(), newOwnerId);
/* New owner must have CREATE privilege on database */
aclresult = pg_database_aclcheck(MyDatabaseId, newOwnerId, ACL_CREATE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_DATABASE,
get_database_name(MyDatabaseId));
if (form->puballtables && !superuser_arg(newOwnerId))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to change owner of publication \"%s\"",
NameStr(form->pubname)),
errhint("The owner of a FOR ALL TABLES publication must be a superuser.")));
}
form->pubowner = newOwnerId; form->pubowner = newOwnerId;
CatalogTupleUpdate(rel, &tup->t_self, tup); CatalogTupleUpdate(rel, &tup->t_self, tup);
......
...@@ -182,6 +182,14 @@ ALTER PUBLICATION testpub_default RENAME TO testpub_foo; ...@@ -182,6 +182,14 @@ ALTER PUBLICATION testpub_default RENAME TO testpub_foo;
-- rename back to keep the rest simple -- rename back to keep the rest simple
ALTER PUBLICATION testpub_foo RENAME TO testpub_default; ALTER PUBLICATION testpub_foo RENAME TO testpub_default;
ALTER PUBLICATION testpub_default OWNER TO regress_publication_user2;
\dRp testpub_default
List of publications
Name | Owner | Inserts | Updates | Deletes
-----------------+---------------------------+---------+---------+---------
testpub_default | regress_publication_user2 | t | t | t
(1 row)
DROP PUBLICATION testpub_default; DROP PUBLICATION testpub_default;
DROP PUBLICATION testpib_ins_trunct; DROP PUBLICATION testpib_ins_trunct;
DROP PUBLICATION testpub_fortbl; DROP PUBLICATION testpub_fortbl;
......
...@@ -108,6 +108,10 @@ ALTER PUBLICATION testpub_default RENAME TO testpub_foo; ...@@ -108,6 +108,10 @@ ALTER PUBLICATION testpub_default RENAME TO testpub_foo;
-- rename back to keep the rest simple -- rename back to keep the rest simple
ALTER PUBLICATION testpub_foo RENAME TO testpub_default; ALTER PUBLICATION testpub_foo RENAME TO testpub_default;
ALTER PUBLICATION testpub_default OWNER TO regress_publication_user2;
\dRp testpub_default
DROP PUBLICATION testpub_default; DROP PUBLICATION testpub_default;
DROP PUBLICATION testpib_ins_trunct; DROP PUBLICATION testpib_ins_trunct;
DROP PUBLICATION testpub_fortbl; DROP PUBLICATION testpub_fortbl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment