Suppose I have queries / views like this:
select
internal.companies._cid,
internal.companies.name,
src1.employees.year,
src1.employees.count
from internal.companies
join src1.employees using (_cid)
In this example, I know that a role will need these privileges:
usage
on schemasinternal
andsrc1
select
on tablesinternal.companies
andsrc1.employees
- and may be
usage
andselect
on any sequences (in case it's aninsert
statement)
I can, of course, browse through all the code and note them down manually. But it will take time. The intention, obviously, is to follow the "least privilege" principle instead of lazily granting all permissions on all tables / schemas.
Is there an automatic way of knowing the exact privileges a role / user would need to run a query successfully?