USE ROLE SECURITYADMIN;
--CREATE ROLE ADMIN_ROLE
CREATE ROLE IF NOT EXISTS ADMIN_ROLE;
GRANT USAGE ON WAREHOUSE ADMIN_WH TO ROLE ADMIN_ROLE;
GRANT ROLE ADMIN_ROLE TO ROLE SYSADMIN;
GRANT USAGE ON DATABASE EXISTING_DB TO ADMIN_ROLE;
GRANT USAGE ON SCHEMA EXISTING_DB.EXISTING_SCHEMA TO ADMIN_ROLE;
GRANT SELECT ON TABLE EXISTING_DB.EXISTING_SCHEMA.MYTABLE TO ADMIN_ROLE;
--CREATE DATA ROLES
CREATE ROLE IF NOT EXISTS USER_ROLE;
GRANT USAGE ON WAREHOUSE USER_WH TO ROLE USER_ROLE;
--USE NEW_DB DATABASE
USE DATABASE NEW_DB;
USE ROLE ADMIN_ROLE;
CREATE SCHEMA IF NOT EXISTS NEW_SCHEMA
GRANT USAGE ON DATABASE NEW_DB TO USER_ROLE;
GRANT USAGE ON SCHEMA NEW_DB.NEW_SCHEMA TO USER_ROLE;
GRANT SELECT ON FUTURE VIEWS IN SCHEMA NEW_DB.NEW_SCHEMA TO USER_ROLE;
CREATE OR REPLACE SECURE VIEW NEW_DB.NEW_SCHEMA.MY_SECURE_VIEW AS SELECT * FROM EXISTING_DB.EXISTING_SCHEMA.MYTABLE
USE ROLE SECURITYADMIN;
GRANT USAGE ON DATABASE EXISTING_DB TO USER_ROLE;
GRANT USAGE ON SCHEMA EXISTING_DB.EXISTING_SCHEMA TO USER_ROLE;
GRANT SELECT ON TABLE EXISTING_DB.EXISTING_SCHEMA.MYTABLE TO USER_ROLE;
REVOKE USAGE ON DATABASE EXISTING_DB FROM ADMIN_ROLE;
REVOKE USAGE ON SCHEMA EXISTING_DB.EXISTING_SCHEMA FROM ADMIN_ROLE;
REVOKE SELECT ON TABLE EXISTING_DB.EXISTING_SCHEMA.MYTABLE FROM ADMIN_ROLE;
CREATE ROLE IF NOT EXISTS TEAM_ROLE;
GRANT ROLE USER_ROLE TO TEAM_ROLE;
USE ROLE TEAM_ROLE;
SELECT * FROM NEW_DB.NEW_SCHEMA.MY_SECURE_VIEW
my use case is very close to this snippet
if I remove
GRANT SELECT ON TABLE EXISTING_DB.EXISTING_SCHEMA.MYTABLE TO ADMIN_ROLE;
I am unable to create the view
if I remove
GRANT SELECT ON TABLE EXISTING_DB.EXISTING_SCHEMA.MYTABLE TO USER_ROLE;
then
SELECT * FROM NEW_DB.NEW_SCHEMA.MY_SECURE_VIEW
fails with the exception
SQL compilation error: Failure during expansion of view 'NEW_DB.NEW_SCHEMA.MY_SECURE_VIEW': SQL compilation error: Object 'EXISTING_DB.EXISTING_SCHEMA.MYTABLE' does not exist or not authorized.
Let me know if the approach has got some basic flaws..