For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
See how MongoDB 9.0 delivers up to 2x higher throughput.
MongoDB Branding Shape
Register now >
Docs Menu

Set up Workload Identity Federation with OAuth 2.0

With Workload Identity Federation, your applications can access MongoDB Cloud Manager deployments using external programmatic identities such as Azure Service Principals, Azure Managed Identities, and Google Service Accounts.

Workload Identity Federation allows your applications access to MongoDB deployments with OAuth 2.0 access tokens. The access tokens can be issued by any external Identity Provider including Azure Entra ID and Google Cloud Platform (GCP). Cloud Manager stores the user identifiers and privileges, but not the secrets. A limited set of MongoDB drivers offers this authentication mechanism for your applications.

MongoDB Drivers support two types of authentication flow for Workload Identity Federation: Built-in Authentication and Callback Authentication.

You can use built-in authentication if you deploy your app on a compatible infrastructure with a compatible principal type. Your app can access Cloud Manager deployments without supplying a password or manually requesting a JWT from your cloud provider's metadata service. Instead, your driver uses the existing principal identifier to request a JSON Web Token (JWT) access token. The driver passes the token to the Cloud Manager deployment when your app connects.

For more implementation details, see your driver's documentation.

Built-in Authentication Supported Infrastructure and Principal Types

Cloud Provider
Infrastructure Type
Principal Type

GCP

Compute Engine

GCP Service Accounts

App Engine Standard Environment

App Engine Flexible Environment

Cloud Functions

Cloud Run

Google Kubernetes Engine

Cloud Build

Azure

Azure VM

Azure Managed Identities (User and System assigned)

You can use callback authentication with any service supporting OAuth 2.0 access tokens. Workload Identity Federation calls a callback method where you request the required JWT from your authorization server or cloud provider. You then pass the token to Cloud Manager with Workload Identity Federation when your app connects.

For more implementation details, review the documentation for your driver.

To configure Workload Identity Federation, you must have Project Owner access to Cloud Manager.

You must meet these prerequisites:

  • MongoDB 7.0 or later.

  • At least one other authentication mechanism with MongoDB Agent configured.

    Note

    The MongoDB Agent can't connect to your deployment through OIDC. You must enable another auth mechanism for the MongoDB Agent. If Cloud Manager doesn't manage Monitoring or Backup, you must manually configure them to use the alternative authentication mechanism.

To configure Workload Identity Federation, follow these steps:

Note

To reset Authentication and TLS settings for your project, first unmanage any MongoDB deployments that Cloud Manager manages in your project.

Note

Workload Identity Federation supports only JWT for authentication. It doesn't support opaque access tokens.

MongoDB does not explicitly create database users for OIDC. It maps OIDC users to MongoDB roles based on the configuration.

Complete the procedure for the authorization type that you selected when configuring OIDC authentication.

If you selected the User ID authorization type, create a new user to grant an individual user authorization:

1
  1. Select the organization that contains your project from the Organizations menu in the navigation bar.

  2. Select your project from the Projects menu in the navigation bar.

  3. Click Deployment in the sidebar.

  4. Click the Security tab.

  5. Click the MongoDB Users tab.

2
3

Note

Before you add users, ensure that you've created any roles that you want to assign to the users.

  1. Complete the user account fields:

    Field
    Description

    Identifier

    • In the first field, enter the $external database.

    • In the second field, enter a username using your OIDC IdP configuration name and the user principal claim from your configuration separated by a slash (/): {configuration_name}/{user_principal_claim}

    Roles

    Enter any available user-defined roles and built-in roles into this box. The combo box provides a list of existing roles when you click in it.

    Authentication Restrictions

    1. Click Add Entry.

    2. Add one or more IP addresses and/or CIDR blocks in either the Client Source or Server Address boxes. Separate multiple addresses or blocks with commas.

      • Client Source restricts which addresses this user can authenticate and use the given roles.

      • Server Address restricts the addresses this user can authenticate and has the given roles.

    3. Click Save.

    4. To add another entry, click Add Entry.

  2. Click Add User.

4
5

Otherwise, click Cancel and you can make additional changes.

If you selected the Group Membership authorization type, complete the following steps to create a custom role that grants authorization based on IdP user group membership:

1
  1. Select the organization that contains your project from the Organizations menu in the navigation bar.

  2. Select your project from the Projects menu in the navigation bar.

  3. Click Deployment in the sidebar.

  4. Click the Security tab.

  5. Click the MongoDB Roles tab.

2
3
  1. Enter the following fields:

    Field
    Necessity
    Description

    Identifier

    Required

    In the Database box, enter admin.

    In the Name box, enter your OIDC IdP configuration name and the group name from your external identity provider, separated by a slash (/): {configuration_name}/{group_name}

    Inherits From

    Optional

    A list of role name and database pairs. The format for these pairs are roleName@dbName.

    Authentication Restrictions

    Optional

    A list of IP addresses or CIDR notations that you want to restrict from your IdP.

    Privilege Actions by Resource

    Optional

    Actions permitted on the resource.

    To learn more, see Privilege Actions.

  2. Click Add Role.

Use these MongoDB drivers to connect an app to MongoDB with Workload Identity Federation authentication:

To manage your Workload Identity Federation configuration, you can perform these actions.

Note

Don't use this feature to rotate your signing keys. When you rotate your OIDC IdP signing keys, MongoDB fetches the JWKS automatically upon expiration of the existing access tokens.

If your private key is compromised, you can immediately revoke the JSON Web Key Sets cached in MongoDB nodes:

1
  1. If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. In the sidebar, click Security under the Database heading.

The Security page displays.

2

Click the Settings tab.

3
  1. Scroll to the OIDC Connection and Authorization (Required for OIDC) section.

  2. Click the REVOKE JWKS button.

    Note

    This button is idle if there is no IdP configured.

  3. In the Revoke JWKS tokens? dialog box, click Revoke.

To edit your Workload Identity Federation configuration:

1
  1. If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. In the sidebar, click Security under the Database heading.

The Security page displays.

2
  1. Scroll to the OIDC Connection and Authorization (Required for OIDC) section.

  2. For the configuration that you want to edit, click the EDIT button.

  3. Make changes to the configuration.

3
4
5
6

Otherwise, click Cancel and you can make additional changes.

To delete your Workload Identity Federation configuration:

1
  1. If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. In the sidebar, click Security under the Database heading.

The Security page displays.

2
  1. Scroll to the OIDC Connection and Authorization (Required for OIDC) section.

  2. For the configuration that you want to delete, click the REMOVE button.

  3. In the Removing OIDC IdP configuration? dialog box, click Remove.