Starting with Vertica version 7.2.x HP Vertica comes with a great feature called Inheritance, this concept is similar to SQL Server schema roles that will dynamic propagate the privileges across all objects in the schema and associate them with the users that have access to this schema roles.
Thanks HP for implementing this as it makes my life much more easy when dealing with new objects and access rules.
So lets dive in and see what is this all about.
To Enable or Disable Inherited Privileges at Database Level use the syntax below:
-- Enable
ALTER DATABASE database_name SET disableinheritedprivileges = 0;
-- Disable
ALTER DATABASE database_name SET disableinheritedprivileges = 1;
create schema no_grants;
create table no_grants.mytab(id int);
create user user_nograt identified by 'bla';
dbadmin= c - user_nograt
Password:
You are now connected as user "user_nograt".
dbadmin= select * from no_grants.mytab;
ERROR 3580: Insufficient privilege: USAGE on SCHEMA 'no_grants' not granted for current user
alter schema no_grants default include privileges;
-- grant select to user
grant select on schema no_grants to user_nograt;
-- grant usage on schema to user
grant usage on schema no_grants to user_nograt;
-- and create a new table
create table no_grants.mytab2(id int);
dbadmin= select * from no_grants.mytab2;
id
----
(0 rows)
dbadmin= select * from no_grants.mytab;
ERROR 4367: Permission denied for relation mytab
alter table no_grants.mytab include schema privileges;
dbadmin= select * from no_grants.mytab;
id
----
(0 rows)
select grantor,privileges_description,object_name,grantee from grants where grantee='user_nograt';
grantor privileges_description object_name grantee
------- ---------------------- ----------- -----------
dbadmin SELECT, USAGE no_grants user_nograt
select name,tb.table_schema,inheritprivileges
from vs_tables vtb join tables tb
on tb.table_schema_id =vtb.schema
where vtb.inheritprivileges='true' ;
name table_schema inheritprivileges
------ ------------ -----------------
mytab no_grants true
mytab no_grants true
mytab2 no_grants true
mytab2 no_grants true
select 'ALTER SCHEMA '||'$Schema_Name$'||' DEFAULT INCLUDE PRIVILEGES;' from dual
union all
select 'ALTER TABLE '||table_schema||'.'||table_name||' INCLUDE SCHEMA PRIVILEGES;' from tables
where table_schema='$Schema_Name$'
union all
select 'ALTER view '||table_schema||'.'||table_name||' INCLUDE SCHEMA PRIVILEGES;' from views
where table_schema='$Schema_Name$';
alter table no_grants.mytab exclude schema privileges;
or
alter view no_grants.v_mytab exclude schema privileges;
select name,tb.table_schema,inheritprivileges
from vs_tables vtb join tables tb
on tb.table_schema_id =vtb.schema
where vtb.inheritprivileges='true' and tb.table_schema='no_grants';
grantor privileges_description object_name grantee
------- ---------------------- ----------- -----------
dbadmin USAGE general user_nograt
dbadmin SELECT, USAGE no_grants user_nograt
badmin= select * from no_grants.mytab;
ERROR 4367: Permission denied for relation mytab
Uppsss.....