Row access policies in Streamlit in Snowflake¶
This topic describes using context functions and row access policies in Streamlit in Snowflake warehouse runtimes.
In container runtimes, context functions on owner’s rights connections will return values from the owner role’s context and so are not appropriate for user-targeted row access policies. However, restricted caller’s rights connections return the viewer’s context. For more information, see Restricted caller’s rights and Streamlit in Snowflake.
Context functions and row access policies in Streamlit in Snowflake¶
To use context functions such as CURRENT_USER and data from tables with row access policies in a Streamlit in Snowflake app, a user with the ACCOUNTADMIN role must grant the global READ SESSION privilege to the Streamlit app owner role, as shown in the following example:
Note
In a Streamlit in Snowflake app, you can’t use row access policies that use CURRENT_ROLE. Streamlit in Snowflake apps run with owner’s rights, so using CURRENT_ROLE inside a Streamlit app always returns the app owner role. For more information, see Understanding owner’s rights and Streamlit in Snowflake apps.
Example: Access data in a table with row access policy using CURRENT_USER¶
You can use a Streamlit in Snowflake app to govern access to rows in a table protected by a row access policy. Specify the CURRENT_USER function in the body of the row access policy and add the row access policy to the table.
The following example demonstrates how to govern access to a table that is protected by a row access policy in a Streamlit in Snowflake app.
Create a table and insert data:
Create a row access policy:
Add the row access policy to the table:
Create a Streamlit app.
Grant the global READ SESSION privilege to the Streamlit app owner role:
Add the following code to your Streamlit app: