@@ -478,6 +478,71 @@ callback function that you defined:
478
478
:end-before: end-credential-callback
479
479
:emphasize-lines: 6
480
480
481
+ Kubernetes
482
+ ~~~~~~~~~~
483
+
484
+ If your application runs on a Kubernetes cluster, you can authenticate to MongoDB
485
+ by using the {+driver-short+}'s built-in Kubernetes support.
486
+
487
+ You can configure OIDC for Kubernetes in the following ways:
488
+
489
+ - By creating a ``Credential`` struct and passing it to the
490
+ ``SetAuth()`` method when creating a client
491
+ - By setting parameters in your connection string
492
+
493
+ .. include:: /includes/authentication/auth-properties-commas.rst
494
+
495
+ .. tabs::
496
+
497
+ .. tab:: Credential
498
+ :tabid: credential struct
499
+
500
+ First, create a map to store your authentication
501
+ mechanism properties, as shown in the following example.
502
+
503
+ .. code-block:: go
504
+
505
+ props := map[string]string{
506
+ "ENVIRONMENT": "k8s",
507
+ }
508
+
509
+ Then, set the following ``Credential`` struct fields:
510
+
511
+ - ``AuthMechanism``: Set to ``"MONGODB-OIDC"``.
512
+ - ``AuthMechanismProperties``: Set to the ``props`` map that you
513
+ previously created.
514
+
515
+ The following code example shows how to set these options when creating a
516
+ ``Client``:
517
+
518
+ .. literalinclude:: /includes/authentication/kubernetes.go
519
+ :language: go
520
+ :dedent:
521
+ :copyable: true
522
+ :start-after: start-kubernetes
523
+ :end-before: end-kubernetes
524
+
525
+ .. tab:: Connection String
526
+ :tabid: connectionstring
527
+
528
+ Include the following connection options in your connection string:
529
+
530
+ - ``authMechanism``: Set to ``MONGODB-OIDC``.
531
+ - ``authMechanismProperties``: Set to``ENVIRONMENT:k8s``.
532
+
533
+ The following code example shows how to set these options in your connection string:
534
+
535
+ .. code-block:: go
536
+
537
+ uri := "mongodb://<hostname>:<port>/?" +
538
+ "&authMechanism=MONGODB-OIDC" +
539
+ "&authMechanismProperties=ENVIRONMENT:k8s"
540
+
541
+ client, err := mongo.Connect(options.Client().ApplyURI(uri))
542
+ if err != nil {
543
+ panic(err)
544
+ }
545
+
481
546
Additional Information
482
547
----------------------
483
548
0 commit comments