Skip to content

Commit 6686421

Browse files
fix(mongodb): apply role
1 parent 7bee026 commit 6686421

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

pages/managed-mongodb-databases/how-to/manage-users.mdx

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can create more users and grant them pre-set roles via the [Scaleway Managed
4242

4343
### How to create a user
4444

45-
1. Edit the POST request payload you will use to create your user. Replace the values of each parameters with your values of choice following the parameter descriptions below.
45+
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.
4646
```
4747
{
4848
"name": "<username>",
@@ -63,24 +63,83 @@ You can create more users and grant them pre-set roles via the [Scaleway Managed
6363
-d '{
6464
"name": "<username>",
6565
"password": "<password>",
66-
}' \
66+
}' \
6767
"https://api.scaleway.com/mongodb/v1alpha1/regions/fr-par/instances/{instance_id}/users"
6868
```
6969

7070
You should get a response like the following:
7171
```
7272
{
73-
"name": "<username>",
74-
"password": "<password>",
73+
"name": "<username>",
74+
"password": "<password>",
7575
"roles": [
76-
{
77-
"role": "<username>",
78-
"database": "<password>",
79-
"any_database": true
80-
}
76+
{
77+
"role": "read_write",
78+
"any_database": true
79+
},
80+
{
81+
"role": "db_admin",
82+
"any_database": true
83+
},
84+
{
85+
"role": "sync",
86+
"any_database": true
87+
}
8188
]
8289
}
8390
```
8491

92+
All users you create will have the `read_write`, `db_admin` and `sync` roles by default.
93+
94+
You can follow the steps below to update a user's role(s) to the one(s) of your choice.
95+
8596
### How to apply a role to a user
8697

98+
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.
99+
100+
In this example, we define a single `read_write` role for the user.
101+
102+
```
103+
{
104+
"name": "<username>",
105+
"roles": [
106+
{
107+
"role": "read_write",
108+
"any_database": true
109+
}
110+
]
111+
}
112+
```
113+
114+
| Role | Description |
115+
| :--------------- | :----------------------------------------------------------------- |
116+
| `read` | Read rights on the database |
117+
| `read_write` | Read and write rights on the database|
118+
| `db_admin` | |
119+
| `sync` | |
120+
121+
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®.
122+
123+
```
124+
curl -X PUT \
125+
-H "X-Auth-Token: $SCW_SECRET_KEY" \
126+
-H "Content-Type: application/json" \
127+
-d '{
128+
"name": "<username>",
129+
"roles": [
130+
{
131+
"role": "read_write",
132+
"any_database": true
133+
}
134+
]
135+
}' \
136+
"https://api.scaleway.com/mongodb/v1alpha1/regions/$SCW_REGION/instances/{instance_id}/roles"
137+
```
138+
139+
If the call was successful, you will get the payload with the new roles as a response.
140+
141+
<Message type="note">
142+
Assigning roles upon user creation will be available shortly. Refer to the [Scaleway Changelog](/docs/changelog/?product=mongodb) to keep up with the latest Managed MongoDB® updates.
143+
</Message>
144+
145+

0 commit comments

Comments
 (0)