教程 6:配置和测试服务端点权限¶
简介
在教程 1 中,您使用相同的角色来创建和测试服务。服务的创建角色是服务的所有者角色,因此您可以使用该角色与服务通信。
在本教程中,您将探索使用不同的角色与服务通信。
You grant this role the USAGE privilege by using a service role that you define in the service specification.
In this tutorial, you modify the Tutorial 1 as follows:
-
创建您将用来与服务通信的新角色。
-
修改服务规范,如下所示:
- 定义两个端点,而不只是一个端点。请注意,添加第二个端点只是为了演示端点权限的工作原理。
- 定义只能访问两个端点之一的服务角色。
-
为您创建的新角色授予服务角色,以允许访问服务端点之一。
-
使用新角色与服务端点通信。
准备
Follow Common Setup with the following modifications:
-
完成通用设置步骤。
-
By using the ACCOUNTADMIN role, execute the following script to create another role (
service_function_user_role), replacinguser_namewith the name of your Snowflake user. After creating the echo service, you use this role to communicate with the service. -
Follow Tutorial 1, steps 1 and 2, to build and upload an image to a repository in your account. Don’t proceed with step 3 because you will create the service as part of this tutorial.
创建服务
-
要确保您处于此步骤中 SQL 语句的正确上下文中,请执行以下步骤:
-
To create the service, execute the following command by using
test_role(the service’s owner role).Per the inline specification, the
echo_serviceexposes two public endpoints but the service role (echoendpoint_role) grants USAGE privilege only on one of the endpoints. -
验证服务是否正在运行。
-
By using
test_role(the service’s owner role), grant the service role defined in the specification to the new role (service_function_user_role) you created as part of the common setup. Also grant USAGE privileges on the database and the schema.This service role grants the
service_function_user_roleUSAGE privilege on theechoendpointendpoint.To demonstrate that the service role name is case in-sensitive, the example uses the
echoendpoint_Rolerole name.
使用服务
Create a service function to communicate with the service. You create a service function by using the service_function_user_role (not the service’s owner role) and use the service.
-
创建服务函数。
-
Try creating another service function that refers to the
echoservice2endpoint for which the role has no access privilege. Therefore, the command should fail. -
使用服务函数。
清理
To remove the resources you created, follow the steps in Tutorial 1 steps to clean up other resources created in Tutorial 1.
下一步是什么?
Now that you’ve completed this tutorial, you can return to Working with Services to explore other topics.