If Hunters runs on your own Snowflake account (Snowflake Partner Connect), a custom SQL enrichment runs as a read-only role. That role can only read the tables and views of the RAW schema of your Hunters database. It cannot change data, create objects, or read any other schema or database.
Hunters cannot create roles in your account, so your Snowflake admin creates this role once, with the script below. Until then, the AI builder cannot test a custom SQL enrichment on your data, and the Portal links to this page.
Before you start
- You need the
ACCOUNTADMINrole, or another role that can create roles and grant privileges. - The script uses the names that Snowflake Partner Connect creates: the database
PC_HUNTERS_DB, the warehousePC_HUNTERS_WHand the userPC_HUNTERS_USER. If yours are named differently, replace them everywhere in the script. - If Hunters has more than one database in your account, for example
PC_HUNTERS_DB_SALESandPC_HUNTERS_DB_SUPPORT, run the script once for each database. Each time, replacePC_HUNTERS_DBwith the name of the database. The role is then named after that database, for examplePC_HUNTERS_DB_SALES_READONLY.
Step 1: keep your own roles' access to new tables
In Snowflake, future grants on a schema take precedence over future grants on its database. Step 2 adds a future grant on the RAW schema. If your own roles read new tables of the database through future grants on the database, copy those grants to the RAW schema first. Otherwise, your roles stop seeing tables that Hunters adds later.
USE ROLE ACCOUNTADMIN;
SHOW FUTURE GRANTS IN SCHEMA PC_HUNTERS_DB.RAW;
- If this lists any rows, go to step 2.
- If it lists no rows, run:
SHOW FUTURE GRANTS IN DATABASE PC_HUNTERS_DB;
For each row whose grant_on is TABLE, VIEW or ICEBERG_TABLE, run the same grant on the RAW schema. Use the row's privilege and grantee_name, for example:
GRANT SELECT ON FUTURE TABLES IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE <grantee_name>;
GRANT SELECT ON FUTURE VIEWS IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE <grantee_name>;
GRANT SELECT ON FUTURE ICEBERG TABLES IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE <grantee_name>;
Step 2: create the read-only role
USE ROLE ACCOUNTADMIN;
CREATE ROLE IF NOT EXISTS PC_HUNTERS_DB_READONLY;
GRANT USAGE ON WAREHOUSE PC_HUNTERS_WH TO ROLE PC_HUNTERS_DB_READONLY;
GRANT USAGE ON DATABASE PC_HUNTERS_DB TO ROLE PC_HUNTERS_DB_READONLY;
GRANT USAGE ON SCHEMA PC_HUNTERS_DB.RAW TO ROLE PC_HUNTERS_DB_READONLY;
GRANT SELECT ON ALL TABLES IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE PC_HUNTERS_DB_READONLY;
GRANT SELECT ON ALL VIEWS IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE PC_HUNTERS_DB_READONLY;
GRANT SELECT ON ALL ICEBERG TABLES IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE PC_HUNTERS_DB_READONLY;
GRANT SELECT ON FUTURE TABLES IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE PC_HUNTERS_DB_READONLY;
GRANT SELECT ON FUTURE VIEWS IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE PC_HUNTERS_DB_READONLY;
GRANT SELECT ON FUTURE ICEBERG TABLES IN SCHEMA PC_HUNTERS_DB.RAW TO ROLE PC_HUNTERS_DB_READONLY;
GRANT ROLE PC_HUNTERS_DB_READONLY TO USER PC_HUNTERS_USER;
What the script does
- Creates the role
PC_HUNTERS_DB_READONLY, which lets Hunters use the warehousePC_HUNTERS_WHand read the tables and views ofPC_HUNTERS_DB.RAW, including tables Hunters adds later. - Grants the role to
PC_HUNTERS_USER, the user Hunters connects as. Hunters runs custom SQL enrichments as this role only, with no other role active. - Grants no privilege to change data, to create objects, or on any other schema, database or warehouse.
The role is yours: you can see its grants with SHOW GRANTS TO ROLE PC_HUNTERS_DB_READONLY;, and you can drop it at any time. Once it is dropped, custom SQL enrichments stop running until the role is created again.
After you run it
Nothing else is needed. The next time someone tests a custom SQL enrichment in the AI builder, Hunters uses the new role.