Skip to content

Commit 3533033

Browse files
fix(mdb): multi-user - MTA-6329 (#5377)
1 parent 946b4e0 commit 3533033

File tree

3 files changed

+183
-124
lines changed

3 files changed

+183
-124
lines changed

menu/navigation.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,10 @@
24502450
},
24512451
{
24522452
"items": [
2453+
{
2454+
"label": "Managing users",
2455+
"slug": "managing-users-api"
2456+
},
24532457
{
24542458
"label": "Back up and restore MongoDB® Databases",
24552459
"slug": "backup-and-restore"
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: Managing MongoDB® users with the Scaleway API
3+
description: This page explains how to manage MongoDB® users via the API
4+
tags: managed-database database postgresql mongodb database-instance mongodb
5+
dates:
6+
validation: 2025-05-08
7+
posted: 2025-04-08
8+
---
9+
10+
When you create your MongoDB® Database Instance, a default user with administrative privileges is automatically created.
11+
12+
You can create more users and grant them pre-set roles via the [Scaleway Managed MongoDB® API](https://www.scaleway.com/en/developers/api/managed-database-mongodb/).
13+
14+
<Message type="important">
15+
All users you create initially have administrator roles, which can be modified after creation using the [Apply user roles](https://www.scaleway.com/en/developers/api/managed-database-mongodb/#path-users-apply-user-roles) API call. However, the default user's role cannot be changed.
16+
</Message>
17+
18+
### How to create a user
19+
20+
1. Edit the POST request payload you will use to create your user. Replace the values of each parameter with your values of choice following the parameter descriptions below.
21+
```
22+
{
23+
"name": "<username>",
24+
"password": "<password>",
25+
}
26+
```
27+
28+
| Parameter | Description |
29+
| :--------------- | :----------------------------------------------------------------- |
30+
| `name` | Set a name for the database user. |
31+
| `password` | Set a password for the database user.|
32+
33+
2. Run the following command to create a user. Make sure you include the payload you edited in the previous step. `{instance_id}` corresponds to the UUID of the Managed MongoDB®.
34+
```
35+
curl -X POST \
36+
-H "X-Auth-Token: $SCW_SECRET_KEY" \
37+
-H "Content-Type: application/json" \
38+
-d '{
39+
"name": "<username>",
40+
"password": "<password>",
41+
}' \
42+
"https://api.scaleway.com/mongodb/v1alpha1/regions/$SCW_REGION/par/instances/{instance_id}/users"
43+
```
44+
45+
You should get a response like the following:
46+
```
47+
{
48+
"name": "<username>",
49+
"password": "<password>",
50+
"roles": [
51+
{
52+
"role": "read_write",
53+
"any_database": true
54+
},
55+
{
56+
"role": "db_admin",
57+
"any_database": true
58+
},
59+
{
60+
"role": "sync",
61+
"any_database": true
62+
}
63+
]
64+
}
65+
```
66+
67+
All users you create will have the `read_write`, `db_admin` and `sync` roles on all databases by default.
68+
69+
You can follow the steps below to update a user's role(s) to the one(s) of your choice.
70+
71+
### How to apply a role to a user
72+
73+
1. Edit the POST request payload you will use to update the user role. Replace the values of each parameter with your values of choice following the parameter descriptions below.
74+
75+
In this example, we define a single `read_write` role for the user. This role applies only in the `example-db` database.
76+
77+
<Message type="tip">
78+
To grant the user this role in all databases, you can set `any_database` to true.
79+
</Message>
80+
81+
```
82+
{
83+
"name": "<username>",
84+
"roles": [
85+
{
86+
"role": "read_write",
87+
"database": "example-db",
88+
"any_database": false
89+
}
90+
]
91+
}
92+
```
93+
94+
| Role | Description |
95+
| :--------------- | :----------------------------------------------------------------- |
96+
| `read` | Read privileges on all non-system collections and the `system.js` collection. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/manual/reference/built-in-roles/#mongodb-authrole-read) for an extensive list of the privileges granted to this role. |
97+
| `read_write` | Read and write privileges on all non-system collections and the `system.js` collection. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/manual/reference/built-in-roles/#mongodb-authrole-readWrite) for an extensive list of the privileges granted to this role. |
98+
| `db_admin` | Privileges to perform administrative tasks on the database, such as schema-related tasks, indexing, and gathering statistics. This role does not grant privileges for user and role management. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/manual/reference/built-in-roles/#mongodb-authrole-dbAdmin) for an extensive list of the privileges granted to this role. |
99+
| `sync` | Role that aggregates three MongoDB roles: |
100+
| | `clusterMonitor` - Read-only access to monitoring tools. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/upcoming/reference/built-in-roles/#mongodb-authrole-clusterMonitor) for an extensive list of the privileges granted to this role. |
101+
| | `backup` - Grants the minimal privileges needed to back up data. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/upcoming/reference/built-in-roles/#mongodb-authrole-backup) for an extensive list of the privileges granted to this role. |
102+
| | `restore` - Grants the privileges needed to restore data from backups. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/upcoming/reference/built-in-roles/#mongodb-authrole-restore) for an extensive list of the privileges granted to this role. |
103+
104+
2. Run the following command to apply a new role to the user. Make sure you include the payload you edited in the previous step and that you replace the parameters in the call with your information. `{instance_id}` corresponds to the UUID of the Managed MongoDB®.
105+
106+
```
107+
curl -X PUT \
108+
-H "X-Auth-Token: $SCW_SECRET_KEY" \
109+
-H "Content-Type: application/json" \
110+
-d '{
111+
"name": "<username>",
112+
"roles": [
113+
{
114+
"role": "read_write",
115+
"database": "<name_of_database>"
116+
"any_database": false
117+
}
118+
]
119+
}' \
120+
"https://api.scaleway.com/mongodb/v1alpha1/regions/$SCW_REGION/instances/{instance_id}/roles"
121+
```
122+
123+
If the call was successful, you will get the payload with the new role(s) as a response.
124+
125+
<Message type="note">
126+
Assigning roles upon user creation will be possible by the second half of 2025. Refer to the [Scaleway Changelog](/changelog/?product=mongodb) to keep up with the latest Managed MongoDB® updates.
127+
</Message>
128+
129+
Lines changed: 50 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: How to manage a MongoDB® Database Instance user
3-
description: This page explains how to manage the MongoDB® Database Instance default user
3+
description: This page explains how to manage MongoDB® Database Instance users
44
tags: managed-database database postgresql mongodb database-instance mongodb
55
dates:
66
validation: 2025-04-08
@@ -18,133 +18,59 @@ Users can connect to a database and access its data.
1818
- A valid [API key](/iam/how-to/create-api-keys/)
1919
- A [MongoDB® Database Instance](/managed-mongodb-databases/quickstart)
2020

21-
## How to change the password of your user
21+
## How to create a new user
22+
23+
1. Click **MongoDB® Databases** under **Databases** on the side menu. A list of your Database Instances displays.
24+
2. Click the database name to access the Database Instance information page.
25+
3. Go to the **Users** tab.
26+
4. Click **Create user**. A pop-up appears.
27+
5. Enter a username and password for the user.
28+
6. Click **Create User** to confirm. Your user is created. The privilege configuration wizard displays.
29+
7. Set the privileges of your new user. You can select one or both of the following:
30+
31+
- **Global roles** - the privileges you set will apply to all your databases, existing and future. You can set one or more global roll at a time. The available global roles include:
32+
- **Ready-only** (`read`) - Read privileges on all non-system collections and the `system.js` collection.
33+
- **Read and write** (`read_write`) - Read and write privileges on all non-system collections and the `system.js` collection.
34+
- **Sync** (`sync`) - Role that aggregates three MongoDB roles: `clusterMonitor`, `backup` and `restore`. This role can only be granted as a global role
35+
- **DB admin** (`db_admin`) - Privileges to perform administrative tasks on the database, such as schema-related tasks, indexing, and gathering statistics. This role does not grant privileges for user and role management.
36+
- **Specific roles** - the privileges will only apply to the databases you define. All global roles except `sync` can also be defined as specific roles.
37+
38+
<Message type="important">
39+
You can manually enter a database that does not yet appear in the list and set privileges for it. This might be helpful as it can take up to 15 minutes before a recently created database appears in the list. You can also set privileges for databases before you create them. Keep in mind that the name you define in this step must be identical in spelling to that of the actual database.
40+
</Message>
41+
42+
<Message type="tip">
43+
Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/manual/reference/built-in-roles/) for an extensive list of the privileges granted to each role.
44+
</Message>
45+
46+
If you set a **global role**, select one or more roles in the drop-down.
47+
48+
If you set **specific roles**, enter the database(s) to which you want to apply the role first, then click **Set privileges**.
49+
Check the box corresponding to the role(s) you wish to apply to each database in the list.
50+
51+
8. Click **Confirm** after reviewing your configuration.
52+
53+
The list of your users is updated. You can see an overview of the global and speficic roles next to the name of each user.
54+
55+
## How to update user privileges
56+
57+
1. Click **MongoDB® Databases** under **Databases** on the side menu. A list of your Database Instances displays.
58+
2. Click the database name to access the Database Instance information page.
59+
3. Go to the **Users** tab.
60+
4. Click <Icon name="more" />, then **Update privileges**. A pop-up appears.
61+
5. Update the privileges according to your preferences, following the instructions described in step 7 of the [procedure above](#how-to-create-a-new-user).
62+
6. Click **Update** after reviewing your configuration.
63+
64+
## How to change user passwords
2265

2366
1. Click **MongoDB® Databases** under **Databases** on the side menu. A list of your Database Instances displays.
2467
2. Click the database name or <Icon name="more" /> > **More info** to access the Database Instance information page.
25-
3. Go to the **Users** tab. Your default user displays.
26-
4. Click **Change password** to do so. A pop-up appears.
68+
3. Go to the **Users** tab.
69+
4. Click <Icon name="more" />, then **Change password**. A pop-up appears.
2770
5. Enter your new password and confirm.
2871

29-
## How to create multi-users via the API
30-
31-
When you create your MongoDB® Database Instance, the first user is created by default and has admin rights.
32-
33-
You can create more users and grant them pre-set roles via the [Scaleway Managed MongoDB® API](https://www.scaleway.com/en/developers/api/managed-database-mongodb/).
34-
35-
<Message type="important">
36-
All users you create have at first administrator roles, which can be changed after creation with the [Apply user roles](https://www.scaleway.com/en/developers/api/managed-database-mongodb/#path-users-apply-user-roles) call. The default user's role cannot be changed.
37-
</Message>
38-
39-
### How to create a user
40-
41-
1. Edit the POST request payload you will use to create your user. Replace the values of each parameter with your values of choice following the parameter descriptions below.
42-
```
43-
{
44-
"name": "<username>",
45-
"password": "<password>",
46-
}
47-
```
48-
49-
| Parameter | Description |
50-
| :--------------- | :----------------------------------------------------------------- |
51-
| `name` | Set a name for the database user. |
52-
| `password` | Set a password for the database user.|
53-
54-
2. Run the following command to create a user. Make sure you include the payload you edited in the previous step. `{instance_id}` corresponds to the UUID of the Managed MongoDB®.
55-
```
56-
curl -X POST \
57-
-H "X-Auth-Token: $SCW_SECRET_KEY" \
58-
-H "Content-Type: application/json" \
59-
-d '{
60-
"name": "<username>",
61-
"password": "<password>",
62-
}' \
63-
"https://api.scaleway.com/mongodb/v1alpha1/regions/$SCW_REGION/par/instances/{instance_id}/users"
64-
```
65-
66-
You should get a response like the following:
67-
```
68-
{
69-
"name": "<username>",
70-
"password": "<password>",
71-
"roles": [
72-
{
73-
"role": "read_write",
74-
"any_database": true
75-
},
76-
{
77-
"role": "db_admin",
78-
"any_database": true
79-
},
80-
{
81-
"role": "sync",
82-
"any_database": true
83-
}
84-
]
85-
}
86-
```
87-
88-
All users you create will have the `read_write`, `db_admin` and `sync` roles on all databases by default.
89-
90-
You can follow the steps below to update a user's role(s) to the one(s) of your choice.
91-
92-
### How to apply a role to a user
93-
94-
1. Edit the POST request payload you will use to update the user role. Replace the values of each parameter with your values of choice following the parameter descriptions below.
95-
96-
In this example, we define a single `read_write` role for the user. This role applies only in the `example-db` database.
97-
98-
<Message type="tip">
99-
To grant the user this role in all databases, you can set `any_database` to true.
100-
</Message>
101-
102-
```
103-
{
104-
"name": "<username>",
105-
"roles": [
106-
{
107-
"role": "read_write",
108-
"database": "example-db",
109-
"any_database": false
110-
}
111-
]
112-
}
113-
```
114-
115-
| Role | Description |
116-
| :--------------- | :----------------------------------------------------------------- |
117-
| `read` | Read privileges on all non-system collections and the `system.js` collection. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/manual/reference/built-in-roles/#mongodb-authrole-read) for an extensive list of the privileges granted to this role. |
118-
| `read_write` | Read and write privileges on all non-system collections and the `system.js` collection. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/manual/reference/built-in-roles/#mongodb-authrole-readWrite) for an extensive list of the privileges granted to this role. |
119-
| `db_admin` | Privileges to perform administrative tasks on the database, such as schema-related tasks, indexing, and gathering statistics. This role does not grant privileges for user and role management. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/manual/reference/built-in-roles/#mongodb-authrole-dbAdmin) for an extensive list of the privileges granted to this role. |
120-
| `sync` | Role that aggregates three MongoDB roles: |
121-
| | `clusterMonitor` - Read-only access to monitoring tools. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/upcoming/reference/built-in-roles/#mongodb-authrole-clusterMonitor) for an extensive list of the privileges granted to this role. |
122-
| | `backup` - Grants the minimal privileges needed to back up data. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/upcoming/reference/built-in-roles/#mongodb-authrole-backup) for an extensive list of the privileges granted to this role. |
123-
| | `restore` - Grants the privileges needed to restore data from backups. Refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/upcoming/reference/built-in-roles/#mongodb-authrole-restore) for an extensive list of the privileges granted to this role. |
124-
125-
2. Run the following command to apply a new role to the user. Make sure you include the payload you edited in the previous step and that you replace the parameters in the call with your information. `{instance_id}` corresponds to the UUID of the Managed MongoDB®.
126-
127-
```
128-
curl -X PUT \
129-
-H "X-Auth-Token: $SCW_SECRET_KEY" \
130-
-H "Content-Type: application/json" \
131-
-d '{
132-
"name": "<username>",
133-
"roles": [
134-
{
135-
"role": "read_write",
136-
"database": "<name_of_database>"
137-
"any_database": false
138-
}
139-
]
140-
}' \
141-
"https://api.scaleway.com/mongodb/v1alpha1/regions/$SCW_REGION/instances/{instance_id}/roles"
142-
```
143-
144-
If the call was successful, you will get the payload with the new role(s) as a response.
145-
146-
<Message type="note">
147-
Assigning roles upon user creation will be possible by the second half of 2025. Refer to the [Scaleway Changelog](/changelog/?product=mongodb) to keep up with the latest Managed MongoDB® updates.
148-
</Message>
72+
73+
74+
14975

15076

0 commit comments

Comments
 (0)