Skip to content

Commit 6309b05

Browse files
authored
Merge pull request #1 from mongodb-developer/suggested-improvements
Suggested improvements
2 parents fc147b5 + b4ed015 commit 6309b05

File tree

10 files changed

+195
-177
lines changed

10 files changed

+195
-177
lines changed

docs/atlas/index.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,5 @@ 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).
175+

docs/challenge/authentication.mdx

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,77 @@ sidebar_position: 2
55

66
# 👐 RUN : Authentication challenge
77

8-
> Hint! Remember to add the `--projectId {project_id}`
8+
:::info
9+
The provided scripts are incomplete. Replace all `<CODE_BLOCK>` with the correct code to complete the lab.
10+
:::
911

10-
> Docs : atlas [dbusers](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-dbusers-create/)
12+
> Hint: Remember to add `--projectId {project_id}`
1113
1214

13-
### 1. Let's create a SCRAM user: 'myUser' with User/Password authentication and assign it the 'readWriteAnyDatabase' role.
15+
### 1. Create a SCRAM user
1416

1517
```python
16-
# CODE_BLOCK_7
17-
!atlas dbusers create <CODE_BLOCK_7>
18+
# create a SCRAM user with username: "myUser", password: "mySecurePassword" and role: "readWriteAnyDatabase"
19+
username = "myUser"
20+
password = "mySecurePassword"
21+
!atlas dbusers create <CODE_BLOCK>
1822
```
23+
> Refer to documentations: [atlas dbusers](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-dbusers-create/)
1924
2025
:::tip
2126
<details>
2227
<summary> Answer </summary>
28+
```python
29+
# create a SCRAM user with username: "myUser", password: "mySecurePassword" and role: "readWriteAnyDatabase"
30+
username = "myUser"
31+
password = "mySecurePassword"
32+
!atlas dbusers create --username {username} --password {password} --role readWriteAnyDatabase --projectId {project_id}
2333
```
24-
!atlas dbusers create --username myUser --password mySecurePassword --role readWriteAnyDatabase --projectId {project_id}
25-
```
2634
</details>
2735
:::
2836

2937
### 2. Lets test our SCRAM user successful creation by performing the authentication process
38+
3039
```python
31-
# CODE_BLOCK_8
3240
!pip install pymongo dnspython
3341
```
42+
3443
```python
35-
# CODE_BLOCK_9
44+
# retrieve connection string
3645
connection = !atlas clusters connectionStrings describe MyNewCluster --projectId {project_id}
3746

38-
username = 'myUser'
39-
password = 'mySecurePassword'
40-
47+
# add username and password to connection string
4148
new_connection = connection[1].replace('mongodb+srv://', f'mongodb+srv://{username}:{password}@')
4249
print(new_connection)
4350

51+
#make the connection get the list of databases
4452
from pymongo import MongoClient
4553
client = MongoClient(new_connection)
46-
4754
client.list_database_names()
4855
```
4956

50-
### 3. Let's create X509 user: 'myX509User' with User/Password authentication and assign it the 'readWriteAnyDatabase' role.
57+
### 3. Create a X509 user and certificate
5158

5259
```python
53-
# CODE_BLOCK_10
54-
!atlas dbusers create ...
55-
56-
!atlas dbusers certs create <CODE_BLOCK_10> > /tmp/cert.pem
60+
# create a Atlas-managed X509 user with username: "myX509User" and role: "readAnyDatabase"
61+
!atlas dbusers create <CODE_BLOCK>
62+
```
63+
> Refer to documentations: [atlas dbusers](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-dbusers-create/)
64+
```python
65+
# Generate a certification for "myX509user", set monthsUntilExpiration to 1, and save it to /tmp/cert.pem
66+
!atlas dbusers certs create <CODE_BLOCK> > /tmp/cert.pem
5767
```
68+
> Refer to documentations: [atlas dbusers certs](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-dbusers-certs-create/)
5869
5970
:::tip
6071
<details>
6172
<summary> Answer </summary>
73+
```python
74+
# create a Atlas-managed X509 user with username: "myX509User" and role: "readAnyDatabase"
75+
!atlas dbusers create --username myX509User --role readAnyDatabase --x509Type MANAGED --projectId {project_id}
6276
```
63-
# Generate an X509 certificate for a new user
64-
!atlas dbusers create --username myX509User --x509Type MANAGED --role readAnyDatabase --projectId {project_id}
65-
# Generate and save the certificate
77+
```python
78+
# Generate a certification for "myX509user", set monthsUntilExpiration to 1, and save it to /tmp/cert.pem
6679
!atlas dbusers certs create --username myX509User --monthsUntilExpiration 1 --projectId {project_id} > /tmp/cert.pem
6780
```
6881
</details>
@@ -71,9 +84,10 @@ client.list_database_names()
7184
### 4. Let's test our X509 User
7285

7386
```python
74-
# CODE_BLOCK_11
75-
username='myX509User'
87+
# Get connection string
7688
connection = !atlas clusters connectionStrings describe MyNewCluster --projectId {project_id}
89+
90+
# Modify connection string to use X509 as authentication mechanism
7791
new_connection = connection[1].replace('.net', '.net?authSource=%24external&authMechanism=MONGODB-X509')
7892
print(new_connection)
7993

@@ -84,7 +98,6 @@ client = MongoClient(new_connection,
8498

8599
# Access the database
86100
client.list_database_names()
87-
88101
```
89102
## Next Steps
90103

docs/challenge/network.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ sidebar_position: 1
55

66
# 👐 RUN : Network challenge
77

8+
:::info
9+
The provided scripts are incomplete. Replace all `<CODE_BLOCK>` with the correct code to complete the lab.
10+
:::
11+
812
### 1. Add 'My current IP' temporary into the atlas project
913

1014
```python
11-
# CODE_BLOCK_5
1215
from datetime import datetime, timedelta
1316

1417
# Calculate the date and time 24 hours from now
@@ -18,7 +21,7 @@ delete_after = (datetime.utcnow() + timedelta(hours=24)).isoformat() + 'Z'
1821
```
1922

2023
:::tip
21-
> Docs : atlas [accessList](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-accessLists/#std-label-atlas-accessLists)
24+
Docs : atlas [accessList](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-accessLists/#std-label-atlas-accessLists)
2225

2326
<details>
2427
<summary> Answer </summary>
@@ -28,8 +31,6 @@ delete_after = (datetime.utcnow() + timedelta(hours=24)).isoformat() + 'Z'
2831
# Calculate the date and time 24 hours from now
2932
delete_after = (datetime.utcnow() + timedelta(hours=24)).isoformat() + 'Z'
3033

31-
32-
3334
!atlas accessLists create --currentIp --projectId {project_id} --deleteAfter "{delete_after}"
3435
```
3536
</details>
@@ -38,7 +39,6 @@ delete_after = (datetime.utcnow() + timedelta(hours=24)).isoformat() + 'Z'
3839
3940
### 2. Check that 'My current IP' was added:
4041
```python
41-
# CODE_BLOCK_6
4242
!atlas accessLists list --output json --projectId {project_id}
4343
```
4444

0 commit comments

Comments
 (0)