Skip to content

DOCSP-47923: kubernetes oidc #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions source/security/enterprise-authentication.txt
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,55 @@ see the corresponding syntax.
:end-before: // end-gcp-oidc-mongocredential
:language: java

.. _java-rs-auth-kubernetes:

Kubernetes
++++++++++

If your application runs on a Kubernetes cluster, you can authenticate
to MongoDB by using the {+driver-short+}'s built-in Kubernetes support.

Select from the :guilabel:`Connection String` or
:guilabel:`MongoCredential` tabs to see the corresponding syntax.

.. tabs::

.. tab:: Connection String
:tabid: mongodb-kubernetes-connection-string

To specify Kubernetes OIDC as the authentication mechanism, set the following
options in your connection string:

- ``authMechanism``: Set to ``MONGODB-OIDC``.
- ``authMechanismProperties``: Set to ``ENVIRONMENT:k8s``.

.. code-block:: java
:emphasize-lines: 4

MongoClient mongoClient = MongoClients.create(
"mongodb://<hostname>:<port>/" +
"?authMechanism=MONGODB-OIDC" +
"&authMechanismProperties=ENVIRONMENT:k8s");

.. tab:: MongoCredential
:tabid: mongodb-kubernetes-mongo-credential

Replace the ``hostname`` and ``port`` with the network address and port
number of your MongoDB deployment.

.. code-block:: java
:emphasize-lines: 2

MongoCredential credential = MongoCredential.createOidcCredential(null)
.withMechanismProperty("ENVIRONMENT", "k8s");

MongoClient mongoClient = MongoClients.create(
MongoClientSettings.builder()
.applyToClusterSettings(builder ->
builder.hosts(Arrays.asList(new ServerAddress("<hostname>", <port>))))
.credential(credential)
.build());

Custom Callback
+++++++++++++++

Expand Down
5 changes: 5 additions & 0 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ and features:
:ref:`java-rs-client-bulk-write-replace` sections of the Bulk
Write Operations guide

.. replacement:: k8s-link

the :ref:`MONGODB-OIDC: Kubernetes <java-rs-auth-kubernetes>`
section of the Enterprise Authentication Mechanisms guide

.. _javars-version-5.3:

What's New in 5.3
Expand Down
Loading