Skip to content

Commit 9f17578

Browse files
committed
rebase and add
1 parent a5e8390 commit 9f17578

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

source/security/auth/oidc.txt

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ see the corresponding syntax:
7777

7878
.. tab:: Connection String
7979
:tabid: mongodb-azure-imds-connection-string
80+
81+
To specify Azure IMDS OIDC as the authentication mechanism, set the following
82+
options in your connection string:
83+
84+
- ``authMechanism``: Set to ``MONGODB-OIDC``.
85+
- ``authMechanismProperties``: Set to ``ENVIRONMENT:azure``.
8086

8187
Replace the ``<percent-encoded audience>`` placeholder in the
8288
following code with the percent-encoded value of the audience server
@@ -134,6 +140,12 @@ see the corresponding syntax:
134140

135141
.. tab:: Connection String
136142
:tabid: mongodb-gcp-imds-connection-string
143+
144+
To specify GCP IMDS OIDC as the authentication mechanism, set the following
145+
options in your connection string:
146+
147+
- ``authMechanism``: Set to ``MONGODB-OIDC``.
148+
- ``authMechanismProperties``: Set to ``ENVIRONMENT:gcp``.
137149

138150
Replace the ``<percent-encoded audience>`` placeholder in the
139151
following code with the percent-encoded value of the audience server
@@ -160,7 +172,7 @@ see the corresponding syntax:
160172

161173
.. code-block:: java
162174

163-
MongoCredential credential = MongoCredential.createOidcCredential()
175+
MongoCredential credential = MongoCredential.createOidcCredential(null)
164176
.withMechanismProperty("ENVIRONMENT", "gcp")
165177
.withMechanismProperty("TOKEN_RESOURCE", "<audience>");
166178

@@ -171,6 +183,52 @@ see the corresponding syntax:
171183
.credential(credential)
172184
.build());
173185

186+
Kubernetes
187+
~~~~~~~~~~
188+
189+
If your application runs on a Kubernetes cluster, you can authenticate to MongoDB by using
190+
191+
the {+driver-short+}'s built-in Kubernetes support.
192+
193+
Select from the :guilabel:`Connection String` or :guilabel:`MongoCredential` tabs to
194+
see the corresponding syntax.
195+
196+
.. tabs::
197+
198+
.. tab:: Connection String
199+
:tabid: mongodb-kubernetes-connection-string
200+
201+
To specify Kubernetes OIDC as the authentication mechanism, set the following
202+
options in your connection string:
203+
204+
- ``authMechanism``: Set to ``MONGODB-OIDC``.
205+
- ``authMechanismProperties``: Set to ``ENVIRONMENT:k8s``.
206+
207+
.. code-block:: java
208+
209+
MongoClient mongoClient = MongoClients.create(
210+
"mongodb://<hostname>:<port>/" +
211+
"?authMechanism=MONGODB-OIDC" +
212+
"&authMechanismProperties=ENVIRONMENT:k8s");
213+
214+
.. tab:: MongoCredential
215+
:tabid: mongodb-kubernetes-mongo-credential
216+
217+
Replace the ``hostname`` and ``port`` with the network address and port
218+
number of your MongoDB deployment.
219+
220+
.. code-block:: java
221+
222+
MongoCredential credential = MongoCredential.createOidcCredential(null)
223+
.withMechanismProperty("ENVIRONMENT", "k8s");
224+
225+
MongoClient mongoClient = MongoClients.create(
226+
MongoClientSettings.builder()
227+
.applyToClusterSettings(builder ->
228+
builder.hosts(Arrays.asList(new ServerAddress("<hostname>", <port>))))
229+
.credential(credential)
230+
.build());
231+
174232
Custom Callback
175233
~~~~~~~~~~~~~~~
176234

0 commit comments

Comments
 (0)