Skip to content

Commit 772ce53

Browse files
committed
DOCSP-47923: kubernetes oidc
1 parent eaddf51 commit 772ce53

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

source/security/enterprise-auth.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,62 @@ see the corresponding syntax.
369369
:start-after: start-oidc-azure-mongo-cred
370370
:end-before: end-oidc-azure-mongo-cred
371371

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+
372428
.. _kotlin-mongodb-oidc-gcp-imds:
373429

374430
GCP IMDS

source/whats-new.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ and features:
3737
:ref:`kotlin-sync-client-bulk-write-replace` sections of the Bulk Write
3838
Operations guide
3939

40+
.. replacement:: k8s-link
41+
42+
the :ref:`MONGODB-OIDC: Kubernetes <kotlin-sync-auth-kubernetes>`
43+
section of the Enterprise Authentication Mechanisms guide
44+
4045
.. _kotlin-sync-version-5.3:
4146

4247
What's New in 5.3

0 commit comments

Comments
 (0)