Skip to content

Commit 4c46ca0

Browse files
mongoKartnorareidy
andauthored
DOCSP-45890 - OIDC Kubernetes (#368)
Co-authored-by: Nora Reidy <[email protected]>
1 parent 0dc9837 commit 4c46ca0

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

source/fundamentals/authentication/oidc.txt

+41-5
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ using a ``MongoCredential`` object or as part of the connection string. Select t
7979
:guilabel:`Connection String` or :guilabel:`MongoCredential` tab to
8080
see the corresponding syntax.
8181

82-
.. include:: /includes/comma-auth-options.rst
83-
8482
.. tabs::
8583

8684
.. tab:: Connection String
@@ -127,8 +125,6 @@ using a ``MongoCredential`` object or as part of the connection string. Select t
127125
:guilabel:`Connection String` or :guilabel:`MongoCredential` tab to
128126
see the corresponding syntax.
129127

130-
.. include:: /includes/comma-auth-options.rst
131-
132128
.. tabs::
133129

134130
.. tab:: Connection String
@@ -159,11 +155,51 @@ see the corresponding syntax.
159155
.WithMechanismProperty("TOKEN_RESOURCE", "<audience>");
160156
var client = new MongoClient(mongoClientSettings);
161157

158+
Kubernetes
159+
~~~~~~~~~~
160+
161+
If your application runs on a Kubernetes cluster, you can authenticate to MongoDB by using
162+
the {+driver-short+}'s built-in Kubernetes support.
163+
164+
You can specify Kubernetes OIDC authentication on a ``MongoClientSettings`` object either by
165+
using a ``MongoCredential`` object or as part of the connection string. Select the
166+
:guilabel:`Connection String` or :guilabel:`MongoCredential` tab to
167+
see the corresponding syntax.
168+
169+
.. tabs::
170+
171+
.. tab:: Connection String
172+
:tabid: oidc-kubernetes-connection-string
173+
174+
The following code example shows how to specify Kubernetes OIDC authentication as
175+
part of the connection string:
176+
177+
.. code-block:: csharp
178+
179+
var connectionString = "mongodb://<hostname>[:<port>]/?authMechanism=MONGODB-OIDC" +
180+
"&authMechanismProperties=ENVIRONMENT:k8s";
181+
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
182+
var client = new MongoClient(mongoClientSettings);
183+
184+
.. tab:: MongoCredential
185+
:tabid: oidc-kubernetes-mongo-credential
186+
187+
The following code example shows how to specify Kubernetes OIDC authentication by using
188+
a ``MongoCredential`` object:
189+
190+
.. code-block:: csharp
191+
192+
var mongoClientSettings = MongoClientSettings.FromConnectionString(
193+
"mongodb://<hostname>[:<port>]");
194+
mongoClientSettings.Credential = MongoCredential
195+
.CreateOidcCredential("k8s")
196+
var client = new MongoClient(mongoClientSettings);
197+
162198
Custom Callback
163199
~~~~~~~~~~~~~~~
164200

165201
The {+driver-short+} doesn't offer built-in support for all platforms, including
166-
Azure Functions and Azure Kubernetes Service (AKS). Instead, you
202+
Azure Functions. Instead, you
167203
must define a custom callback to use OIDC to authenticate from these platforms.
168204

169205
First, define a class that implements the ``IOidcCallback`` interface. This interface
+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.. note::
22

3-
You cannot pass values containing the comma (``,``) character to the
4-
``authMechanismProperties`` connection string parameter.
5-
You must specify values that contain commas in a ``MongoCredential`` object,
6-
as demonstrated in the :guilabel:`MongoCredential` tab.
3+
If you pass a value containing the comma (``,``) character to the
4+
``authMechanismProperties`` connection string parameter, you must
5+
percent-encode the comma character as ``%2C``.

0 commit comments

Comments
 (0)