From f1358ca52dd7b8cedd29c6f2f8c163914f03ea2e Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 24 Jan 2023 10:57:09 -0500 Subject: Adjust interaction of CREATEROLE with role properties. Previously, a CREATEROLE user without SUPERUSER could not alter REPLICATION users in any way, and could not set the BYPASSRLS attribute. However, they could manipulate the CREATEDB property even if they themselves did not possess it. With this change, a CREATEROLE user without SUPERUSER can set or clear the REPLICATION, BYPASSRLS, or CREATEDB property on a new role or a role that they have rights to manage if and only if that property is set for their own role. This implements the standard idea that you can't give permissions you don't have (but you can give the ones you do have). We might in the future want to provide more powerful ways to constrain what a CREATEROLE user can do - for example, to limit whether CONNECTION LIMIT can be set or the values to which it can be set - but that is left as future work. Patch by me, reviewed by Nathan Bossart, Tushar Ahuja, and Neha Sharma. Discussion: http://postgr.es/m/CA+TgmobX=LHg_J5aT=0pi9gJy=JdtrUVGAu0zhr-i5v5nNbJDg@mail.gmail.com --- doc/src/sgml/ref/alter_role.sgml | 13 ++++++++----- doc/src/sgml/ref/create_role.sgml | 23 ++++++----------------- 2 files changed, 14 insertions(+), 22 deletions(-) (limited to 'doc') diff --git a/doc/src/sgml/ref/alter_role.sgml b/doc/src/sgml/ref/alter_role.sgml index fbb4612e70..ff2b88e9b6 100644 --- a/doc/src/sgml/ref/alter_role.sgml +++ b/doc/src/sgml/ref/alter_role.sgml @@ -70,11 +70,14 @@ ALTER ROLE { role_specification | A REVOKE for that.) Attributes not mentioned in the command retain their previous settings. Database superusers can change any of these settings for any role. - Roles having CREATEROLE privilege can change any of these - settings except SUPERUSER, REPLICATION, - and BYPASSRLS; but only for non-superuser and - non-replication roles for which they have been - granted ADMIN OPTION. + Non-superuser roles having CREATEROLE privilege can + change most of these properties, but only for non-superuser and + non-replication roles for which they have been granted + ADMIN OPTION. Non-superusers cannot change the + SUPERUSER property and can change the + CREATEDB, REPLICATION, and + BYPASSRLS properties only if they possess the + corresponding property themselves. Ordinary roles can only change their own password. diff --git a/doc/src/sgml/ref/create_role.sgml b/doc/src/sgml/ref/create_role.sgml index 7ce4e38b45..c101df6e2f 100644 --- a/doc/src/sgml/ref/create_role.sgml +++ b/doc/src/sgml/ref/create_role.sgml @@ -109,6 +109,8 @@ in sync when changing the above synopsis! NOCREATEDB will deny a role the ability to create databases. If not specified, NOCREATEDB is the default. + Only superuser roles or roles with CREATEDB + can specify CREATEDB. @@ -188,8 +190,8 @@ in sync when changing the above synopsis! highly privileged role, and should only be used on roles actually used for replication. If not specified, NOREPLICATION is the default. - You must be a superuser to create a new role having the - REPLICATION attribute. + Only superuser roles or roles with REPLICATION + can specify REPLICATION. @@ -201,8 +203,8 @@ in sync when changing the above synopsis! These clauses determine whether a role bypasses every row-level security (RLS) policy. NOBYPASSRLS is the default. - You must be a superuser to create a new role having - the BYPASSRLS attribute. + Only superuser roles or roles with BYPASSRLS + can specify BYPASSRLS. @@ -390,19 +392,6 @@ in sync when changing the above synopsis! specified in the SQL standard. - - Be careful with the CREATEROLE privilege. There is no concept of - inheritance for the privileges of a CREATEROLE-role. That - means that even if a role does not have a certain privilege but is allowed - to create other roles, it can easily create another role with different - privileges than its own (except for creating roles with superuser - privileges). For example, if the role user has the - CREATEROLE privilege but not the CREATEDB privilege, - nonetheless it can create a new role with the CREATEDB - privilege. Therefore, regard roles that have the CREATEROLE - privilege as almost-superuser-roles. - - PostgreSQL includes a program that has -- cgit v1.2.3