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:
This new feature all privileges granted to the schema are automatically granted to all newly created tables or views in the schema.
Note:
Existing tables or views remain unchanged when you alter the schema to include or exclude inherited privileges.
Not be able to apply inherited privileges you need be the owner of the schema or a superuser.
Below is full step by step example of inheritance works:
We will create a new schema called no_grants and put one table in it. Next create a new user.
Login with the new user.
Try to query the new table.
make sense the error since we havent granted anything to the new user.
Now lets alter the schema definition and enable inheritance using the "include privileges" option and add a new table.
Try to query the secound table, and we can see that even no direct grant to the table was given to the user he is able to query the table.
this is because of the inheritance we enabled on schema level in combination with the USAGE + SELECT grant on schema granted to the user.
Run this as user_nograt.
Now try to query the old table logged as user_nograt and see we get an error due to permission fault.
the reason for this is that even thou we have applied the inheritance at the schema level the inheritance it will only apply to new objects and will omit the existing objects.
To fix this we need to alter each object in the database using the following syntax:
Now the user can query the table.
Looking at the grants table we can see that we only have entries for the schema granted privileges:
Also there is no reference in the v_catalog.tables system table about the inheritance parameter, if is enabled or disabled.
But there is a way for you find and list the tables that have inheritance enabled, the table is vs_tables.
Now to make your life a bit easier when trying to implement inheritance use the below script to pickup the present tables and views and alter their definition to apply schema privilege inheritance.
Note:
replace the $Schema_Name$ with the schema of your choice.
Also we can revoke and inherited privilege for a single object that resides in a schema that has inheritance enabled.
To see if the privileges were excluded you can use the query below :
Or try to query the table:
Hope this was helpful !