Skip to content

Commit 2530f4c

Browse files
DOCSP-46651 - Authentication reorganization (#148) (#151)
(cherry picked from commit ec77be0) Co-authored-by: Mike Woofter <[email protected]>
1 parent 8479f59 commit 2530f4c

17 files changed

+1265
-1001
lines changed

snooty.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ toc_landing_pages = [
1010
"/aggregation",
1111
"/aggregation/aggregation-tutorials",
1212
"/security",
13+
"/security/authentication",
1314
"/aggregation-tutorials",
1415
"/data-formats",
1516
]

source/includes/authentication/azure-envs-mongoclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
# define callback, properties, and MongoClient
66
audience = "<audience>"
7-
client_id = "<Azure client ID>"
7+
client_id = "<Azure ID>"
88
class MyCallback(OIDCCallback):
99
def fetch(self, context: OIDCCallbackContext) -> OIDCCallbackResult:
1010
credential = DefaultAzureCredential(managed_identity_client_id=client_id)
1111
token = credential.get_token(f"{audience}/.default").token
1212
return OIDCCallbackResult(access_token=token)
1313
properties = {"OIDC_CALLBACK": MyCallback()}
1414
client = MongoClient(
15-
"mongodb://<hostname>:<port>",
15+
"mongodb[+srv]://<hostname>:<port>",
1616
authMechanism="MONGODB-OIDC",
1717
authMechanismProperties=properties
1818
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from pymongo import MongoClient
22

33
# define URI and MongoClient
4-
uri = ("mongodb://<hostname>:<port>/?"
5-
"username=<Azure client ID or application ID>"
4+
uri = ("mongodb[+srv]://<hostname>:<port>/?"
5+
"username=<username>"
66
"&authMechanism=MONGODB-OIDC"
77
"&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:<percent-encoded audience>")
88
client = MongoClient(uri)

source/includes/authentication/azure-imds-mongoclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# define properties and MongoClient
44
properties = {"ENVIRONMENT": "azure", "TOKEN_RESOURCE": "<audience>"}
55
client = MongoClient(
6-
"mongodb://<hostname>:<port>",
7-
username="<Azure client ID or application ID>",
6+
"mongodb[+srv]://<hostname>:<port>",
7+
username="<Azure ID>",
88
authMechanism="MONGODB-OIDC",
99
authMechanismProperties=properties
1010
)

source/includes/authentication/gcp-gke-mongoclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def fetch(self, context: OIDCCallbackContext) -> OIDCCallbackResult:
99
return OIDCCallbackResult(access_token=token)
1010
properties = {"OIDC_CALLBACK": MyCallback()}
1111
client = MongoClient(
12-
"mongodb://<hostname>:<port>",
12+
"mongodb[+srv]://<hostname>:<port>",
1313
authMechanism="MONGODB-OIDC",
1414
authMechanismProperties=properties
1515
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pymongo import MongoClient
22

33
# define URI and MongoClient
4-
uri = ("mongodb://<hostname>:<port>/?"
4+
uri = ("mongodb[+srv]://<hostname>:<port>/?"
55
"&authMechanism=MONGODB-OIDC"
66
"&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:<percent-encoded audience>")
77
client = MongoClient(uri)

source/includes/authentication/gcp-imds-mongoclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# define properties and MongoClient
44
properties = {"ENVIRONMENT": "gcp", "TOKEN_RESOURCE": "<audience>"}
55
client = MongoClient(
6-
"mongodb://<hostname>:<port>",
6+
"mongodb[+srv]://<hostname>:<port>",
77
authMechanism="MONGODB-OIDC",
88
authMechanismProperties=properties
99
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. important:: Percent-Encoding
2+
3+
You must :wikipedia:`percent-encode <Percent-encoding>` a username and password before
4+
you include them in a MongoDB URI. The ``quote_plus()`` method, available in the
5+
`urllib.parse <https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_plus>`__
6+
module, is one way to perform this task. For example, calling ``quote_plus("and / or")``
7+
returns the string ``and+%2F+or``.
8+
9+
Don't percent-encode the username or password when passing them as arguments to
10+
``MongoClient``.

source/security.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Secure Your Data
2323
:maxdepth: 1
2424

2525
Authentication </security/authentication>
26-
Enterprise Authentication </security/enterprise-authentication>
2726
In-Use Encryption </security/in-use-encryption>
2827

2928
Overview

0 commit comments

Comments
 (0)