A database role can have a number of attributes that define its privileges and interact with the client authentication system.One such attribute is the CREATEROLE attribute, which is important to PostgreSQL database management of users and roles. In this blog post, we will discuss the improvement to this attribute that has been done for PostgreSQL 16.

In previous releases of PostgreSQL, a superuser can grant a non-superuser the CREATEROLE attribute. This is important because it gives the ability to someone other than the superuser to add, drop, and modify users to the database. Unfortunately in previous PostgreSQL versions, when a user is granted the CREATEROLE attribute, it gets the ability to drop users as well that it did not create. 

With PostgreSQL 16, the CREATEROLE attribute still allows a non-superuser the ability to provision new users, however they can only drop users that they themselves created. The system will generate error codes if they try to delete users which they did not create.

In PostgreSQL 15 and older versions

In PostgreSQL 16

In previous releases, a user with the CREATEROLE attribute has access to all predefined system roles, including highly privileged roles like pg_execute_server_program and pg_write_server_files. CREATEROLE also allows them to grant privileges to themself or other users that they haven’t been granted themself.

When providing these roles pg_read_server_files, pg_write_server_files, and pg_execute_server_program to users, extreme caution should be taken because they have access to every file on the server file system, bypass all database-level permission checks when accessing files directly and might be exploited to obtain superuser-level access

So it seems we can expose our systems to risk by granting a user the CREATEROLE privilege. Now the concern is how to deal with the problem mentioned above.

In PostgreSQL 16, users with the CREATEROLE attribute do not  have the ability to grant membership of a role to anyone;  they can only grant membership to roles for which they have the ADMIN OPTION. The WITH ADMIN OPTION clause gives the user the authority to grant membership of a role to other users, to revoke membership of the role from other members of the role.

Let me try to explain this with the help of an example.

In PostgreSQL 15 and older versions:

As per the above example, dev_admin can login from QA_admin whenever he wants and get almost all the privileges to view internal configurations as well as reading and writing the whole database which is not expected at all. This poses a security threat to the whole organisation.

In PostgreSQL 16:

From above it seems that, if pg_execute_server_program, pg_monitor role is assigned to dev_admin user by a super user then only it would be possible to grant that role to QA_admin like below.

The change in CREATEROLE attribute in PostgreSQL 16 is an important improvement to user management because it allows some users the ability to manage all aspects of their team, but not beyond the rights and not outside their own area of responsibility. This gives them just the right amount of control without allowing them to overstep what is required to execute their job.

Percona Distribution for PostgreSQL provides the best and most critical enterprise components from the open-source community, in a single distribution, designed and tested to work together.

 

Download Percona Distribution for PostgreSQL Today!

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments