Database Manual / Self-Managed Deployments / Security / Authentication / OIDC/OAuth 2.0 / Workload (Applications)

Configure an External Identity Provider for Workload Authentication为工作负载身份验证配置外部身份提供程序

To configure Workload Identity Federation using OAuth 2.0, register your OAuth 2.0 application with an external identity provider like Microsoft Azure or Google Cloud Platform (GCP). This enables secure authentication and streamlines user management.要使用OAuth 2.0配置工作负载身份联合,请向Microsoft Azure或Google Cloud Platform(GCP)等外部身份提供程序注册OAuth 2.0应用程序。这实现了安全身份验证并简化了用户管理。

About this Task关于此任务

Workload Identity Federation uses OAuth2.0 access tokens. These tokens can be issued by any external identity provider.工作负载身份联合使用OAuth2.0访问令牌。这些令牌可以由任何外部身份提供者颁发。

The following procedures configure Microsoft Azure Entra ID and Google Cloud Platform as external identity providers for MongoDB.以下过程将Microsoft Azure Entra ID和Google Cloud Platform配置为MongoDB的外部身份提供者。

Before you Begin开始之前

Steps步骤

Azure

In order to access self-managed MongoDB instances with Azure Managed Identities or Azure Service Principals, you need to register an Azure Entra ID application. 为了使用Azure托管标识或Azure服务主体访问自我管理的MongoDB实例,您需要注册Azure Entra ID应用程序。If you have an existing application registration for Workforce (human user) access, we recommended that you register a separate application for Workload access.如果您已有Workforce(人类用户)访问的应用程序注册,我们建议您为Workload访问注册一个单独的应用程序。

1

Register an application注册应用程序

  1. Navigate to App registrations.导航到“应用程序注册”。

    1. In your Azure portal account, search and click Microsoft Entra ID.Azure门户帐户中,搜索并单击Microsoft Entra ID。
    2. In the Manage section of the left navigation, click App registrations.在左侧导航的“管理”部分,单击“应用程序注册”。
  2. Click New registration.单击“新建注册”。
  3. Apply the following values.应用以下值。

    Field字段Value
    Name名称MongoDB - WorkloadMongoDB-工作负载
    Supported Account Types支持的帐户类型Accounts in this organizational directory only (single tenant)仅此组织目录中的帐户(单个租户)
    Redirect URI重定向 URIWeb
2

(Optional) Add groups claim(可选)添加组声明

For application access, it is a best practice to use service principal identifiers as MongoDB user identifiers while defining access rights in self-managed MongoDB deployments. If you plan to use this common approach, skip this step. 对于应用程序访问,在自我管理的MongoDB部署中定义访问权限时,最好将服务主体标识符用作MongoDB用户标识符。如果您打算使用这种常见方法,请跳过此步骤。However, if you prefer to use group identifiers such as Azure AD Security Group identifier instead, you can set groups claim in your application registration with below steps.但是,如果您更喜欢使用组标识符,如Azure AD安全组标识符,则可以通过以下步骤在应用程序注册中设置组声明。

  1. Navigate to Token Configuration.导航到“令牌配置”。

    In the Manage section of the left navigation, click Token Configuration.在左侧导航的管理部分,单击“令牌配置”。

  2. Click Add groups claim.单击“添加组索赔”。
  3. In the Edit groups claim modal, select Security.在“编辑组声明”模式中,选择“安全”。

    What groups you select depend on the type of groups you configured in your Azure environment. You may need to select a different type of group to send the appropriate group information.您选择的组取决于您在Azure环境中配置的组类型。您可能需要选择其他类型的组来发送相应的组信息。

  4. In the Customize token properties by type section, ensure that you only select Group ID.在“按类型自定义令牌属性”部分,确保仅选择“组ID”。

    When you select Group ID, Azure sends the security group's Object ID.当您选择“组ID”时,Azure会发送安全组的对象ID。

  5. Click Add.单击“添加”。

    To learn more about adding a group claim, see Azure Documentation.要了解有关添加组声明的更多信息,请参阅Azure文档

3

Enable an Application ID URI启用应用程序ID URI

  1. Navigate to Expose an API in the left sidebar and enable Application ID URI.导航到左侧栏中的Exposeanneneneba API并启用应用程序IDURI。
  2. Enable an Application ID URI.启用应用程序ID URI。

    Keep the default Application ID URI assigned by Azure, which is <application_client_id>.保留Azure分配的默认应用程序ID URI,即<application_client_id> Copy and store this value, as self-managed MongoDB deployments and all MongoDB drivers require this value for Workload Identity Federation configuration.复制并存储此值,因为自我管理的MongoDB部署和所有MongoDB驱动程序都需要此值用于工作负载身份联合配置。

4

Update the manifest更新清单

  1. In the Manage section of the left navigation, click Manifest.在左侧导航的“管理”部分,单击“清单”。
  2. Update the requestedAccessTokenVersion from null to 2.requestedAccessTokenVersionnull更新为2

    The number 2 represents Version 2 of Microsoft's access tokens. Other applications can use this as proof of the Active Directory-managed user's identity. Version 2 ensures that the token is a JSON Web Token that MongoDB understands.数字2代表微软访问令牌的版本2。其他应用程序可以将此作为活动目录管理用户身份的证明。版本2确保令牌是MongoDB理解的JSON Web令牌。

  3. Click Save.单击“保存”。

To learn more about adding an optional claim, see Azure Documentation.要了解有关添加可选声明的更多信息,请参阅Azure文档

5

Remember metadata

  1. In the left navigation, click Overview.在左侧导航中,单击“概述”。
  2. In the top navigation, click Endpoints.在顶部导航中,单击“端点”。

    Copy the OpenID Connect metadata document value, excluding /.well-known/openid-configuration.复制“OpenID Connect元数据文档”值,不包括/.well-known/openid-configuration

    You can also retrieve this value by following the OpenID Connect metadata document URL and copying the value for issuer.您还可以通过遵循“OpenID Connect元数据文档URL”并复制“颁发者”的值来检索此值。

The following table shows what these Microsoft Entra ID UI values map to in the MongoDB oidcIdentityProviders parameter:下表显示了这些Microsoft Entra ID UI值在MongoDB oidcIdentityProviders参数中的映射:

Microsoft Entra ID UIMongoDB oidcIdentityProviders Parameter Field
OpenID Connect metadata document OpenID连接元数据文档(without /.well-known/openid-configuration)issuer
Application ID URI应用程序ID URIaudience
GCP

You don't need to make any configuration changes in your Google Cloud service account.您不需要在Google Cloud服务帐户中进行任何配置更改。