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.
示例:使用 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.
-
创建表并插入数据:
-
创建行访问策略:
-
将行访问策略添加到表中:
-
创建一个 Streamlit 应用程序。
-
将全局 READ SESSION 权限授予 Streamlit 应用程序所有者角色:
-
将以下代码添加到 Streamlit 应用程序中: