Skip to content

Commit d9b3907

Browse files
committed
aligning to the review
1 parent f7be186 commit d9b3907

File tree

9 files changed

+110
-116
lines changed

9 files changed

+110
-116
lines changed

docs/atlas/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_position: 2
55
import Tabs from '@theme/Tabs';
66
import TabItem from '@theme/TabItem';
77

8-
# MongoDB Security Configuration
8+
# 📘 MongoDB Security Configuration
99

1010
This guide covers essential security configurations for MongoDB deployments. Learn how to secure your databases using best practices for both Atlas and On-premises installations.
1111

@@ -171,4 +171,4 @@ net:
171171
172172
## Next Steps
173173
174-
Let's start the network access control [challenge](./challenge/network)
174+
Let's start the network access control [challenge](./challenge/network)

docs/challenge/authentication.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sidebar_position: 2
33
---
44

55

6-
# RUN : Authentication challenge
6+
# 👐 RUN : Authentication challenge
77

88
> Hint! Remember to add the `--projectId {project_id}`
99
@@ -14,16 +14,17 @@ sidebar_position: 2
1414

1515
```python
1616
# CODE_BLOCK_7
17-
!atlas dbusers create ...
17+
!atlas dbusers create <CODE_BLOCK_7>
1818
```
1919

20-
20+
:::tip
2121
<details>
2222
<summary> Answer </summary>
2323
```
2424
!atlas dbusers create --username myUser --password mySecurePassword --role readWriteAnyDatabase --projectId {project_id}
2525
```
2626
</details>
27+
:::
2728
2829
### 2. Lets test our SCRAM user successful creation by performing the authentication process
2930
```python
@@ -52,9 +53,10 @@ client.list_database_names()
5253
# CODE_BLOCK_10
5354
!atlas dbusers create ...
5455

55-
!atlas dbusers certs create ... > /tmp/cert.pem
56+
!atlas dbusers certs create <CODE_BLOCK_10> > /tmp/cert.pem
5657
```
5758

59+
:::tip
5860
<details>
5961
<summary> Answer </summary>
6062
```
@@ -64,6 +66,7 @@ client.list_database_names()
6466
!atlas dbusers certs create --username myX509User --monthsUntilExpiration 1 --projectId {project_id} > /tmp/cert.pem
6567
```
6668
</details>
69+
:::
6770

6871
### 4. Let's test our X509 User
6972

docs/challenge/network.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sidebar_position: 1
33
---
44

55

6-
# RUN : Network challenge
6+
# 👐 RUN : Network challenge
77

88
### 1. Add 'My current IP' temporary into the atlas project
99

@@ -14,9 +14,10 @@ from datetime import datetime, timedelta
1414
# Calculate the date and time 24 hours from now
1515
delete_after = (datetime.utcnow() + timedelta(hours=24)).isoformat() + 'Z'
1616

17-
!atlas accessLists ...
17+
!atlas accessLists <CODE_BLOCK_5>
1818
```
1919

20+
:::tip
2021
> Docs : atlas [accessList](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-accessLists/#std-label-atlas-accessLists)
2122
2223
<details>
@@ -33,6 +34,8 @@ delete_after = (datetime.utcnow() + timedelta(hours=24)).isoformat() + 'Z'
3334
```
3435
</details>
3536
37+
:::
38+
3639
### 2. Check that 'My current IP' was added:
3740
```python
3841
# CODE_BLOCK_6

docs/challenge/queryable-encryption.mdx

Lines changed: 49 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
sidebar_position: 2
33
---
44

5-
# RUN : Queryable Encryption challenge
5+
# 👐 RUN : Queryable Encryption challenge
66

7-
> Hint! Remember to add the `--projectId {project_id}`
7+
:::tip
8+
Remember to add the `--projectId {project_id}`
9+
:::
810

11+
:::info
912
> Docs : [CSFLE](https://www.mongodb.com/docs/atlas/app-services/data-api/csfle/)
13+
:::
1014

1115
### 1. Install the necessary packages.
1216

@@ -89,17 +93,6 @@ client = MongoClient(new_connection)
8993
```python
9094
# CODE_BLOCK_19
9195

92-
import os
93-
from pymongo import MongoClient
94-
from pymongo.encryption import Algorithm, ClientEncryption, QueryType
95-
from pymongo.encryption_options import AutoEncryptionOpts
96-
from bson.codec_options import CodecOptions
97-
from bson import json_util
98-
import json
99-
import requests
100-
import platform
101-
import tempfile
102-
10396
local_master_key = os.urandom(96)
10497
kms_providers = {"local": {"key": local_master_key}}
10598
key_vault_namespace = "encryption.__keyVault"
@@ -119,60 +112,54 @@ auto_encryption_options = AutoEncryptionOpts(
119112
encrypted_client = MongoClient(
120113
new_connection, auto_encryption_opts=auto_encryption_options)
121114

122-
# TODO CODE_BLOCK_19
123-
124-
encrypted_fields_map = ...
125-
126115
client_encryption = ClientEncryption(
127116
kms_providers=kms_providers,
128117
key_vault_namespace=key_vault_namespace,
129118
key_vault_client=encrypted_client,
130119
codec_options=CodecOptions()
131120
)
121+
```
122+
123+
### 5. Consider the following patient document:
124+
125+
```python
126+
patient_document = {
127+
"patientName": "Jon Doe",
128+
"patientId": 12345678,
129+
"patientRecord": {
130+
"ssn": "987-65-4320",
131+
"billing": {
132+
"type": "Visa",
133+
"number": "4111111111111111",
134+
},
135+
},
136+
}
137+
```
138+
### 6. Create an encrypted collection based on the following requirements:
139+
- 'patientId' and 'billing' must be encrypted
140+
- patients will be queried by 'patientId'
141+
142+
```python
143+
# TODO CODE_BLOCK_19
144+
145+
encrypted_fields_map = <CODE_BLOCK_19>
132146

133147
# TODO CODE_BLOCK_19
134148

135149
client_encryption.create_encrypted_collection(
136150
encrypted_client[encrypted_database_name],
137151
encrypted_collection_name,
138-
... ,
152+
<CODE_BLOCK_19>,
139153
kms_provider_name,
140154
{},
141155
)
142156

143157
```
158+
159+
:::tip
144160
<details>
145161
<summary> Answer </summary>
146162
```python
147-
import os
148-
from pymongo import MongoClient
149-
from pymongo.encryption import Algorithm, ClientEncryption, QueryType
150-
from pymongo.encryption_options import AutoEncryptionOpts
151-
from bson.codec_options import CodecOptions
152-
from bson import json_util
153-
import json
154-
import requests
155-
import platform
156-
import tempfile
157-
158-
local_master_key = os.urandom(96)
159-
kms_providers = {"local": {"key": local_master_key}}
160-
key_vault_namespace = "encryption.__keyVault"
161-
kms_provider_name="local"
162-
key_vault_database_name = "encryption"
163-
key_vault_collection_name = "__keyVault"
164-
key_vault_namespace = f"{key_vault_database_name}.{key_vault_collection_name}"
165-
encrypted_database_name = "medicalRecords"
166-
encrypted_collection_name = "patients"
167-
168-
auto_encryption_options = AutoEncryptionOpts(
169-
kms_providers,
170-
key_vault_namespace,
171-
crypt_shared_lib_path=crypt_shared_lib_path
172-
)
173-
174-
encrypted_client = MongoClient(
175-
new_connection, auto_encryption_opts=auto_encryption_options)
176163

177164
encrypted_fields_map = {
178165
"fields": [
@@ -187,14 +174,6 @@ encrypted_fields_map = {
187174
}
188175
]
189176
}
190-
191-
client_encryption = ClientEncryption(
192-
kms_providers=kms_providers,
193-
key_vault_namespace=key_vault_namespace,
194-
key_vault_client=encrypted_client,
195-
codec_options=CodecOptions()
196-
)
197-
198177
client_encryption.create_encrypted_collection(
199178
encrypted_client[encrypted_database_name],
200179
encrypted_collection_name,
@@ -204,59 +183,44 @@ client_encryption.create_encrypted_collection(
204183
)
205184
```
206185
</details>
186+
:::
187+
188+
### 7. Insert an encrypted document.
207189
208-
### 5. Insert an encrypted document.
209190
210191
```python
211-
# TODO CODE_BLOCK_20
212192
213-
patient_document = {
214-
"patientName": "Jon Doe",
215-
"patientId": 12345678,
216-
"patientRecord": {
217-
"ssn": "987-65-4320",
218-
"billing": {
219-
"type": "Visa",
220-
"number": "4111111111111111",
221-
},
222-
},
223-
}
224193
225194
# TODO CODE_BLOCK_20
226195
227-
encrypted_collection = # encrypted_client ...
228-
result = encrypted_collection.insert_one(...)
196+
encrypted_collection = encrypted_client[encrypted_database_name][encrypted_collection_name]
197+
result = <CODE_BLOCK_20>
229198
print(f"Inserted document ID: {result.inserted_id}")
230199
```
200+
:::tip
231201
<details>
232202
<summary> Answer </summary>
233203
```python
234-
patient_document = {
235-
"patientName": "Jon Doe",
236-
"patientId": 12345678,
237-
"patientRecord": {
238-
"ssn": "987-65-4320",
239-
"billing": {
240-
"type": "Visa",
241-
"number": "4111111111111111",
242-
},
243-
},
244-
}
204+
245205
encrypted_collection = encrypted_client[encrypted_database_name][encrypted_collection_name]
246206
result = encrypted_collection.insert_one(patient_document)
247207
print(f"Inserted document ID: {result.inserted_id}")
248208
```
209+
210+
249211
</details>
212+
:::
250213
251214
### 6. Query the encrypted collection.
252215
253216
```python
254217
# TODO CODE_BLOCK_21
255218
256-
find_result = encrypted_collection.find_one(...)
219+
find_result = <CODE_BLOCK_21>
257220
print(find_result)
258221
...
259222
```
223+
:::tip
260224
<details>
261225
<summary> Answer </summary>
262226
```python
@@ -266,6 +230,7 @@ find_result = encrypted_collection.find_one({
266230
print(find_result)
267231
```
268232
</details>
233+
:::
269234
270235
### 7. Query the collection without encryption.
271236
@@ -285,6 +250,7 @@ print("\nAll documents in the collection:")
285250
for doc in all_docs:
286251
print(doc)
287252
```
253+
:::tip
288254
<details>
289255
<summary> Answer </summary>
290256
```python
@@ -303,6 +269,7 @@ for doc in all_docs:
303269
print(doc)
304270
```
305271
</details>
272+
:::
306273
307274
## Next Steps
308275

docs/challenge/rbac.mdx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,51 @@
22
sidebar_position: 2
33
---
44

5-
# RUN : RBAC challenge
5+
# 👐 RUN : RBAC challenge
6+
:::tip
67

7-
> Hint! Remember to add the `--projectId {project_id}`
8+
Remember to add the `--projectId {project_id}`
9+
:::
810

9-
> Docs : atlas [dbusers](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-dbusers-create/) , [customDbRoles](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-customDbRoles-create/)
11+
:::info
12+
13+
Docs : atlas [dbusers](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-dbusers-create/) , [customDbRoles](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-customDbRoles-create/)
14+
15+
:::
1016

1117
### 1. Let's create a user: 'myAdmin' with User/Password authentication and assign it the 'readWriteAnyDatabase' role, but only for the 'MyNewCluster' database.
1218

1319
```python
1420
# CODE_BLOCK_12
15-
!atlas dbusers create ...
21+
!atlas dbusers create <CODE_BLOCK_12>
1622
```
1723

24+
:::tip
1825
<details>
1926
<summary> Answer </summary>
2027
```python
2128
!atlas dbusers create --username myAdmin --password secureAdminPass --role readWriteAnyDatabase --scope 'MyNewCluster' --projectId {project_id}
2229
```
2330
</details>
31+
:::
2432
2533
### 2. Let's create a user: 'readOnlyUser' with read-only access to the 'salesDB' database.
2634
2735
```python
2836
# CODE_BLOCK_13
29-
!atlas customDbRoles create ...
30-
!atlas dbusers create ...
37+
!atlas customDbRoles create <CODE_BLOCK_13>
38+
!atlas dbusers create <CODE_BLOCK_13>
3139
```
3240

41+
:::tip
3342
<details>
3443
<summary> Answer </summary>
3544
```python
3645
!atlas customDbRoles create salesRead --inheritedRole read@salesDB --projectId {project_id}
3746
!atlas dbusers create --username readOnlyUser --password readOnlyPass --role salesRead --projectId {project_id}
3847
```
3948
</details>
49+
:::
4050
4151
### 3. Let's test that the 'readOnlyUser' cannot insert data into the 'salesDB' database.
4252

0 commit comments

Comments
 (0)