Search code examples
postgresqlroles

Granting rolegroup to role did not inherit the config from rolegroup in postgres


We have a scenario where some users would need super user permissions and other db users dont need it. So we have create the users and then created a role 'SuperRole' which has permissions to create role, db.

Let's say I have user 'User1' mapped to role 'User1' by default with INHERIT. After creating 'SuperRole' role I have ran

GRANT superrole to user1;

After this if I see \du output

postgres=# \du user1
                    List of roles
  Role name   |       Attributes       |  Member of
--------------+------------------------+--------------
 user1        | Create role, Create DB | {superrole}

As per the documentation https://www.postgresql.org/docs/11/role-membership.html the privileges of role 'member of' should also be inherited. But when i connect to psql with user1, I should be having the privileges of superrole also to create role and db. However when I try to create a db I am getting the below error.

postgres=> create database test;
ERROR:  permission denied to create database

The similar error shows for creating role as well. What should be done to make the privileges set for superrole to be available for user1 as well.


Solution

  • The role attributes LOGIN, SUPERUSER, CREATEDB, and CREATEROLE can be thought of as special privileges, but they are never inherited as ordinary privileges on database objects are. You must actually SET ROLE to a specific role having one of these attributes in order to make use of the attribute.

    refer: https://www.postgresql.org/docs/current/role-membership.html