通过 DataBricks 中的 Spark 连接器授予对 Snowflake 数据库的权限
Granting permissions to a Snowflake database through Spark connecter in DataBricks
我当前使用的角色,比如说 main_user
,拥有对特定 Snowflake 数据库的完全权限,比如 live_database
。还有一个角色目前没有任何与此数据相关的权限,比如 temp_user
。在 Snowflake UI 中,我可以简单地 运行 以下查询,临时用户可以按预期访问。
use role main_user;
grant usage on database live_database to role temp_user;
grant usage on schema live_database.example to role temp_user;
grant select on table live_database.example.sample_table to role temp_user;
我还有一个管道 运行 是 DataBricks 中的一个模型,并通过 Spark 连接器将 from/writes 读取到上述 Snowflake 数据库。
不幸的是,每次我写信给 table 使用:
# results is a PySpark dataframe containing the model results
results.write \
.format("snowflake") \
.option("sfUser", <username>) \
.option("sfPassword", <password>) \
.option("dbtable", "live_database.example.sample_table") \
...
.mode('overwrite') \
.save()
权限已重置,我必须返回 Snowflake UI 才能授予权限。有没有办法在不重置权限的情况下写入 table?或者有没有办法直接从 DataBricks 运行 第一个查询授予权限?问题出现在调度任务的时候,手动更新权限就违背了调度的目的。
注意:我知道 this article but I have a DataBricks runtime v8 and thus according to this 我的 Spark_connector 是 > v2.5.9
由于覆盖模式导致 table 被重新创建,因此现有权限被清除,您可以:
a) 使用追加模式来重用现有的 table;
b) 授予相关架构中未来 tables 的权限:
GRANT SELECT
ON FUTURE TABLES
IN SCHEMA live_database.example
TO ROLE temp_user;
参考文献:
a) https://docs.snowflake.com/en/user-guide/spark-connector-use.html
我当前使用的角色,比如说 main_user
,拥有对特定 Snowflake 数据库的完全权限,比如 live_database
。还有一个角色目前没有任何与此数据相关的权限,比如 temp_user
。在 Snowflake UI 中,我可以简单地 运行 以下查询,临时用户可以按预期访问。
use role main_user;
grant usage on database live_database to role temp_user;
grant usage on schema live_database.example to role temp_user;
grant select on table live_database.example.sample_table to role temp_user;
我还有一个管道 运行 是 DataBricks 中的一个模型,并通过 Spark 连接器将 from/writes 读取到上述 Snowflake 数据库。
不幸的是,每次我写信给 table 使用:
# results is a PySpark dataframe containing the model results
results.write \
.format("snowflake") \
.option("sfUser", <username>) \
.option("sfPassword", <password>) \
.option("dbtable", "live_database.example.sample_table") \
...
.mode('overwrite') \
.save()
权限已重置,我必须返回 Snowflake UI 才能授予权限。有没有办法在不重置权限的情况下写入 table?或者有没有办法直接从 DataBricks 运行 第一个查询授予权限?问题出现在调度任务的时候,手动更新权限就违背了调度的目的。
注意:我知道 this article but I have a DataBricks runtime v8 and thus according to this 我的 Spark_connector 是 > v2.5.9
由于覆盖模式导致 table 被重新创建,因此现有权限被清除,您可以:
a) 使用追加模式来重用现有的 table;
b) 授予相关架构中未来 tables 的权限:
GRANT SELECT
ON FUTURE TABLES
IN SCHEMA live_database.example
TO ROLE temp_user;
参考文献:
a) https://docs.snowflake.com/en/user-guide/spark-connector-use.html