@@ -369,6 +369,62 @@ see the corresponding syntax.
369
369
:start-after: start-oidc-azure-mongo-cred
370
370
:end-before: end-oidc-azure-mongo-cred
371
371
372
+ .. _kotlin-sync-auth-kubernetes:
373
+
374
+ Kubernetes
375
+ ~~~~~~~~~~
376
+
377
+ If your application runs on a Kubernetes cluster, you can authenticate
378
+ to MongoDB by using the {+driver-short+}'s built-in Kubernetes support.
379
+
380
+ Select from the :guilabel:`Connection String` or
381
+ :guilabel:`MongoCredential` tabs to see the corresponding syntax.
382
+
383
+ .. tabs::
384
+
385
+ .. tab:: Connection String
386
+ :tabid: mongodb-kubernetes-connection-string
387
+
388
+ To specify Kubernetes OIDC as the authentication mechanism, set the following
389
+ options in your connection string:
390
+
391
+ - ``authMechanism``: Set to ``MONGODB-OIDC``.
392
+ - ``authMechanismProperties``: Set to ``ENVIRONMENT:k8s``.
393
+
394
+ Replace the ``<percent-encoded audience>`` placeholder in the
395
+ following code with the percent-encoded value of the audience server
396
+ parameter configured on your MongoDB deployment.
397
+
398
+ .. code-block:: kotlin
399
+
400
+ val connectionString = ConnectionString(
401
+ "mongodb://<OIDC principal>@<hostname>:<port>/?" +
402
+ "authMechanism=MONGODB-OIDC" +
403
+ "&authMechanismProperties=ENVIRONMENT:k8s,TOKEN_RESOURCE:<percent-encoded audience>")
404
+ val mongoClient = MongoClient.create(connectionString)
405
+
406
+ .. tab:: MongoCredential
407
+ :tabid: mongodb-kubernetes-mongo-credential
408
+
409
+ Replace the ``hostname`` and ``port`` with the network address and port
410
+ number of your MongoDB deployment. Also, replace the
411
+ ``<audience>`` placeholder with the value of the ``audience``
412
+ server parameter configured on your MongoDB deployment.
413
+
414
+ .. code-block:: kotlin
415
+
416
+ val credential = MongoCredential.createOidcCredential("<OIDC principal>")
417
+ .withMechanismProperty("ENVIRONMENT", "k8s")
418
+ .withMechanismProperty("TOKEN_RESOURCE", "<audience>")
419
+
420
+ val mongoClient = MongoClient.create(
421
+ MongoClientSettings.builder()
422
+ .applyToClusterSettings { builder ->
423
+ builder.hosts(listOf(ServerAddress("<hostname>", <port>)))
424
+ }
425
+ .credential(credential)
426
+ .build())
427
+
372
428
.. _kotlin-mongodb-oidc-gcp-imds:
373
429
374
430
GCP IMDS
0 commit comments