要使用 OIDC 配置 Workforce Identity Federation,请向外部身份提供商(例如 Okta 或Microsoft Entra ID)注册您的 OIDC应用程序。这可确保安全身份验证并简化用户管理。
关于此任务
Workforce Identity Federation 使用 OIDC。 您可以使用任何支持 OIDC 标准的外部身份提供商。
您可以为以下授权类型配置 OIDC应用程序:
使用PKCE的授权代码流
设备授权流程
MongoDB建议您将授权代码流与 PKCE 结合使用以提高安全性。 仅当用户需要从没有浏览器的计算机上访问权限数据库时,才使用设备授权流程。
注意
Workforce Identity Federation 仅支持使用JSON web token进行身份验证。它不支持不透明访问权限令牌。
以下过程提供了Microsoft Entra ID和 Okta 的详细配置说明,以及其他外部身份提供程序的通用配置说明。
开始之前
要将 Okta 用作身份提供商,您必须拥有Okta 帐户。
要将Microsoft Entra ID用作身份提供商,您必须拥有Microsoft Azure帐户。
要使用 Microsoft AD FS 作为身份验证,您必须拥有一个已加入 Active Directory 域并具有公共信任 SSL 证书的 AD FS 服务器。
步骤
注册应用程序
导航至 App registrations。
在Azure门户帐户中,搜索并单击 Microsoft Entra ID。
在左侧导航栏的 Manage 部分,单击 App registrations。
单击 New registration(连接)。
应用以下值。
字段值Name
MongoDB - Workforce
Supported Account Types
Accounts in this organizational directory only (single tenant)
Redirect URI
- Public client/native (mobile & desktop)
- 要使用 MongoDB Compass 和 MongoDB Shell 访问集群,将 Redirect URI 设置为http://localhost:27097/redirect。单击 Register(连接)。
要了解有关注册应用程序的更多信息,请参阅 Azure 文档。
添加群组声明
导航至 Token Configuration。
在左侧导航栏的 Manage 部分,单击 Token Configuration。
单击 Add groups claim(连接)。
在 Edit groups claim 模式中,选择 Security。
所选择的群组取决于您在 Azure 环境中配置的群组类型。 您可能需要选择不同类型的群组 来发送相应的群组信息。
在Customize token properties by type部分中,仅选择Group ID 。
单击 Add(连接)。
要学习;了解有关添加群组声明的更多信息,请参阅Azure文档。
将用户标识符声明添加到访问权限令牌
单击 Add optional claim(连接)。
在 Add optional claim 模式中,选择 Access。
选择带有用户标识符的声明,您可以在 MongoDB 访问 日志(如电子邮件)中引用该标识符。
您可以使用UPN声明通过电子邮件解决来识别用户。
单击 Add(连接)。
在 Microsoft Graph Permissions(Microsoft Graph 权限)注释中,选中复选框,然后单击 Add(添加)。
要了解详情,请参阅 Azure 文档。
更新清单
在左侧导航栏的 Manage 部分,单击 Manifest。
将 requestedAccessTokenVersion 从
null更新为2。数字
2代表 Microsoft 访问令牌版本 2。其他应用程序可以将其用作 Active Directory 托管用户身份的签名证明。版本 2 确保令牌是 MongoDB 可理解的 JSON 网络令牌。单击 Save(连接)。
要学习;了解有关添加可选声明的更多信息,请参阅Azure文档。
记住元数据
在左侧导航栏中单击 Overview。
复制 Application (client) ID(应用程序(客户端)ID)值。
在顶部导航栏中,单击 Endpoints。
复制不带
/.well-known/openid-configuration部分的 OpenID Connect metadata document 值。您还可以通过复制 OpenID Connect metadata document URL中
issuer的值来获取此值。
下表显示了这些Microsoft Entra ID 用户界面值在MongoDBoidcIdentityProviders 参数中的映射:
Microsoft Entra ID UI | MongoDB oidcIdentityProviders 参数字段 |
|---|---|
Application (client) ID |
|
OpenID Connect metadata document (without /.well-known/openid-configuration) |
|
更新联合服务标识符。
In Server Manager, go to Tools → AD FS Management.
单击 Edit Federation Service Properties(连接)。
In the Federation Service identifier field, change the value from
https://<domain>/adfs/services/trusttohttps://<domain>/adfs.<domain>应替换为您的 AD FS 服务器所属的 Active Directory 域的名称。单击 OK(连接)。
在此步骤中更新的联合服务标识符是您在 MongoDB 中配置 OIDC 提供程序时使用的颁发者 URI。如果这些值不匹配,则由于令牌颁发者不匹配,身份验证将失败。
Add the groups and sub claims to the access token.
MongoDB reads the groups and sub claims from the access token. By default, AD FS includes sub only in the ID token and sends an idsub claim in the access token instead. To add both claims to the access token, create an issuance transform rule on your web API:
在 AD FS 管理中,打开应用程序组的属性。
In the Applications section, select your web API and click Edit.
On the Issuance Transform Rules tab, click Add Rule.
In the Claim rule template field, select Send LDAP Attributes as Claims and click Next.
In the Claim rule name field, enter a name for the rule.
在 Attribute store字段中,选择 Active Directory。
将以下 LDAP 属性映射到传出声明类型:
LDAP属性对外索赔类型Token-Groups - Unqualified Names
groupsUser-Principal-Name
sub单击 OK(连接)。
在 Okta 中创建应用程序。
在 Okta Admin仪表盘,使用左侧导航窗格GoApplications → Applications。
在 Applications 屏幕上,单击 Create App Integration。
在 Sign-in method 部分,选择 OIDC - OpenID Connect。
在 Application type 部分,选择 Native Application。
单击 Next(连接)。
要学习;了解详情,请参阅创建 OIDC应用集成。
配置您的 New Native App Integration。
创建应用集成后,系统会自动重定向到 New Native App Integration 屏幕。
在 App integration name字段中,输入应用程序的名称。
In the Grant type field, select the grant types.
启用以下授权类型:
Authorization Code, Device Authorization, or both
(可选) Refresh Token
启用刷新令牌可提供更佳的用户体验。如果不启用刷新令牌,用户在访问令牌过期后必须重新向身份提供商进行身份验证。
在 Sign-in redirect URIs 部分,输入URL。
输入以下URL:
http://localhost:27097/redirect。In the Assignments section, configure the Controlled access and Enable immediate access fields with the appropriate settings for your security policies.
单击 Save(连接)。
要学习;了解详情,请参阅创建 OIDC应用集成。
添加授权服务器。
在左侧导航窗格中,GoSecurity → API。 单击 Add Authorization Server。
在 Name字段中,输入服务器的名称。
Fill in the Audience field.
The Audience is the entity that OIDC intends the token for. While this can be any valid URI, generally, this is the client ID of your application you copied in the previous step.
(可选)在 Description字段中,输入服务器的描述。
单击 Save(连接)。
要学习;了解更多信息,请参阅创建授权服务器。
(Conditionally Required) Add a Groups claim.
如果您希望使用 Okta 群组进行用户授权,则需要执行此步骤。如果您计划使用用户 ID 进行授权,则可以跳过此步骤。
在授权服务器屏幕上,GoClaims标签页并单击 Add Claim。
Configure the Groups claim with the following configuration information:
字段值Name
输入声明的名称。
Include in token type
单击下拉菜单并选择 Access Token。
Value type
单击下拉菜单并选择 Groups。
Filter
点击下拉菜单,并选择 Matches regex 。在下拉菜单旁边,输入一个正则表达式,该表达式仅匹配用于 Atlas 授权的组。示例,如果 Atlas 授权组使用公共命名前缀,输入
^<mongodb-atlas-group-prefix>.*,其中<mongodb-atlas-group-prefix>是您选择的前缀。Disable claim
请勿检查。
Include in
选择 Any scope 。
单击 Create(连接)。
重要
避免使用 .* 作为过滤器值。.* 表达式匹配分配给用户的所有组,包括与 Atlas 授权无关的组。宽泛的过滤器会增加访问令牌的大小,并可能导致令牌超出 preAuthMaximumMessageSizeBytes 限制(默认值为 16 KiB)时身份验证失败。
为了减少令牌大小,为 Atlas 授权组创建专用的命名规范,并根据该规范使用过滤器。
If your deployment intentionally requires a large groups claim, you can increase the preAuthMaximumMessageSizeBytes parameter on your cluster. However, increasing this limit has resource and security implications and should not be used as a workaround for an unnecessarily broad claim.
要学习;了解更多信息,请参阅创建声明。
创建访问权限策略。
在授权服务器屏幕上,GoAccess Policies标签页并单击 Add Policy。
在 Name字段中,输入策略名称。
在 Description字段中,输入策略的说明。
在 Assign to字段中,选择 All clients。
单击 Create Policy(连接)。
要学习;了解更多信息,请参阅创建访问策略。
为访问权限策略创建规则。
在 Access Policies标签页下,单击 Add Rule。
在 Rule Name字段中,输入访问权限策略的名称。
对于 IF Grant Type is,请选择一种授权类型。
配置授权类型时,请根据客户端行为选择适当的选项:
如果客户端代表自身运行,请选择 Client Credentials。
如果客户端端代表用户,请选择以下选项:
Authorization Code
Device Authorization
根据组织的安全策略添加规则配置。
Okta 规则配置示例:
字段值AND user is
选择 Any user assigned to the app 。
AND Scopes requested
选择 Any scopes 。
THEN Use this inline hook
无(已禁用)
AND Access token lifetime is
1 Hours
AND Refresh token lifetime is
单击第二个下拉菜单并选择 Unlimited。
but will expire if not used every
输入 7 days。
单击 Create Rule(连接)。
要学习;了解详情,请参阅为每个访问策略创建规则。
创建群组。
在左侧导航窗格中,GoDirectory → Groups 并单击 Add Group。
在 Name字段中,将目录命名为
OIDC。(可选)在 Description字段中,输入规则的说明。
单击 Save(连接)。
要学习;了解更多信息,请参阅创建群组。
按照 Okta 文档手动将人员分配到群组。
为您的组织添加用户。
在左侧导航窗格中,GoDirectory → People 并单击 Add Person。
通过在相应字段中输入以下值来提供用户详细信息:
字段值User type
选择 User 。
First name
根据需要提供名称。
Last name
根据需要提供名称。
Username
输入电子邮件作为用户名。
Primary email
输入电子邮件。 电子邮件必须与 Username字段使用的电子邮件相同。
Secondary email
可选。
Groups
输入 OIDC。
Activation
选择 Activate Now 并选中 I will set password。
Password
输入密码。
User must change password on first login
选择 Optional
单击 Save(连接)。
要学习;了解更多信息,请参阅手动添加用户。
(可选)如果您希望MongoDB客户端刷新令牌以获得更好的用户体验,请允许刷新令牌
(可选)配置访问权限令牌生命周期(exp 声明)以与数据库连接会话时间保持一致
注册应用程序后,保存 issuer 、 clientId 和 audience 值以在下一阶段的配置中使用。