How to get an overview of users and roles and their priviliges on Redshift tables

0

Hi, With the following query I am able to see the privileges on schema level and I see there also my configured roles (which are connected with Azure Active Directory groups)

SELECT DISTINCT
       namespace_name as schema,
       privilege_type,
       identity_id,
       identity_type,
       identity_name
FROM svv_schema_privileges
ORDER BY identity_name;

But I would like the same on table(s) level, but here I find only solution where I get the overview of users, not roles. I want to see something like this:

table_name | identity_type | user or role | can select | can insert | can delete | can update

table1 | user | user1 | True | False | False | True table1 | role | aad:group1 | True | True | False | False

Hope you can help me out.

Thanks!

René

Rene
질문됨 5달 전99회 조회
2개 답변
0
수락된 답변

Hello rene,

Below query will provide you user permission ( INSERT, UPDATE, DELETE ) at table level using the HAS_TABLE_PRIVILEGE function - https://docs.aws.amazon.com/redshift/latest/dg/r_HAS_TABLE_PRIVILEGE.html

select * from ( select schemaname ,obj_owner ,obj_type ,objectname ,usename ,has_table_privilege(usrs.usename, fullobj, 'select') as sel ,has_table_privilege(usrs.usename, fullobj, 'insert') as ins ,has_table_privilege(usrs.usename, fullobj, 'update') as upd ,has_table_privilege(usrs.usename, fullobj, 'delete') as del ,has_table_privilege(usrs.usename, fullobj, 'references') as ref from ( select pt.schemaname ,pt.tableowner as obj_owner ,'table' as obj_type ,pt.tablename as objectname ,quote_ident(pt.schemaname) || '.' || quote_ident(pt.tablename) as fullobj from pg_tables pt where pt.schemaname not in ('pg_internal','pg_catalog','information_schema','pg_automv') union select pv.schemaname ,pv.viewowner as obj_owner ,case when position('materialized' in lower(pv.definition)) between 1 and 20 then 'materialized view' else 'view' end as obj_type ,pv.viewname as objectname ,quote_ident(pv.schemaname) || '.' || quote_ident(pv.viewname) as fullobj from pg_views pv where pv.schemaname not in ('pg_internal','pg_catalog','information_schema','pg_automv')
) as objs ,(select * from pg_user) as usrs order by fullobj ) where (sel = true or ins = true or upd = true or del = true or ref = true);

AWS
전문가
답변함 3달 전
profile picture
전문가
검토됨 한 달 전
0

Thanks, this works flawless!!

Rene
답변함 3달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠