1

I am trying to set up RBAC in Postgres where I have a database and a schema. I have a few roles provisioner, service, mydb_ro, and mydb_rw. I ran the following to change default privileges

ALTER DEFAULT PRIVILEGES FOR ROLE provisioner IN SCHEMA mydb_schema
 GRANT SELECT ON TABLES TO mydb_ro; -- only read
ALTER DEFAULT PRIVILEGES FOR ROLE provisioner IN SCHEMA mydb_schema
 GRANT INSERT, UPDATE, DELETE, TRUNCATE ON TABLES TO mydb_rw; -- + write, TRUNCATE optional
ALTER DEFAULT PRIVILEGES FOR ROLE provisioner IN SCHEMA mydb_schema
 GRANT REFERENCES, TRIGGER ON TABLES TO mydb_rw; -- + TRIGGER
ALTER DEFAULT PRIVILEGES FOR ROLE provisioner IN SCHEMA mydb_schema
 GRANT USAGE, SELECT, UPDATE ON SEQUENCES TO mydb_rw; -- SELECT, UPDATE are optional
ALTER DEFAULT PRIVILEGES FOR ROLE provisioner IN SCHEMA mydb_schema
 GRANT EXECUTE ON FUNCTIONS TO mydb_rw;

this is what I see in default privileges

postgres@mydb=> \ddp
 Default access privileges
┌─────────────┬──────────────────┬──────────┬─────────────────────────────────┐
│ Owner │ Schema │ Type │ Access privileges │
├─────────────┼──────────────────┼──────────┼─────────────────────────────────┤
│ provisioner │ mydb_schema │ function │ mydb_rw=X/provisioner │
│ provisioner │ mydb_schema │ sequence │ mydb_rw=rwU/provisioner │
│ provisioner │ mydb_schema │ table │ mydb_ro=r/provisioner ↵│
│ │ │ │ mydb_rw=awdDxt/provisioner │
└─────────────┴──────────────────┴──────────┴─────────────────────────────────┘

But when I am logged in as a user that has the provisioner role and I create a table, a user that has service role cannot see it. What am I doing wrong?

I now ran

GRANT mydb_ro TO mydb_rw;
GRANT mydb_rw TO service;

But that did not help with the permission issue.

Paul White
95.3k30 gold badges439 silver badges689 bronze badges
asked Aug 26, 2020 at 14:13
0

1 Answer 1

3

Having the 'provisioner' role is not the same thing as being 'provisioner'.

For your shown default permission to apply, you would have to create the object as 'provisioner' (for example, SET ROLE provisioner; before you create the objects)

answered Aug 27, 2020 at 13:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.