在应用程序中使用所有者权限和受限制的调用方权限¶
本主题介绍如何将应用程序配置为使用所有者权限和受限制的调用方权限。
关于应用程序中的所有者权限和受限制的调用方权限¶
在应用程序的上下文中,支持以下类型的可执行文件:
应用程序拥有的存储过程
带有容器的应用程序中提供的服务
Each of these types of executables can be configured to use either owner's rights or restricted caller's rights.
- 所有者权限:
By default, executables within an app use owner's rights, which means that they run with the privileges granted to the owner of the executable, which is the app itself.
例如,所有者权限允许可执行文件访问提供商账户中的数据,并将该数据提供给使用者。但是,这种权限模式不允许使用者直接访问数据。
For example, the CREATE PROCEDURE command creates a stored procedure that uses owner's rights by default. Consumers can call the stored procedure if they have been granted access using application roles. If the app has the privileges to perform an operation, then the stored procedure can perform that operation.
For general information on owner's rights, see 了解调用方权限和所有者权限存储过程.
- 受限制的调用方的权限:
受限制的调用方权限允许可执行文件以调用方的权限运行,但限制可执行文件以调用方的哪些权限运行。在受限制的调用方权限下,应用程序拥有的可执行文件无法以某项特定权限运行,除非使用者账户中的管理员通过使用 GRANT CALLER 命令明确允许该权限。
备注
为确保应用程序中可执行文件的安全性,Snowflake Native Apps 不支持不受限制的调用方权限。
有关受限制的调用方权限的一般信息,请参阅 受限制的调用方的权限。
Scope of restricted caller's rights in an app¶
Snowflake 建议使用者在容器级别授予调用方权限,而非针对其账户中的特定对象。
- 架构级别:
授予针对架构的调用方权限,但不授予对架构中对象的任何权限。例如,授予对架构的 CALLER USAGE 调用方权限只能授予对架构的 USAGE 权限。要授予对特定对象(例如函数)的访问权限,请使用 GRANT INHERITED CALLER USAGE ON ALL FUNCTIONS IN SCHEMA。
- 数据库级别:
在数据库级别授予调用方权限,仅允许可执行文件访问数据库和数据库中的所有架构。例如,授予 CALLER USAGE 调用方权限将授予该数据库的 USAGE 权限。但是,要授予对特定对象的访问权限,必须使用以下命令:
GRANT INHERITED CALLER USAGE ON ALL FUNCTIONS IN DATABASE;
- Account level:
在账户级授予调用方授权,允许可执行文件执行账户级别的操作。授予 CALLER USAGE 调用方权限仅允许可执行文件访问账户,但不提供对账户内对象的访问权限。
要允许访问特定对象,需授予对账户中特定类型对象的访问权限。例如,授予 CREATE DATABASE 调用方权限将允许可执行文件在使用者账户中创建数据库,如以下示例所示:
GRANT CALLER CREATE DATABASE ON ACCOUNT TO my_app;
可授予应用程序的账户级调用方权限¶
提供商可以在应用程序中配置可执行文件,以使用以下账户级调用方权限:
CREATE DATABASE
EXECUTE ALERT
EXECUTE MANAGED TASK
EXECUTE TASK
READ SESSION
VIEW LINEAGE
备注
使用者在向应用程序授予账户级调用方权限时应当审慎操作。
确定应用程序的访问权限要求¶
Snowflake Native Apps give providers flexibility in how they configure access to the data and executables managed by the app. The following table provides guidelines for which mechanism to use depending on the access requirements of the app:
所需的访问权限 |
如何获得访问权限 |
|---|---|
应用程序拥有的数据或函数 |
默认使用所有者权限。提供商无需向使用者请求访问权限即可创建或访问应用程序拥有的对象。 |
使用者账户中的特定表、视图或函数 |
向使用者请求参考 |
其他用户或角色拥有的表、视图、函数和行策略。 |
使用受限制的调用方权限,从而让使用者能够访问这些对象。 |
广泛访问使用者拥有的数据库 |
使用数据库角色授权 |
访问使用者和提供商数据组合的查询 |
同时使用参考和所有者权限 |
账户级对象 |
提供自定义脚本,其中包含用于授予对特定对象的权限的 GRANT 命令。 |
执行账户级操作,例如创建数据库或执行任务。 |
Use restricted caller's rights, which allow the consumer to enable access to perform these actions. |
将 restricted_callers_rights 属性添加到清单中¶
As a provider, if you configure an executable in an app to use restricted caller's rights,
Snowflake recommends that you add the restricted_callers_rights to the manifest
file as shown in the following example:
restricted_callers_rights:
enabled: true
description: This app includes stored procedure that uses restricted caller's rights.
尽管 restricted_callers_rights 不是必填项,但如果它已存在且 enabled 设置为 true, 则 Snowsight 会在应用程序的列表中添加一个名为 Restricted caller's rights 的部分。
将过程或服务配置为使用受限制的调用方权限¶
To create a stored procedure that uses restricted caller's rights, use the EXECUTE AS RESTRICTED CALLER clause when the app creates an executable as shown in the following example:
CREATE OR REPLACE PROCEDURE CORE.HELLO()
RETURNS STRING
LANGUAGE SQL
EXECUTE AS RESTRICTED CALLER
AS
BEGIN
RETURN 'Hello Snowflake!';
END;
有关更多信息,请参阅 CREATE PROCEDURE。
Using a restricted caller's rights service in an app with containers¶
有关将服务配置为使用受限制的调用方权限的更多信息,请参阅 使用调用方限从容器内部连接到 Snowflake。
In an app with containers, a Snowpark Container Services service can run with privileges of the app (owner’s rights) or with the privileges of the caller of the service (restricted caller’s rights). However, the service _owner_ role, instead of the service _user_ role, is the app. When granting caller grants, a consumer specifies the app by using the TO APPLICATION clause as shown in the following example:
GRANT CALLER USAGE ON DATABASE consumer_db TO APPLICATION hello_snowflake_app;
此示例允许该服务使用受限制的调用方权限运行,从而使用调用方角色访问 consumer_db 数据库。
对应用程序中受限制的调用方权限的限制¶
在应用程序中使用受限制的调用方权限时,适用以下限制。
对受限制的调用方权限的一般限制¶
有关对受限制的调用方权限的一般限制,请参阅 具有受限制的调用方权限的可执行文件的限制。此处列出的限制也适用于应用程序。
应用程序的其他限制¶
除了对受限制的调用方权限的一般限制外,应用程序还有以下限制:
应用程序中的可执行文件不支持 不受限制 的调用方权限。
无法执行以下命令:
SHOW ROLES
SHOW USERS
SHOW [CALLER] GRANTS
SHOW AVAILABLE LISTINGS
无法执行以下函数:
ALL_USER_NAMES
GET_USERS_FOR_COLLABORATION
CURRENT_IP_ADDRESS
CURRENT_AVAILABLE_ROLES
CURRENT_SECONDARY_ROLES
SYSTEM$ALLOWLIST(或已弃用的 SYSTEM$WHITELIST)
不支持持久引用函数。
不支持暂存区上对象的相对路径。
Restricted caller's rights executables cannot access the app's internal objects.
如果可执行文件使用所有者权限,则无法调用使用不受限制的调用方权限的其他可执行文件。
Although executables with owner's rights owned by the application can invoke executables with restricted caller's rights, these executables must also be owned by the app. For example, an app's stored procedure with owner's rights cannot call a consumer's stored procedure with restricted caller's rights.
从应用程序中受限制的调用方权限过程中调用计费函数¶
无法从 RCR 可执行文件中调用 SYSTEM$CREATE_BILLING_EVENT 或 SYSTEM$CREATE_BILLING_EVENTS 等计费函数。要从应用程序中的 RCR 可执行文件中调用这些函数,请在所有者权限过程中添加这些函数,并从受限制的调用方权限过程中调用该过程。
知识产权保护和受限制的调用方权限¶
包含所有者权限存储过程的应用程序会编辑有关应用程序内部实现的信息。有关更多信息,请参阅 保护提供商的知识产权。
Stored procedures with restricted caller's rights also redact internal information about the app. In particular, this applies to the following commands, views, and functions where much of the information is redacted:
Information Schema 的 PROCEDURES 视图
Account Information Schema 的 PROCEDURES 视图
GET_DDL 函数
但是,与使用所有者权限的存储过程不同,使用受限制的调用方权限的过程不会编辑查询历史记录和查询配置文件中的信息。
开发使用受限制的调用方权限的应用程序¶
In general, only roles that have been granted the MANAGE CALLER GRANTS privilege can grant caller grants to an executable. However, during the development lifecycle of a Snowflake Native App, providers may need to create and drop the app frequently. Snowflake Native Apps provide a mechanism for creating caller grants for an app in development mode.
提供商可以使用不具备 MANAGE CALLER GRANTS 的角色向应用程序授予调用方授权。但是,这需要满足以下所有条件:
应用程序必须在 开发模式 下创建。
当前角色在角色层次结构中具有应用程序所有者角色。
应用程序所有者角色拥有所授予的调用方授权的超集。
备注
ALL CALLER PRIVILEGES 权限是任何调用方权限集的超集。
超集要求无法通过 INHERITED CALLER 授权来满足,该授权通常涵盖特定容器下特定类型的所有当前和未来对象。有关更多信息,请参阅 GRANT CALLER。
为了满足此要求,向应用程序所有者角色授予的调用方授权必须明确涵盖要授予的调用方授权。
允许应用程序开发者在开发模式下向应用程序授予调用方权限¶
要允许应用程序所有者角色向开发模式下的应用程序授予特定的调用方授权集,如果用户拥有 ACCOUNTADMIN 角色或已被授予 MANAGE CALLER GRANTS 权限的角色,则必须首先授予调用方授权,该调用方授权涵盖向应用程序所有者角色授予的授权集。
以下示例展示了在账户中如何授予所需的对数据库的调用方权限:
GRANT ALL INHERITED CALLER PRIVILEGES
ON ALL DATABASES IN ACCOUNT
TO ROLE app_dev_role;
此命令向 app_dev_role 角色授予对所有数据库的所有调用方授权。
备注
此命令仅授予调用方授权。此命令不允许应用程序开发者访问尚未允许他们访问的对象。
开发模式下应用程序的其他安全措施¶
允许不具备 MANAGE CALLER GRANTS 权限的应用程序开发者所有者角色简化应用程序开发过程,但这也会带来潜在的安全风险。为了尽可能降低这些风险,Snowflake 会验证应用程序所有者是否仍然需要调用方授权才能使用该应用程序。如果应用程序所有者失去了所需的调用方授权,则应用程序也会失去这些授权。