Managing ClickHouse® users
Managed Service for ClickHouse® provides two ways for you to manage users and their individual settings:
- Using native Yandex Cloud interfaces, such as the management console, CLI, Terraform, or API . Select this method to create, update, and delete users and custom user settings using Yandex Managed Service for ClickHouse® features.
- SQL queries to the cluster. Select this method to use your existing solutions to create and manage users or if you are using RBAC
.
Warning
In a Managed Service for ClickHouse® cluster, you can only use one user management method at a time: either via standard interfaces or via SQL queries.
Note
Creating a new ClickHouse® cluster automatically creates service users to administer and monitor the service.
Managing users via SQL
To enable management, activate the User management via SQL option when creating or reconfiguring a cluster.
Warning
You cannot disable the SQL user management setting once it is enabled.
In a cluster with user management via SQL enabled:
- User management via standard Yandex Cloud interfaces (management console, CLI, API, Terraform) is unavailable.
- The existing users as well as user settings made with the standard Yandex Cloud interfaces will be saved.
- User management is performed using the
admin
account. You set its password when you select the User management via SQL option.
For more information about managing users via SQL, see the ClickHouse® documentation
Getting a list of users
- In the management console
, go to the folder page and select Managed Service for ClickHouse. - Click the name of the cluster you need and select the Users tab.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get a list of cluster users, run the following command:
yc managed-clickhouse user list
--cluster-name=<cluster_name>
You can request the cluster name with a list of clusters in the folder.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the User.list method and send the following request, e.g., via cURL
:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/users'
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the UserService.List call and send the following request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.UserService.List
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Connect to a cluster using the
admin
account. -
Get a list of users:
SHOW USERS;
Creating a user
-
In the management console
, go to the folder page and select Managed Service for ClickHouse. -
Click the cluster name and open the Users tab.
-
Click Create user.
-
Enter the database username and password.
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter or underscore. The password must be from 8 to 128 characters long.
-
Select one or more databases that the user should have access to:
- Click
and select a database from the drop-down list. - Repeat the previous step until all the required databases are selected.
- To delete a database added by mistake, click
to the right of the database name.
- Click
-
Configure additional settings for the user:
- Set quotas in Additional settings → Quotas:
- To add a quota, click
. You can add multiple quotas that will be valid at the same time. - To delete a quota, click
to the right of the quota name and select Delete. - To change a quota, set the required values of its settings.
- To add a quota, click
- Configure ClickHouse® in Additional settings → Settings.
- Set quotas in Additional settings → Quotas:
-
Click Create.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To create a user in a cluster, run the command:
yc managed-clickhouse user create <username> \
--cluster-name=<cluster_name> \
--password=<user_password> \
--permissions=<DB_list> \
--quota=<list_of_single_quota_settings_for_user> \
--settings=<list_of_ClickHouse®_settings_for_user>
Where --permissions
is a list of DBs the user must have access to.
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter or underscore. The password must be from 8 to 128 characters long.
For more information about quotas and query-level settings, see ClickHouse® settings.
To set multiple quotas, list them using the required number of --quota
parameters in the command:
yc managed-clickhouse user create <username> \
...
--quota="<quota_0_settings>" \
--quota="<quota_1_settings>" \
...
You can request the cluster name with a list of clusters in the folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Add a
user
block to the Managed Service for ClickHouse® cluster description:resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" { ... user { name = "<username>" password = "<password>" ... } }
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter or underscore. The password must be from 8 to 128 characters long.
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring one from a backup: 60 minutes.
- Editing a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the User.create method and send the following request, e.g., via cURL
:-
Create a file named
body.json
and add the following contents to it:{ "userSpec": { "name": "<username>", "password": "<user_password>", "permissions": [ { "databaseName": "<DB_name>" } ], "settings": {<ClickHouse®_settings>}, "quotas": [ { "intervalDuration": "<quota_interval>", "queries": "<total_number_of_queries>", "errors": "<number_of_failed_queries>", "resultRows": "<number_of_rows_of_result>", "readRows": "<number_of_source_rows>", "executionTime": "<total_execution_time>" }, { <similar_settings_for_quota_2> }, { ... }, { <similar_settings_for_quota_N> } ] }, { <similar_settings_for_new_user_2> }, { ... }, { <similar_settings_for_new_user_N> } }
Where
userSpec
is an array with settings for the new users. One array element contains settings for a single user and has the following structure:-
name
: Username. It may contain Latin letters, numbers, hyphens, and underscores, and must start with a letter or underscore. -
password
: User password. The password must be from 8 to 128 characters long. -
permissions
: List of DBs the user must have access to.The list appears as an array of
databaseName
parameters. Each parameter contains the name of a separate database.
-
settings
: List of ClickHouse® settings for the user.Settings are specified as comma-separated
key: value
pairs. -
quotas
: Array with quota settings. One array element contains settings for a single quota.
-
-
Run this request:
curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/users' \ --data '@body.json'
You can get the cluster ID with a list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService.Create call and send the following request, e.g., via gRPCurl
:-
Create a file named
body.json
and add the following contents to it:{ "cluster_id": "<cluster_ID>", "user_spec": { "name": "<username>", "password": "<user_password>", "permissions": [ { "database_name": "<DB_name>" } ], "settings": {<ClickHouse®_settings>}, "quotas": [ { "interval_duration": "<quota_interval>", "queries": "<total_number_of_queries>", "errors": "<number_of_failed_queries>", "result_rows": "<number_of_rows_of_result>", "read_rows": "<number_of_source_rows>", "execution_time": "<total_execution_time>" }, { <similar_settings_for_quota_2> }, { ... }, { <similar_settings_for_quota_N> } ] }, { <similar_settings_for_new_user_2> }, { ... }, { <similar_settings_for_new_user_N> } }
Where
user_spec
is an array with settings for the new users. One array element contains settings for a single user and has the following structure:-
name
: Username. It may contain Latin letters, numbers, hyphens, and underscores, and must start with a letter or underscore. -
password
: User password. The password must be from 8 to 128 characters long. -
permissions
: List of DBs the user must have access to.The list appears as an array of
database_name
parameters. Each parameter contains the name of a separate database. -
settings
: List of ClickHouse® settings for the user.Settings are specified as comma-separated
key: value
pairs. -
quotas
: Array with quota settings. One array element contains settings for a single quota.
You can get the cluster ID with a list of clusters in the folder.
-
-
Run this request:
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.UserService.Create \ < body.json
-
-
View the server response to make sure the request was successful.
-
Connect to a cluster using the
admin
account. -
Create a user:
CREATE USER <username> IDENTIFIED WITH sha256_password BY '<user_password>';
Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter or underscore.
The password must be from 8 to 128 characters long.
For more information about creating users, see the ClickHouse® documentation
Changing a password
We recommend that you use the Yandex Cloud interfaces listed below. Do not use SQL to change your password; otherwise, the password may reset to the previous one after maintenance.
- In the management console
, go to the folder page and select Managed Service for ClickHouse. - Click the cluster name and open the Users tab.
- Click
and select Change password. - Set a new password and click Edit.
Note
The password must be between 8 and 128 characters.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To change the user password, run this command:
yc managed-clickhouse user update <username> \
--cluster-name=<cluster_name> \
--password=<new_password>
Note
The password must be between 8 and 128 characters.
You can request the cluster name with a list of clusters in the folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
In the Managed Service for ClickHouse® cluster description, find the
user
block for the required user. -
Change the value of the
password
field:resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" { ... user { name = "<username>" password = "<new_password>" ... } }
Note
The password must be between 8 and 128 characters.
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring one from a backup: 60 minutes.
- Editing a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the User.update method and send the following request, e.g., using cURL
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMask
parameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/users/<username>' \ --data '{ "updateMask": "password", "password": "<new_password>" }'
Where:
-
updateMask
: List of parameters to update as a single string, separated by commas.Here only one parameter is specified:
password
. -
password
: New user password.The password must be from 8 to 128 characters long.
You can get the cluster ID with a list of clusters in the folder. You can request the user name with the list of users in the cluster.
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the UserService.Update call and send the following request, e.g., via gRPCurl
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_mask
parameter as an array ofpaths[]
strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "user_name": "<username>", "update_mask": { "paths": [ "password" ] }, "password": "<new_password>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.UserService.Update
Where:
-
update_mask
: List of parameters to update as an array ofpaths[]
strings.Here only one parameter is specified:
password
. -
password
: New user password.The password must be from 8 to 128 characters long.
You can get the cluster ID with a list of clusters in the folder. You can request the user name with the list of users in the cluster.
-
-
View the server response to make sure the request was successful.
Changing the admin password
We recommend that you use the Yandex Cloud interfaces listed below. Do not use SQL to change your password; otherwise, the password may reset to the previous one after maintenance.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To change the admin
password, run the command below:
yc managed-clickhouse cluster update <cluster_name_or_ID> \
--admin-password <new_admin_user_password>
Note
The password must be between 8 and 128 characters.
You can request the cluster ID and name with a list of clusters in the folder.
Tip
- For increased security, instead of
--admin-password
, use the--read-admin-password
parameter: you will need to enter the new password using the keyboard, and it will not be saved in the command history. - To generate a password automatically, use
--generate-admin-password
. The command output will contain the new password.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Change the value of the
admin_password
field:resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" { ... admin_password = "<admin_user_password>" ... }
Note
The password must be between 8 and 128 characters.
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring one from a backup: 60 minutes.
- Editing a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.Update method and send the following request, e.g., via cURL
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMask
parameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>' \ --data '{ "updateMask": "configSpec.adminPassword", "configSpec": { "adminPassword": "<new_password>" } }'
Where:
-
updateMask
: List of parameters to update as a single string, separated by commas.Here only one parameter is specified:
configSpec.adminPassword
. -
configSpec.adminPassword
: New user password.The password must be from 8 to 128 characters long.
You can get the cluster ID with a list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService.Update call and send the following request, e.g., via gRPCurl
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_mask
parameter as an array ofpaths[]
strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "update_mask": { "paths": [ "config_spec.admin_password" ] }, "config_spec": { "admin_password": "<new_password>" } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.Update
Where:
-
update_mask
: List of parameters to update as an array ofpaths[]
strings.Here only one parameter is specified:
config_spec.admin_password
. -
config_spec.admin_password
: New user password.The password must be from 8 to 128 characters long.
You can get the cluster ID with a list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
Changing user settings
- In the management console
, go to the folder page and select Managed Service for ClickHouse. - Click the cluster name and open the Users tab.
- Click
and select Configure. - Configure user permissions to access certain databases:
- To grant access to the required databases:
- Click
and select a database from the drop-down list. - Repeat the previous step until all the required databases are selected.
- Click
- To delete a database, click
to the right of the database name.
- To grant access to the required databases:
- Set quotas for the user in Additional settings → Quotas:
- To add a quota, click
. You can add multiple quotas that will be valid at the same time. - To delete a quota, click
to the right of the quota name and select Delete. - To change a quota, set the required values of its settings.
- To add a quota, click
- Edit the user ClickHouse® settings under Additional settings → Settings.
- Click Save.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
You can change the user settings from the command line interface:
-
To set up the user's permissions to access certain databases, run the command, listing the database names in the
--permissions
parameter:yc managed-clickhouse user update <username> \ --cluster-name=<cluster_name> \ --permissions=<DB_list>
You can request the cluster name with a list of clusters in the folder.
This command grants the user access rights to the databases listed.
To revoke access to a specific database, remove its name from the list and send the updated list to the command.
-
To change the user's quota settings, run the command with a list of all quotas, using
--quota
parameters (one parameter per quota):yc managed-clickhouse user update <username> \ --cluster-name=<cluster_name> \ --quota=<quota_0_settings_(unchanged)> \ --quota=<quota_1_settings_(unchanged)> \ --quota=<quota_2_settings_(changed)> \ --quota=<quota_3_settings_(unchanged)> \ --quota=<quota_4_settings_(changed)> \ --quota=<quota_5_settings_(new_quota)> ...
You can request the cluster name with a list of clusters in the folder.
This command overwrites all existing user quota settings with the new ones you provided to the command.
Before running the command, make sure that you included the settings for new and changed quotas and the settings for existing quotas that have not changed.To delete one or more user quotas, exclude their settings from the list and send the updated list of
--quota
parameters to the command.When setting an interval, you can use an entry with units: hours (
h
), minutes (m
), seconds (s
), and milliseconds (ms
). Sample entry:3h20m10s7000ms
(the resulting value is still represented in milliseconds:12017000
). The interval value must be a multiple of 1,000 milliseconds (e.g.,1s500ms
is incorrect). -
To edit a user's ClickHouse® settings, run the command below listing the changed setting using the
--settings
option:yc managed-clickhouse user update <username> \ --cluster-name=<cluster_name> \ --settings=<list_of_ClickHouse®>_settings
You can request the cluster name with a list of clusters in the folder.
The command only changes the settings that are explicitly specified in the
--settings
parameter. For example, the command with the parameter--settings="readonly=1"
only changes thereadonly
setting and doesn't reset the values of the other settings. This is how changing ClickHouse® settings differs from changing quota settings.You cannot use this command to delete an existing setting. You can only explicitly set it to its default value (specified for each setting).
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
To configure the user's permissions to access certain databases, add the required number of
permission
sections to the cluster user description, one for each database:resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" { ... user { name = "<username>" password = "<password>" permission { database_name = "<database_1>" } ... permission { database_name = "<database_N>" } } }
In the
database_name
field, specify the name of the database to grant access to. -
To change quota settings for the user, add the required number of
quota
blocks to the cluster user description.When describing quotas, only the
interval_duration
field is required.resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" { ... user { name = "<username>" password = "<password>" ... quota { interval_duration = <interval_in_milliseconds> ... } } }
-
To edit a user's ClickHouse® settings add a
settings
section to its description.resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" { ... user { name = "<username>" password = "<password>" ... settings { <DBMS_settings_for_individual_user> } } }
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform
Time limits
A Terraform provider sets the timeout for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring one from a backup: 60 minutes.
- Editing a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the User.update method and send the following request, e.g., using cURL
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMask
parameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/users/<username>' \ --data '{ "updateMask": "<list_of_settings_to_update>", "permissions": [ <updated_DB_list> ], "settings": { <ClickHouse®_settings> }, "quotas": [ <updated_list_of_quota_settings> ] }'
Where
updateMask
is the list of parameters to update as a single string, separated by commas.Specify the required parameters to update individual categories of settings:
-
To update the list of databases available to the user, provide the updated list in the
permissions
parameter.The list appears as an array of
databaseName
parameters. Each parameter contains the name of a separate database.Warning
The current DB list in the cluster will be completely overwritten by the list provided in the
permissions
parameter.Before executing your request, make sure the list includes all the required databases, including existing ones.
-
To update ClickHouse® settings for a user, provide the required settings with updated values in the
settings
parameter. -
To update quota settings, provide the updated list of settings in the
quotas
parameter.The list appears as an array. One array element contains settings for a single quota.
Warning
The current list of quota settings in the cluster will be completely overwritten by the list provided in the
quotas
parameter.Before executing your request, make sure the list includes all the required quota settings, including existing ones.
You can get the cluster ID with a list of clusters in the folder. You can request the user name with the list of users in the cluster.
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the UserService.Update call and send the following request, e.g., via gRPCurl
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_mask
parameter as an array ofpaths[]
strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "user_name": "<username>", "update_mask": { "paths": [ <list_of_settings_to_update> ] }, "permissions": [ <updated_DB_list> ], "settings": { <ClickHouse®_settings> }, "quotas": [ <updated_list_of_quota_settings> ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.UserService.Update
Where
update_mask
is the list of parameters to update as an array ofpaths[]
strings.Specify the required parameters to update individual categories of settings:
-
To update the list of databases available to the user, provide the updated list in the
permissions
parameter.The list appears as an array of
database_name
parameters. Each parameter contains the name of a separate database.Warning
The current DB list in the cluster will be completely overwritten by the list provided in the
permissions
parameter.Before executing your request, make sure the list includes all the required databases, including existing ones.
-
To update ClickHouse® settings for a user, provide the required settings with updated values in the
settings
parameter. -
To update quota settings, provide the updated list of settings in the
quotas
parameter.The list appears as an array. One array element contains settings for a single quota.
Warning
The current list of quota settings in the cluster will be completely overwritten by the list provided in the
quotas
parameter.Before executing your request, make sure the list includes all the required quota settings, including existing ones.
You can get the cluster ID with a list of clusters in the folder. You can request the user name with the list of users in the cluster.
-
-
View the server response to make sure the request was successful.
-
Connect to a cluster using the
admin
account. -
To change a set of user privileges and roles, use the GRANT
and REVOKE queries. For example, grant the user read rights to all objects in a specific database:GRANT SELECT ON <DB_name>.* TO <username>;
-
To edit a user's quota settings, use the CREATE QUOTA
, ALTER QUOTA , and DROP QUOTA queries. For example, limit the total number of user requests for a 15-month period:CREATE QUOTA <quota_name> FOR INTERVAL 15 MONTH MAX QUERIES 100 TO <username>;
-
To change the user account, use the ALTER USER
query. To edit the ClickHouse® settings, for instance, run the command below listing the settings to modify:ALTER USER <username> SETTINGS <list_of_ClickHouse®>_settings;
Deleting a user
- In the management console
, go to the folder page and select Managed Service for ClickHouse. - Click the cluster name and open the Users tab.
- Click
and select Delete.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To remove a user, run:
yc managed-clickhouse user delete <username> \
--cluster-name=<cluster_name>
You can request the cluster name with a list of clusters in the folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Delete the
user
block with the user's description from the Managed Service for ClickHouse® cluster description. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring one from a backup: 60 minutes.
- Editing a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the User.delete method and send the following request, e.g., via cURL
:curl \ --request DELETE \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/users/<username>'
You can get the cluster ID with a list of clusters in the folder. You can request the user name with the list of users in the cluster.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the UserService.Delete call and send the following request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "user_name": "<username>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.UserService.Delete
You can get the cluster ID with a list of clusters in the folder. You can request the user name with the list of users in the cluster.
-
View the server response to make sure the request was successful.
To learn more about deleting objects, see the ClickHouse® documentation
Examples
Creating a read-only user
Let's say you need to add a new user named ro-user
with the Passw0rd
password to the existing mych
cluster with the cat0adul1fj0********
ID, and:
- The user has access to the
db1
database of the cluster. - The access is read-only, so the user is not allowed to change any settings.
- In the management console
, go to the folder page and select Managed Service for ClickHouse. - Click the
mych
cluster and select the Users tab. - Click Create user.
- Enter
ro-user
as the DB username andPassw0rd
as the password. - Click
and select thedb1
database from the drop-down list. - Select Additional settings → Settings → Readonly.
- Set the Readonly field value to
1
. - Click Create.
Run the command:
yc managed-clickhouse user create "ro-user" \
--cluster-name="mych" \
--password="Passw0rd" \
--permissions="db1" \
--settings="readonly=1"
After creating the user, check that it is actually in read-only mode:
-
Connect to the
mych
cluster as thero-user
you created. -
Try changing a setting, for example, disable read-only mode:
SET readonly=0
As a result, the command should return a message stating that you cannot change the setting in read-only mode:
DB::Exception: Cannot modify 'readonly' setting in readonly mode.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Add the
user
section to the cluster description.resource "yandex_mdb_clickhouse_cluster" "mych" { name = "mych" database { name = "db1" } user { name = "ro-user" password = "Passw0rd" permission { database_name = "db1" } settings { readonly = 1 } } ... }
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Make a request using cURL
:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/cat0adul1fj0********/users' \ --data '{ "userSpec": { "name": "ro-user", "password": "Passw0rd", "permissions": [ { "databaseName": "db1" } ], "settings": { "readonly": "1" } } }'
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Make a request using gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "cat0adul1fj0********", "user_spec": { "name": "ro-user", "password": "Passw0rd", "permissions": [ { "database_name": "db1" } ], "settings": { "readonly": "1" } } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.UserService.Create
-
Connect to the
mych
cluster using theadmin
account. -
Create a user:
CREATE USER ro-user IDENTIFIED WITH sha256_password BY 'Passw0rd';
-
Grant the user read rights to all objects in the
db1
database:GRANT SELECT ON db1.* TO ro-user;
ClickHouse® is a registered trademark of ClickHouse, Inc