Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ toc_landing_pages = [
"/aggregation",
"/aggregation/aggregation-tutorials",
"/security",
"/security/authentication",
"/aggregation-tutorials",
"/data-formats",
]
Expand Down
4 changes: 2 additions & 2 deletions source/includes/authentication/azure-envs-mongoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

# define callback, properties, and MongoClient
audience = "<audience>"
client_id = "<Azure client ID>"
client_id = "<Azure ID>"
class MyCallback(OIDCCallback):
def fetch(self, context: OIDCCallbackContext) -> OIDCCallbackResult:
credential = DefaultAzureCredential(managed_identity_client_id=client_id)
token = credential.get_token(f"{audience}/.default").token
return OIDCCallbackResult(access_token=token)
properties = {"OIDC_CALLBACK": MyCallback()}
client = MongoClient(
"mongodb://<hostname>:<port>",
"mongodb[+srv]://<hostname>:<port>",
authMechanism="MONGODB-OIDC",
authMechanismProperties=properties
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pymongo import MongoClient

# define URI and MongoClient
uri = ("mongodb://<hostname>:<port>/?"
"username=<Azure client ID or application ID>"
uri = ("mongodb[+srv]://<hostname>:<port>/?"
"username=<username>"
"&authMechanism=MONGODB-OIDC"
"&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:<percent-encoded audience>")
client = MongoClient(uri)
4 changes: 2 additions & 2 deletions source/includes/authentication/azure-imds-mongoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# define properties and MongoClient
properties = {"ENVIRONMENT": "azure", "TOKEN_RESOURCE": "<audience>"}
client = MongoClient(
"mongodb://<hostname>:<port>",
username="<Azure client ID or application ID>",
"mongodb[+srv]://<hostname>:<port>",
username="<Azure ID>",
authMechanism="MONGODB-OIDC",
authMechanismProperties=properties
)
2 changes: 1 addition & 1 deletion source/includes/authentication/gcp-gke-mongoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def fetch(self, context: OIDCCallbackContext) -> OIDCCallbackResult:
return OIDCCallbackResult(access_token=token)
properties = {"OIDC_CALLBACK": MyCallback()}
client = MongoClient(
"mongodb://<hostname>:<port>",
"mongodb[+srv]://<hostname>:<port>",
authMechanism="MONGODB-OIDC",
authMechanismProperties=properties
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pymongo import MongoClient

# define URI and MongoClient
uri = ("mongodb://<hostname>:<port>/?"
uri = ("mongodb[+srv]://<hostname>:<port>/?"
"&authMechanism=MONGODB-OIDC"
"&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:<percent-encoded audience>")
client = MongoClient(uri)
2 changes: 1 addition & 1 deletion source/includes/authentication/gcp-imds-mongoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# define properties and MongoClient
properties = {"ENVIRONMENT": "gcp", "TOKEN_RESOURCE": "<audience>"}
client = MongoClient(
"mongodb://<hostname>:<port>",
"mongodb[+srv]://<hostname>:<port>",
authMechanism="MONGODB-OIDC",
authMechanismProperties=properties
)
10 changes: 10 additions & 0 deletions source/includes/authentication/percent-encoding.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. important:: Percent-Encoding

You must :wikipedia:`percent-encode <Percent-encoding>` a username and password before
you include them in a MongoDB URI. The ``quote_plus()`` method, available in the
`urllib.parse <https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_plus>`__
module, is one way to perform this task. For example, calling ``quote_plus("and / or")``
returns the string ``and+%2F+or``.

Don't percent-encode the username or password when passing them as arguments to
``MongoClient``.
1 change: 0 additions & 1 deletion source/security.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Secure Your Data
:maxdepth: 1

Authentication </security/authentication>
Enterprise Authentication </security/enterprise-authentication>
In-Use Encryption </security/in-use-encryption>

Overview
Expand Down
Loading
Loading