Tutorial 6: Configure and test service endpoint privileges¶
Introduction¶
In Tutorial 1, you use the same role to create and test a service. The role that creates the service is the service’s owner role, so you’re able to communicate with the service by using that role.
In this tutorial, you explore by using a different role to communicate with the service.
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:
-
Create a new role that you will use to communicate with the service.
-
Modify the service specification as follows:
- Define two endpoints, instead of just one endpoint. Note that the second endpoint is added only to demonstrate how endpoint permissions work.
- Define a service role that is allowed to access only one of the two endpoints.
-
Grant the service role to the new role you created to allow access to one of the service endpoints.
-
Use the new role to communicate with the service endpoint.
Prepare¶
Follow Common Setup with the following modifications:
-
Complete the common setup steps.
-
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.
Create a service¶
-
To ensure you’re in the right context for the SQL statements in this step, execute the following:
-
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. -
Verify the service is running.
-
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.
Use the service¶
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.
-
Create a service function.
-
Try creating another service function that refers to the
echoservice2endpoint for which the role has no access privilege. Therefore, the command should fail. -
Use the service function.
Clean up¶
To remove the resources you created, follow the steps in Tutorial 1 steps to clean up other resources created in Tutorial 1.
What’s next?¶
Now that you’ve completed this tutorial, you can return to Working with Services to explore other topics.