Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Redshift Grants - New table can't be accessed even though user has grants to all tables in schema

Tags:

I have a bit of a funny situation in Amazon Redshift where I have a user X who has grant select on all tables in schema public, but once a new table is created, this grant doesn't seem to apply to the new table. Is this normal behaviour? If yes, how does one deal with it such that the schema level grants are maintained. Thank you.

like image 336
elvikingo Avatar asked Feb 03 '16 22:02

elvikingo


People also ask

How do you grant access to tables in redshift?

You can use following command, to give select access of specific table to specific user. GRANT SELECT on SCHEMA_NAME. TABLE_NAME TO USER_NAME; NOTE: user still list and describe other tables in the given schema.

How do you check if a user has access to a schema in redshift?

To view the permissions of a specific user on a specific schema, simply change the bold user name and schema name to the user and schema of interest on the following code. For a full list of every user - schema permission status, simply delete the entire WHERE clause. SELECT u. usename, s.

How do you grant SELECT to all tables in a schema?

Grant SELECT on all tables in a schema to a user Unfortunately, Oracle doesn't directly support this using a single SQL statement. To work around this, you can select all table names of a user (or a schema) and grant the SELECT object privilege on each table to a grantee.

How do I create schemas and grant access in AWS Redshift?

If you are new to the AWS RedShift database and need to create schemas and grant access you can use the below SQL to manage this process To create a schema in your existing database run the below SQL and replace

What is Grant command in Amazon Redshift?

Redshift GRANT command is used to control the security and access to the database and its objects for users and groups of users in Amazon Redshift. We can specify the options inside the command as for reading or writing the data from and to the database, tables, columns, schema, procedures, functions or language.

How do I grant privileges to users on Amazon Redshift?

[ WITH GRANT OPTION ] The following is the syntax for using GRANT for datashare privileges on Amazon Redshift. ALTER and SHARE are the only privileges that you can grant to users and user groups in this case. GRANT { ALTER | SHARE } ON DATASHARE datashare_name TO { username [ WITH GRANT OPTION ] | GROUP group_name | PUBLIC } [, ...]

Does access to a schema grant access to its underlying tables?

The following sequence of commands shows how access to a schema doesn't grant privileges on a table in the schema. The following sequence of commands shows how access to a view doesn't imply access to its underlying tables.


2 Answers

Executing the following command as super user (master):

alter default privileges    for user staging_user    in schema staging    grant select on tables    to reporting_user; 

will allow reporting_user to select data from all future tables created by staging_user in schema staging.

like image 146
hibernado Avatar answered Oct 19 '22 23:10

hibernado


In Redshift tables and views do not automatically inherit the permissions of their parent schema. Your newly created tables are only accessible to the user who created them, and the superuser.

In a recent patch to Redshift a new feature to grant default privileges was implemented that addresses this issue.

Alter Default Privileges

The following code snippet will grant select privileges only for all future tables in the sales schema to the sales_admin group. If you want this to apply to existing tables in a schema you will need to combine it with a second grant statement.

alter default privileges in schema sales grant select on tables to group sales_admin; 
like image 20
John Avatar answered Oct 20 '22 00:10

John