File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
includes/fundamentals/code-snippets Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,27 @@ The following code example shows how to set these options when creating a
192192 :end-before: end-gcp-imds
193193 :emphasize-lines: 2-4
194194
195+ Kubernetes
196+ ~~~~~~~~~~
197+
198+ If your application runs on a Kubernetes cluster, you can authenticate to MongoDB by using
199+ the {+driver-short+}'s built-in Kubernetes support.
200+
201+ You can configure OIDC for Kubernetes by setting the ``mechanism`` field of your
202+ ``Credential`` struct to ``AuthMechanism::MongoDbOidc``. Then, specify the
203+ authentication mechanism by setting the ``ENVIRONMENT`` property to ``k8s`` in the
204+ ``mechanism_properties`` field.
205+
206+ The following code example shows how to set these options when creating a
207+ ``Client``:
208+
209+ .. literalinclude:: /includes/fundamentals/code-snippets/enterprise-auth.rs
210+ :language: rust
211+ :dedent:
212+ :start-after: start-kubernetes
213+ :end-before: end-kubernetes
214+ :emphasize-lines: 2-4
215+
195216.. _rust-mongodb-oidc-custom-callback:
196217
197218Custom Callback
Original file line number Diff line number Diff line change @@ -60,6 +60,23 @@ async fn main() -> mongodb::error::Result<()> {
6060 . await ?;
6161 // end-gcp-imds
6262
63+ // start-kubernetes
64+ let credential = Credential :: builder ( )
65+ . mechanism ( AuthMechanism :: MongoDbOidc )
66+ . mechanism_properties (
67+ doc ! { "ENVIRONMENT" : "k8s" }
68+ )
69+ . build ( ) ;
70+
71+ client_options. credential = Some ( credential) ;
72+ let client = Client :: with_options ( client_options) ?;
73+ let res = client
74+ . database ( "test" )
75+ . collection :: < Document > ( "test" )
76+ . find_one ( doc ! { } )
77+ . await ?;
78+ // end-kubernetes
79+
6380 // start-custom-callback-machine
6481 let credential = Credential :: builder ( )
6582 . mechanism ( AuthMechanism :: MongoDbOidc )
You can’t perform that action at this time.
0 commit comments