Reputation: 45
I am trying to create an admin role/user in PostgreSQL which should fulfil the following requirements:
This is what I have so far:
create role dba with nosuperuser createdb createrole nologin replication bypassrls;
grant usage on schema public to dba;
alter default privileges in schema public grant all on tables to dba;
alter default privileges in schema public grant all on sequences to dba;
grant connect on database myDatabase to dba;
grant usage on schema public to dba;
grant select on all tables in schema public to dba;
grant select on all sequences in schema public to dba;
grant all privileges on all tables in schema public to dba;
create user dba_user login inherit encrypted password 'password' in role dba;
Please advise how to modify the above code to fulfill the requirements.
Upvotes: 0
Views: 5456
Reputation: 246493
To achieve that, perform the following modifications:
Transfer ownership of the database and all schemas and objects in it to the new user.
Give the user CREATEROLE
.
Make sure to REVOKE CONNECT ON
all databases FROM PUBLIC
. Grant the new user the CONNECT
privilege on the database in question.
Don't give the new user any permissions on other databases or objects therein.
Upvotes: 1