File tree Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change
1
+ from pymongo import MongoClient
2
+
3
+ # start-kubernetes-connection-string
4
+ uri = ("mongodb[+srv]://<hostname>:<port>/?"
5
+ "authMechanism=MONGODB-OIDC"
6
+ "&authMechanismProperties=ENVIRONMENT:k8s" )
7
+ client = MongoClient (uri )
8
+ # end-kubernetes-connection-string
Original file line number Diff line number Diff line change
1
+ from pymongo import MongoClient
2
+
3
+ # start-kubernetes-mongoclient
4
+ properties = {"ENVIRONMENT" : "k8s" }
5
+ client = MongoClient (
6
+ "mongodb[+srv]://<hostname>:<port>" ,
7
+ authMechanism = "MONGODB-OIDC" ,
8
+ authMechanismProperties = properties
9
+ )
10
+ # end-kubernetes-mongoclient
Original file line number Diff line number Diff line change @@ -293,4 +293,36 @@ constructor:
293
293
.. literalinclude:: /includes/authentication/gcp-gke-mongoclient.py
294
294
:language: python
295
295
:copyable: true
296
- :emphasize-lines: 11-15
296
+ :emphasize-lines: 11-15
297
+
298
+ .. _pymongo-mongodb-oidc-kubernetes:
299
+
300
+ Kubernetes
301
+ ~~~~~~~~~~
302
+
303
+ If your application runs on a Kubernetes cluster, you can authenticate to MongoDB by using
304
+ {+driver-short+}'s built-in Kubernetes support.
305
+
306
+ You can configure OIDC for Kubernetes in two ways: by passing arguments to the
307
+ ``MongoClient`` constructor or through parameters in your connection string. Select from
308
+ the following tabs to see how to enable Kubernetes authentication for your application:
309
+
310
+ .. tabs::
311
+
312
+ .. tab:: MongoClient
313
+ :tabid: mongoclient
314
+
315
+ .. literalinclude:: /includes/authentication/kubernetes-mongoclient.py
316
+ :language: python
317
+ :copyable: true
318
+ :start-after: start-kubernetes-mongoclient
319
+ :end-before: end-kubernetes-mongoclient
320
+
321
+ .. tab:: Connection String
322
+ :tabid: connectionstring
323
+
324
+ .. literalinclude:: /includes/authentication/kubernetes-connection-string.py
325
+ :language: python
326
+ :copyable: true
327
+ :start-after: start-kubernetes-connection-string
328
+ :end-before: end-kubernetes-connection-string
You can’t perform that action at this time.
0 commit comments