Assigning access rules for queries in Managed Service for Trino
Query access rules define the actions users can perform with SQL queries in a Managed Service for Trino cluster.
For each user-query pair, the rules apply as follows:
- Rules are checked for matches in the order they are listed in the configuration file. The first rule matching the user-query pair applies.
- If none of the rules match the user-query pair, no actions with the query are allowed to the user.
- If no query access rules are set, any user can perform any actions with any query.
- Query access rules apply together with the top-level rules for catalog objects.
Warning
If there are no query access rules, users can view and cancel each other's queries.
Setting rules when creating a cluster
You can set query access rules when creating a Managed Service for Trino cluster.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To set query access rules:
-
Create a file named
access_control.yamland paste the following code into it:queries: # Rule 1 - privileges: [<list_of_privileges>] query_owners: [<list_of_query_owners>] groups: [<list_of_group_IDs>] users: [<list_of_user_IDs>] description: <rule_description> # Rule 2 - <Rule_2_parameters> ... # Rule N - <Rule_N_parameters>Where:
-
queries: List of query rules. All the rule parameters are optional:privileges,query_owners,groups,users, anddescription. -
privileges: List of permitted actions with queries:VIEW: View query information.KILL: Cancel a query.EXECUTE: Run a query.
If you do not specify the
privilegesparameter, the rule will prohibit any actions with the queries.Warning
You cannot specify the
EXECUTEprivilege if the rule already contains thequery_ownersparameter. -
query_owners: List of query owner IDs. The rule will apply to queries whose owners are listed inquery_owners. If not specified, the rule will apply to queries from all users.
-
groups: List of group IDs the rule applies to. If you do not specifygroups, the rule applies to all user groups. -
users: List of user IDs the rule applies to. If you do not specifyusers, the rule applies to all users. -
description: Rule description.
-
-
View the description of the CLI command for creating a cluster:
yc managed-trino cluster create --help -
Run this command:
yc managed-trino cluster create \ ... --access-control-from-file access_control.yamlFor available cluster parameters and their descriptions, see this guide.
-
Create a Terraform configuration file describing your infrastructure.
-
Add to the configuration file the
yandex_trino_access_controlresource containing thequeriesrule list.resource "yandex_trino_cluster" "<cluster_name>" { ... } resource "yandex_trino_access_control" "trino_access_control" { ... cluster_id = yandex_trino_cluster.<cluster_name>.id queries = [ # Rule 1 { privileges = ["<list_of_privileges>"] query_owners = ["<list_of_query_owners>"] users = ["<list_of_user_IDs>"] groups = ["<list_of_group_IDs>"] description = "<rule_description>" }, # Rule 2 { ... }, ... # Rule N { ... } ] ... }Where:
-
queries: List of rule sections for queries. All the rule parameters are optional:privileges,query_owners,groups,users, anddescription. -
privileges: List of permitted actions with queries:VIEW: View query information.KILL: Cancel a query.EXECUTE: Run a query.
If you do not specify the
privilegesparameter, the rule will prohibit any actions with the queries.Warning
You cannot specify the
EXECUTEprivilege if the rule already contains thequery_ownersparameter. -
query_owners: List of query owner IDs. The rule will apply to queries whose owners are listed inquery_owners. If not specified, the rule will apply to queries from all users.
-
groups: List of group IDs the rule applies to. If you do not specifygroups, the rule applies to all user groups. -
users: List of user IDs the rule applies to. If you do not specifyusers, the rule applies to all users. -
description: Rule description.
-
-
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
-
Get an IAM token for API authentication and put it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Create a file named
body.jsonand paste the following code into it:{ <cluster_parameters> ... "trino": { "access_control": { "queries": [ { "privileges": [ "<list_of_privileges>" ], "query_owners": [ "<list_of_query_owners>" ], "users": [ "<list_of_user_IDs>" ], "groups": [ "<list_of_group_IDs>" ], "description": "<rule_description>" }, { <Rule_2_section> }, ... { <Rule_N_section> } ] } } }Where:
-
access_control: Access rule configuration in the cluster. -
queries: List of rule sections for queries. All the rule parameters are optional:privileges,query_owners,groups,users, anddescription. -
privileges: List of permitted actions with queries:VIEW: View query information.KILL: Cancel a query.EXECUTE: Run a query.
If you do not specify the
privilegesparameter, the rule will prohibit any actions with the queries.Warning
You cannot specify the
EXECUTEprivilege if the rule already contains thequery_ownersparameter. -
query_owners: List of query owner IDs. The rule will apply to queries whose owners are listed inquery_owners. If not specified, the rule will apply to queries from all users.
-
groups: List of group IDs the rule applies to. If you do not specifygroups, the rule applies to all user groups. -
users: List of user IDs the rule applies to. If you do not specifyusers, the rule applies to all users. -
description: Rule description.
For available cluster parameters and their descriptions, see this guide.
-
-
Call the ClusterService/Create method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/trino/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ \ trino.api.cloud.yandex.net:443 \ yandex.cloud.trino.v1.ClusterService.Create \ < body.json -
Check the server response to make sure your request was successful.
Setting rules for an existing cluster
You can set or update query access rules in an existing Managed Service for Trino cluster.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To set query access rules:
-
If you have not set any access rules yet, create a file named
access_control.yamland paste the following code into it:queries: # Rule 1 - privileges: [<list_of_privileges>] query_owners: [<list_of_query_owners>] groups: [<list_of_group_IDs>] users: [<list_of_user_IDs>] description: <rule_description> # Rule 2 - <Rule_2_parameters> ... # Rule N - <Rule_N_parameters>Where:
-
queries: List of query rules. All the rule parameters are optional:privileges,query_owners,groups,users, anddescription. -
privileges: List of permitted actions with queries:VIEW: View query information.KILL: Cancel a query.EXECUTE: Run a query.
If you do not specify the
privilegesparameter, the rule will prohibit any actions with the queries.Warning
You cannot specify the
EXECUTEprivilege if the rule already contains thequery_ownersparameter. -
query_owners: List of query owner IDs. The rule will apply to queries whose owners are listed inquery_owners. If not specified, the rule will apply to queries from all users.
-
groups: List of group IDs the rule applies to. If you do not specifygroups, the rule applies to all user groups. -
users: List of user IDs the rule applies to. If you do not specifyusers, the rule applies to all users. -
description: Rule description.
-
-
If you have already set the access rules, open
access_control.yamland edit it as needed. You can:- Add new rules.
- Update the existing ones.
- Delete the rules you no longer need.
-
Run this command:
yc managed-trino cluster set-access-control <cluster_name_or_ID> \ --from-file access_control.yamlYou can get the cluster ID and name with the list of clusters in the folder.
-
Open the current Terraform configuration file describing your infrastructure.
To learn how to create this file, see Creating a cluster.
-
If you have not set the access rules yet, add the
yandex_trino_access_controlresource containing thequeriesrule list.resource "yandex_trino_cluster" "<cluster_name>" { ... } resource "yandex_trino_access_control" "trino_access_control" { ... cluster_id = yandex_trino_cluster.<cluster_name>.id queries = [ # Rule 1 { privileges = ["<list_of_privileges>"] query_owners = ["<list_of_query_owners>"] users = ["<list_of_user_IDs>"] groups = ["<list_of_group_IDs>"] description = "<rule_description>" }, # Rule 2 { ... }, ... # Rule N { ... } ] ... }Where:
-
queries: List of rule sections for queries. All the rule parameters are optional:privileges,query_owners,groups,users, anddescription. -
privileges: List of permitted actions with queries:VIEW: View query information.KILL: Cancel a query.EXECUTE: Run a query.
If you do not specify the
privilegesparameter, the rule will prohibit any actions with the queries.Warning
You cannot specify the
EXECUTEprivilege if the rule already contains thequery_ownersparameter. -
query_owners: List of query owner IDs. The rule will apply to queries whose owners are listed inquery_owners. If not specified, the rule will apply to queries from all users.
-
groups: List of group IDs the rule applies to. If you do not specifygroups, the rule applies to all user groups. -
users: List of user IDs the rule applies to. If you do not specifyusers, the rule applies to all users. -
description: Rule description.
-
-
If you have already set the access rules, edit the
yandex_trino_access_controlresource description. You can:- Add new rules.
- Update the existing ones.
- Delete the rules you no longer need.
-
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
-
Get an IAM token for API authentication and put it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
If you have not set any access rules yet, create a file named
body.jsonand paste the following code into it:{ "cluster_id": "<cluster_ID>", "update_mask": { "paths": [ "trino.access_control.queries" ] }, "trino": { "access_control": { "queries": [ { "privileges": [ "<list_of_privileges>" ], "query_owners": [ "<list_of_query_owners>" ], "users": [ "<list_of_user_IDs>" ], "groups": [ "<list_of_group_IDs>" ], "description": "<rule_description>" }, { <Rule_2_section> }, ... { <Rule_N_section> } ] } } }Where:
-
cluster_id: Cluster ID.You can get the cluster ID with the list of clusters in the folder.
-
update_mask: List of parameters to update as an array of strings (paths[]).Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }Warning
When you update a cluster, all parameters of the object you are modifying will take their defaults unless explicitly provided in the request. To avoid this, list the settings you want to change in the
update_maskparameter. -
access_control: Access rule configuration in the cluster. -
queries: List of rule sections for queries. All the rule parameters are optional:privileges,query_owners,groups,users, anddescription. -
privileges: List of permitted actions with queries:VIEW: View query information.KILL: Cancel a query.EXECUTE: Run a query.
If you do not specify the
privilegesparameter, the rule will prohibit any actions with the queries.Warning
You cannot specify the
EXECUTEprivilege if the rule already contains thequery_ownersparameter. -
query_owners: List of query owner IDs. The rule will apply to queries whose owners are listed inquery_owners. If not specified, the rule will apply to queries from all users.
-
groups: List of group IDs the rule applies to. If you do not specifygroups, the rule applies to all user groups. -
users: List of user IDs the rule applies to. If you do not specifyusers, the rule applies to all users. -
description: Rule description.
-
-
If you have already set the access rules, open the existing
body.jsonrules file and edit it as needed. You can:- Add new rules.
- Update the existing ones.
- Delete the rules you no longer need.
-
Call the ClusterService.Update method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/trino/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ \ trino.api.cloud.yandex.net:443 \ yandex.cloud.trino.v1.ClusterService.Update \ < body.json -
Check the server response to make sure your request was successful.
Example of setting query access rules
Let's configure query access rules as follows:
- Allow any actions on queries to the user group with the
admins_group_id. - Allow the user group with the
security_group_idto view and delete queries owned by user with thesuspicious_user_id. - Allow all other users to only run queries.
The access_control.yaml file for this rule set is as follows:
queries:
- groups:
- admins_group_id
privileges:
- VIEW
- KILL
- EXECUTE
- groups:
- security_group_id
query_owners:
- suspicious_user_id
privileges:
- VIEW
- KILL
- privileges:
- EXECUTE
The configuration file for this rule set is as follows:
resource "yandex_trino_access_control" "trino_access_control" {
...
cluster_id = <cluster_ID>
queries = [
{
privileges = ["VIEW", "KILL", "EXECUTE"]
groups = ["admins_group_id"]
},
{
privileges = ["VIEW", "KILL"]
groups = ["security_group_id"]
query_owners = ["suspicious_user_id"]
},
{
privileges = ["EXECUTE"]
}
]
...
}
The body.json file for this rule set is as follows:
{
"cluster_id": "<cluster_ID>",
"update_mask": {
"paths": [
"trino.access_control.queries"
]
},
"trino": {
"access_control": {
"queries": [
{
"privileges": [
"VIEW",
"KILL",
"EXECUTE"
],
"groups": [
"admins_group_id"
]
},
{
"privileges": [
"VIEW",
"KILL"
],
"query_owners": [
"suspicious_user_id"
],
"groups": [
"security_group_id"
]
},
{
"privileges": [
"EXECUTE"
]
}
]
}
}
}