Snowflake - Privileges required to query snowflake Information schema views - snowflake-cloud-data-platform

I am new to Snowflake. Is it possible to query Information schema views for eg, SCHEMATA, TABLES, COLUMNS for all tables in a snowflake Db without having select access to the underlying tables. The requirement is to create a user/account that only has access to query metadata of the snowflake Db and should not have a select access to the table data. Please advise.

From the Snowflake documentation:
"The output of a view or table function depends on the privileges
granted to the user’s current role. When querying an
INFORMATION_SCHEMA view or table function, only objects for which the
current role has been granted access privileges are returned."
In other words, you won't see the metadata for objects you do not have access to when you query the INFORMATION_SCHEMA views.
To workaround, you can use a role like ACCOUNTADMIN that has permissions to all tables and populate a new table with results from the desired INFORMATION_SCHEMA views. Then give your new role access to that table. You may be able to even setup a task in Snowflake to regularly update the table.
References:
https://docs.snowflake.net/manuals/sql-reference/info-schema.html#general-usage-notes
https://docs.snowflake.net/manuals/user-guide/tasks.html#executing-sql-statements-on-a-schedule-using-tasks

I believe you won't see the object in information schema views. So you required privileges to access the object.

The views in INFORMATION_SCHEMA display metadata about objects defined in the database, as well as metadata for non-database, account-level objects that are common across all databases.
There are 17 views available under INFORMATION_SCHEMA that holds information of Database level objects.
There are 8 views that holds information of Account level objects.
INFORMATION_SCHEMA is a read-only schema available automatically under each database. It stores metadata of all Snowflake objects built under the database.
Running Queries on INFORMATION_SCHEMA requires warehouse to be up and running which incurs Snowflake credits.
The output of a view or table function depend on the privileges granted to the user’s current role. When querying an INFORMATION_SCHEMA view or table function, only objects for which the current role has been granted access privileges are returned.
To use a database's information schema all you need is usage privilege on that database. The role in turn will only see content from the information schema that he/she has access to.

Related

List down all the tables in Snowflake Schema

I have a requirement to list down all the tables created under snowflake schema.
I tried using "Show Tables" and "Information_Schema.Tables", but these only list the tables accessible to me. I need to be able to see the entire list of tables irrespective of the access.
Is there a way I can do it other than Admin access?
You can list all the tables for which you have access privileges - which role(s) that is depends on how you've set up your account
You cannot see any information, even the names, of tables that you do not have access to. This is fundamental to Snowflake's role-based access. Your user must be assigned a role that has the necessary access.

INFORMATION_SCHEMA.TABLES access to all schemas and tables

I am creating a user that should only have access to the database tables metadata,via INFORMATION_SCHEMA, and not the table data. So no perms to query the tables directly. The role the user will be a member of will have USAGE privileges on INFORMATION_SCHEMA schema. I tested the user with that role and it is only able to see tables within public and no where else.
I did see in Snowflake documentation:
"The output of a view or table function depend on the privileges granted to the user’s current role. When querying an INFORMATION_SCHEMA view or table function, only objects for which the current role has been granted access privileges are returned."
So, I tried to grant to the role MONITOR and USAGE on other schemas; but, that did not work either. Only when I granted a role with read access to all the tables in the schema was it able to see and query from INFORMATION_SCHEMA.TABLES the tables in that schema. This, however, is not what I want as now that user would be able to query data from the tables. I just want to set that user to be able to query and gather the metadata of tables and not allow data access. Is there a way in Snowflake to setup and perform this type of setup?
I believe the only way to do this would be to provide access to the SNOWFLAKE.ACCOUNT_USAGE share on Snowflake, which also has TABLES and would allow this user to query the metadata of all tables and columns in that Snowflake account. There is a lot more information available in that share, but at least the user would not have access to any real data, if that is what you are after.

Access rights of stored procedures, views and tables (sql server)

I have a question about the topic access rights of stored procedures, views and tables.
Users can execute stored procedures and views. If the user needs to update data in a view (this view contains only one base table) do I need to define the usergroup update/insert access rights to the table or view? My intention is, that this usergroup shouldn't have access rights to tables directly.
Can anyone explain me the approach about access rights on stored procedures, views and tables or send me a link with an explanation?
If you grant Insert and Update access to the view, the users will be be able to insert/update data from the view. They will not be able to insert/update directly to the table. However, if there are DENY insert/update permnissions on the underlying table, then the insert/update to the view will fail.
Here's a comprehensive link to permissioning.
SQL Server permissions

Understanding access when there is database chaining

I am new to SQL Server database and I am struggling to figure out the access issue for one of the user on a particular view. I don't want to expose any of my base tables.
The scenario is: I have 3 databases, DB one, two and three
Database one has 2 base tables
Database two has one view on top of those tables (tables in database one)
Database three has one view which is on top of the view of database two
Database three is our data warehouse. So, I would like to know if I give select permission on only database three's view, will that suffice?
The catch is I don't want to expose any of my base tables in database one
If I grant select permission to user1 on datawarehouse view (view in database three) and deny all the permissions to the base tables (in database 1), then is it possible?
Thanks
Ownership chaining allows access to data via the view without permissions on the underlying tables as long as all objects are owned by the same security principal. There is no need for an explicit GRANT or DENY on the indirectly used objects with an unbroken ownership chain since permissions are checked only on the directly access view. The object owner is typically inherited from the schema owner.
To allow ownership chaining to extend across multiple database:
The DB_CHAINING database option must be ON for the databases involved.
The user must be able to use the databases (have a user account in each database with CONNECT permissions), although only permissions on directly accessed objects are needed.
In the case of dbo-owned objects, the databases must be owned by the same login (AUTHORIZATION) since the dbo schema owner is the database owner. For other schemas, the schema owner must map to the same login.
DB_CHAINING should be enabled only when you fully trust highly-privileged users (those with permissions to create database objects).

what is the significance of schema name in SQL server

I am new to SQL Server. I connected to SQL server via SQuirrel Client.
Connection URL:
jdbc:sqlserver://192.xx.xx.xx:1433;databaseName=ep
with username & password.
Then I tried a query on table1 in schema1 -
SELECT * from table1
It returned records. I did not mention schema name in query.
There may be possibility of having tables in different sachems (same database) with same name.
Am I right? If yes, then how will it resolve schema name?
Schema work like a namespace in SQL SERVER, you can create tables, views, sps under a schema and set GRANT, DENY, or REVOKE permissions on those objects. From Implementation of Database Object Schemas
SQL Server 2005 implemented the concept of a database object schema. A schema is a distinct namespace to facilitate the separation, management, and ownership of database objects. It removed the tight coupling of database objects and owners to improve the security administration of database objects. Database object schemas offer functionality to control and help secure application objects within a database environment not available in previous versions of SQL Server.
Just wanted to add here, if you have not specified any schema than, it select dbo as schema.
It is distinguished by its owner. Every object (table ,view ,proc) has an owner which must be a user in the database. For example you may have user1.table1 and user2.table2 in the same database.
So you may type
select * from user1.table1
and
select * from user2.table1
You may see names like dbo.table_name, this means that the owner is the dbo, the database owner. If you do not specify an owner then the system checks dbo and your user (the user that run the command)

Resources