Managing Yandex StoreDoc users
You can add and remove users, manage individual user settings, and change database access permissions.
Getting a list of users
- Open the folder dashboard
. - Navigate to the Yandex StoreDoc service.
- Locate the cluster you need in the list, click its name, and select the
Users tab.
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 get a list of cluster users, run this command:
yc managed-mongodb user list \
--cluster-name <cluster_name>
You can get the cluster name from the list of clusters in your folder.
-
Get an IAM token for API authentication and place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the User.List method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/users'You can get the cluster ID from the list of clusters in your folder.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and place 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. -
Call the UserService.List method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.UserService.ListYou can get the cluster ID from the list of clusters in your folder.
-
Check the server response to make sure your request was successful.
Creating a user
-
Open the folder dashboard
. -
Navigate to the Yandex StoreDoc service.
-
Click the name of your cluster and open the
Users tab. -
Click Create user.
-
Enter the database user’s name and password.
Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter, number, or underscore.
The password must be between 8 and 128 characters.
-
Configure the user’s roles:
- Click Add database and select the database for role assignment.
- Add roles using the
button.
You can assign a user multiple roles across different databases.
-
Click Create.
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 create a cluster user:
-
See the description of the CLI command for creating a user:
yc managed-mongodb user create --help -
Specify user properties in the creation command:
yc managed-mongodb user create <username> \ --cluster-name <cluster_name> \ --password <user_password> \ --permission database=<DB_name>,role=<role>,role=<other_role>,... \ --permission database=<other_DB_name>,role=<role>,...Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter, number, or underscore.
The password must be between 8 and 128 characters.
You can get the cluster name from the list of clusters in your folder.
-
Open the current Terraform configuration file describing your infrastructure.
To learn how to create this file, see Creating a cluster.
-
Add the
yandex_mdb_mongodb_userresource:resource "yandex_mdb_mongodb_user" "<username>" { cluster_id = <cluster_ID> name = "<username>" password = "<password>" permission { database_name = "<DB_name>" roles = [ "<list_of_user_roles>" ] } }Where
database_nameis the name of the target database for user access.Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter, number, or underscore.
The password must be between 8 and 128 characters.
-
Validate your configuration.
-
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 resource changes.
-
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 place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the User.Create method, e.g., via the following cURL
request:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/users' \ --data '{ "userSpec": { "name": "<username>", "password": "<user_password>", "permissions": [ { "databaseName": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] } }'Where
userSpecare the new database user’s settings:-
name: Username. -
password: Password.Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter, number, or underscore.
The password must be between 8 and 128 characters.
-
permissions: User permissions:databaseName: Name of the database the user can access.roles: User roles as an array of strings, one per role. Possible values are listed in Users and roles.
In the
permissionsarray, add a separate element with permission settings for each database.
You can get the cluster ID from the list of clusters in your folder.
-
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and place 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. -
Call the UserService.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/mdb/mongodb/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "user_spec": { "name": "<username>", "password": "<user_password>", "permissions": [ { "database_name": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.UserService.CreateWhere
user_specare the settings for the new database user:-
name: Username. -
password: Password.Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter, number, or underscore.
The password must be between 8 and 128 characters.
-
permissions: User permissions:database_name: Name of the database the user can access.roles: User roles as an array of strings, one per role. Possible values are listed in Users and roles.
In the
permissionsarray, add a separate element with permission settings for each database.
You can get the cluster ID from the list of clusters in your folder.
-
-
Check the server response to make sure your request was successful.
Updating user settings
-
Open the folder dashboard
. -
Navigate to the Yandex StoreDoc service.
-
Click the name of your cluster and open the
Users tab. -
To change a user’s password, locate the user in the list, click
in their row, and select Change password.Note
The password must be from 8 to 128 characters long.
-
To change the user's roles:
- Locate the user you need in the list, click
in their row, and select Configure. - To add a role, click
next to the target database and select the role you want to assign. - To delete a role, click
next to its name.
- Locate the user you need in the list, click
-
Click Save.
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 change a user's password or role assignments:
-
See the description of the CLI command for updating a user:
yc managed-mongodb user update --help -
Specify user properties in the
user updatecommand:yc managed-mongodb user update <username> \ --cluster-name <cluster_name> \ --password <user_password> \ --permission database=<DB_name>,role=<role>,role=<other_role>,... \ --permission database=<other_DB_name>,role=<role>,...Note
The password must be from 8 to 128 characters long.
To grant a user access to a database with a specific set of roles:
-
See the description of the CLI command for granting user permissions:
yc managed-mongodb user grant-permission --help -
Specify user properties in the
user grant permissioncommand:yc managed-mongodb user grant-permission <username> \ --cluster-name <cluster_name> \ --database <DB_name> \ --role <list_of_roles_separated_by_commas>
To revoke database access from a user:
-
See the description of the CLI command for revoking user permissions:
yc managed-mongodb user revoke-permission --help -
Specify user properties in the
user revoke permissioncommand:yc managed-mongodb user revoke-permission <username> \ --cluster-name <cluster_name> \ --database <DB_name>This command revokes the user’s access to the specified database.
You can get the cluster’s name from the list of clusters in your folder, the database name from the list of your cluster databases, and the user's name from the list of cluster users.
-
Open the current Terraform configuration file describing your infrastructure.
To learn how to create this file, see Creating a cluster.
-
Locate the
yandex_mdb_mongodb_userresource. -
Update the
passwordandpermissionsettings:resource "yandex_mdb_mongodb_user" "<username>" { cluster_id = <cluster_ID> name = "<username>" password = "<new_password>" permission { database_name = "<DB_name>" roles = [ "<new_list_of_user_roles>" ] } }Note
The password must be from 8 to 128 characters long.
-
Validate your configuration.
-
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 resource changes.
-
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 place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the User.Update method, e.g., via the following cURL
request: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
updateMaskparameter 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-mongodb/v1/clusters/<cluster_ID>/users/<username>' \ --data '{ "updateMask": "password,permissions.databaseName,permissions.roles", "password": "<user_password>", "permissions": [ { "databaseName": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] }'Where:
-
updateMask: Comma-separated list of settings you want to update. -
password: Password.Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter, number, or underscore.
The password must be between 8 and 128 characters.
-
permissions: User permission settings:database_name: Name of the database to which the user will have access.roles: Array of user roles. Each role is provided as a separate string in the array. For the list of possible values, see Users and roles.
You can get the cluster ID from the folder’s cluster list, and the username from the list of cluster users.
-
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and place 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. -
Call the UserService.Update method, e.g., via the following gRPCurl
request: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_maskparameter 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/mongodb/v1/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "user_name": "<username>", "update_mask": { "paths": [ "password", "permissions.database_name", "permissions.roles" ] }, "password": "<user_password>", "permissions": [ { "database_name": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.UserService.UpdateWhere:
-
update_mask: Comma-separated list of settings you want to update. -
password: Password.Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter, number, or underscore.
The password must be between 8 and 128 characters.
-
permissions: User permissions:database_name: Name of the database the user can access.roles: User roles as an array of strings, one per role. Possible values are listed in Users and roles.
You can get the cluster ID from the list of clusters in your folder, and the username from the list of cluster users.
-
-
Check the server response to make sure your request was successful.
Deleting a user
- Open the folder dashboard
. - Navigate to the Yandex StoreDoc service.
- Click the name of your cluster and open the
Users tab. - Locate the user you need in the list, click
in their row, and select Delete.
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 delete a user, run this command:
yc managed-mongodb user delete <username> \
--cluster-name <cluster_name>
You can get the cluster name from the list of clusters in your folder.
-
Open the current Terraform configuration file describing your infrastructure.
To learn how to create this file, see Creating a cluster.
-
Delete the
yandex_mdb_mongodb_userresource with the target user’s description. -
Validate your configuration.
-
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 resource changes.
-
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 place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the User.Delete method, e.g., via the following cURL
request:curl \ --request DELETE \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/users/<username>'You can get the cluster ID from the list of clusters in your folder, and the username from the list of cluster users.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and place 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. -
Call the UserService.Delete method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/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.mongodb.v1.UserService.DeleteYou can get the cluster ID from the list of clusters in your folder, and the username from the list of cluster users.
-
Check the server response to make sure your request was successful.
Examples
Add a user with read-only permissions
To add a new user2 account with read-only access for the db1 database to an existing cluster:
- Go to the folder
page. - Go to Yandex StoreDoc.
- Click the name of your cluster and open the
Users tab. - Click Create user.
- Enter
user2for username and enter a password (from 8 to 128 characters). - Select the
db1database from the Add database drop-down list. - Select the
readrole from the drop-down list next to thedb1database. - Click Create.
Run this command:
yc managed-mongodb user create user2 \
--cluster-name <cluster_name> \
--password <user_password> \
--permission database=db1,role=read
-
Open the current Terraform configuration file describing your infrastructure.
Learn how to create this file in Creating a cluster.
-
Add the
yandex_mdb_mongodb_userresource:resource "yandex_mdb_mongodb_user" "user2" { cluster_id = <cluster_ID> name = "user2" password = "<password>" permission { database_name = "db1" roles = [ "read" ] } } -
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.
Modify user permissions
To grant read-only access to the db2 database to an existing cluster1 user named user1:
Run this command:
yc managed-mongodb user grant-permission user1 \
--cluster-name cluster1 \
--database db2 \
--role read
-
Open the current Terraform configuration file describing your infrastructure.
Learn how to create this file in Creating a cluster.
-
Find the
yandex_mdb_mongodb_userresource. -
Add the
permissionsection:resource "yandex_mdb_mongodb_user" "user1" { cluster_id = <cluster_ID> name = "user1" password = "<password>" permission { database_name = "db2" roles = [ "read" ] } } -
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.