Skip to content

Commit 03396f7

Browse files
authored
DOCSP-47923: kubernetes oidc (#86)
* DOCSP-47923: kubernetes oidc * ordering * includes
1 parent eaddf51 commit 03396f7

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

source/includes/security/enterprise-auth.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ val mongoClient = MongoClient.create(
121121
.build())
122122
// end-oidc-gcp-mongo-cred
123123

124+
// start-oidc-k8s-connect-str
125+
val connectionString = ConnectionString(
126+
"mongodb://<OIDC principal>@<hostname>:<port>/?" +
127+
"authMechanism=MONGODB-OIDC" +
128+
"&authMechanismProperties=ENVIRONMENT:k8s,TOKEN_RESOURCE:<percent-encoded audience>")
129+
val mongoClient = MongoClient.create(connectionString)
130+
// end-oidc-k8s-connect-str
131+
132+
// start-oidc-k8s-mongo-cred
133+
val credential = MongoCredential.createOidcCredential("<OIDC principal>")
134+
.withMechanismProperty("ENVIRONMENT", "k8s")
135+
.withMechanismProperty("TOKEN_RESOURCE", "<audience>")
136+
137+
val mongoClient = MongoClient.create(
138+
MongoClientSettings.builder()
139+
.applyToClusterSettings { builder ->
140+
builder.hosts(listOf(ServerAddress("<hostname>", <port>)))
141+
}
142+
.credential(credential)
143+
.build())
144+
// end-oidc-k8s-mongo-cred
145+
124146
// start-oidc-custom-callback
125147
val credential = MongoCredential.createOidcCredential(null)
126148
.withMechanismProperty("OIDC_CALLBACK") { context: Context ->

source/security/enterprise-auth.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,52 @@ see the corresponding syntax.
419419
:start-after: start-oidc-gcp-mongo-cred
420420
:end-before: end-oidc-gcp-mongo-cred
421421

422+
.. _kotlin-sync-auth-kubernetes:
423+
424+
Kubernetes
425+
~~~~~~~~~~
426+
427+
If your application runs on a Kubernetes cluster, you can authenticate
428+
to MongoDB by using the {+driver-short+}'s built-in Kubernetes support.
429+
430+
Select from the :guilabel:`Connection String` or
431+
:guilabel:`MongoCredential` tabs to see the corresponding syntax.
432+
433+
.. tabs::
434+
435+
.. tab:: Connection String
436+
:tabid: mongodb-kubernetes-connection-string
437+
438+
To specify Kubernetes OIDC as the authentication mechanism, set the following
439+
options in your connection string:
440+
441+
- ``authMechanism``: Set to ``MONGODB-OIDC``.
442+
- ``authMechanismProperties``: Set to ``ENVIRONMENT:k8s``.
443+
444+
Replace the ``<percent-encoded audience>`` placeholder in the
445+
following code with the percent-encoded value of the audience server
446+
parameter configured on your MongoDB deployment.
447+
448+
.. literalinclude:: /includes/security/enterprise-auth.kt
449+
:language: kotlin
450+
:dedent:
451+
:start-after: start-oidc-k8s-connect-str
452+
:end-before: end-oidc-k8s-connect-str
453+
454+
.. tab:: MongoCredential
455+
:tabid: mongodb-kubernetes-mongo-credential
456+
457+
Replace the ``hostname`` and ``port`` with the network address and port
458+
number of your MongoDB deployment. Also, replace the
459+
``<audience>`` placeholder with the value of the ``audience``
460+
server parameter configured on your MongoDB deployment.
461+
462+
.. literalinclude:: /includes/security/enterprise-auth.kt
463+
:language: kotlin
464+
:dedent:
465+
:start-after: start-oidc-k8s-mongo-cred
466+
:end-before: end-oidc-k8s-mongo-cred
467+
422468
Custom Callback
423469
~~~~~~~~~~~~~~~
424470

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)