在MongoDB 7.0 及更高版本中,劳动力身份联合允许您使用外部身份提供者 (IdP)(例如公司 IdP)对特定劳动力(例如员工、合作伙伴和承包商)进行身份验证和授权。
通过 Workforce Identity Federation,您可以:
通过现有的 IdP 管理员工对MongoDB部署的访问权限。
在 IdP 中实施密码复杂性、档案轮换和 MFA 等安全策略。
配置外部 IdP 并将其一次添加到 Workforce Identity Federation 后,您可以为多个Atlas组织启用Workforce Identity Provider。在给定组织中启用Workforce Identity Federation 后,您可以在该组织的所有项目中使用它来访问权限数据库。
运行MongoDB 7.0.11及更高版本的Atlas专用集群(M 10及更高版本)支持 Workforce Identity Federation。 您需要使用MongoDB Shell或Compass来访问权限具有 Workforce Identity Federation 的Atlas 。
要学习;了解有关实施 Workforce Identity Federation访问权限的更多信息,请参阅使用 Workforce Identity Federation 将客户端连接到MongoDB 。
必需的访问权限
要管理Workforce Identity Federation 配置,您必须拥有Atlas的Organization Owner访问权限。
步骤
要使用 Workforce Identity Federation访问权限Atlas集群,请完成以下步骤:
配置劳动力身份提供程序(一次性设置)。
授予外部身份(用户主体)或群组访问权限MongoDB集群的权限。
使用MongoDB Shell或Compass对Atlas集群进行身份验证。
配置外部身份提供商应用程序
要使用 OIDC 配置 Workforce Identity Federation,请向支持 OIDC 标准的 IdP(例如Microsoft Entra ID 、Okta 或 Ping Identity)注册您的 OIDC应用程序。
有关配置特定身份提供程序的分步说明,请参阅:
注意
Workforce Identity Federation 仅支持使用 JSON web token 进行身份验证。 它不支持不透明访问令牌。
您可以为以下授权类型配置 OIDC应用程序:
使用 PKCE 的授权代码流
设备授权流程
MongoDB建议您将授权代码流与 PKCE 结合使用以提高安全性。仅当用户需要从没有浏览器的计算机上访问权限数据库时,才使用设备授权流程。
注意
如果您的身份提供商是Microsoft Entra ID并且您使用设备授权流程,则必须在Azure应用注册中启用Allow public client flows。要学习;了解如何启用此设置,请参阅Azure文档。
OIDC应用程序注册步骤可能因 IdP 而异。确保在注册进程中完成以下事项:
(可选)如果希望 MongoDB 客户端刷新令牌以获得更好的用户体验, 则允许刷新令牌。
(可选)配置访问令牌生命周期( exp声明)以与数据库连接会话时间保持一致。
注册应用程序后,保存 issuer、clientId 和 audience 值,以在Atlas Workforce IdP 配置的下一阶段使用。
要使用Microsoft Entra ID注册您的 OIDC应用程序:
注册应用程序。
导航至 App registrations。
在Azure门户帐户中,搜索并单击 Microsoft Entra ID。
在左侧导航栏的 Manage 部分,单击 App registrations。
单击 New registration(连接)。
应用以下值。
字段值Name
Atlas Database - Workforce
Supported Account Types
Accounts in this organizational directory only (single tenant)
Redirect URI
- Public client/native (mobile & desktop)
-http://localhost:27097/redirect单击 Register(连接)。
记住元数据。
在左侧导航栏中单击 Overview。
复制 Application (client) ID(应用程序(客户端)ID)值。
在顶部导航栏中,单击 Endpoints。
复制不带
/.well-known/openid-configuration部分的 OpenID Connect metadata document 值。您还可以通过复制 OpenID Connect metadata document URL中
issuer的值来获取此值。
下表显示这些 Microsoft Entra ID 用户界面值在我们的 Atlas 配置属性中映射的内容:
Microsoft Entra ID UI | Atlas 配置属性 |
|---|---|
Application (client) ID | Client ID |
OpenID Connect metadata document (without /.well-known/openid-configuration) | Issuer URI |
要将 OIDC应用程序注册到 Okta,请执行以下操作:
在 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字段中,输入应用程序的名称。
在 Grant type字段中,选择授权类型。
启用以下授权类型:
Authorization Code or Device Authorization
(可选) Refresh Token
启用刷新令牌可提供更好的用户体验。 如果未启用刷新令牌,则一旦访问权限令牌过期,用户就必须向身份提供商重新进行身份验证。
在 Sign-in redirect URIs 部分,输入URL。
输入以下URL:
http://localhost:27097/redirect。在 Assignments 部分中,配置 Controlled access 和 Enable immediate access 字段。
对于 Controlled access字段,选择 Allow everyone in your organization to access。
对于 Enable immediate access字段,确保选中 Enable immediate access with Federation Broker Mode。
单击 Save(连接)。
要学习;了解详情,请参阅创建 OIDC应用集成。
添加 Groups 声明。
在授权服务器屏幕上,GoClaims标签页并单击 Add Claim。
使用以下配置信息配置 Groups 声明:
字段值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 授权组创建专用的命名规范,并根据该规范使用过滤器。
如果您的部署有意要求大型群组声明,则可以增加集群上的 preAuthMaximumMessageSizeBytes 参数。但是,增加此限制会对资源和安全产生影响,并且不应用于不必要的广泛声明的变通方法。
为访问权限策略创建规则。
在 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(连接)。
配置 Workforce Identity Federation 身份验证
要在Atlas中配置劳动力身份提供程序,请执行以下操作:
输入以下劳动力身份提供商协议设置。
设置 | 必要性 | 值 |
|---|---|---|
Configuration Name | 必需 | 标识此配置的人类可读标签。 此标签对Atlas用户可见。 |
Configuration Description | Optional | 描述此配置的人类可读标签。 |
Issuer URI | 必需 | 已注册的 IdP应用程序提供的发行者值。 MongoDB使用此 URI 查找 OpenID 提供程序配置文档,该文档应在 |
Client ID | 必需 | 已注册应用程序的唯一标识符。 输入您在外部身份提供程序中注册的应用的 |
Audience | 必需 | 外部身份提供商打算为其提供令牌的实体。 输入您在外部身份提供程序中注册的应用的 |
Requested Scopes | Optional | 授予用户从授权端点请求数据权限的令牌。 如果计划支持刷新令牌,则此字段必须包含值 如果您的身份提供商是Microsoft Entra ID,则Atlas需要此设置。 添加默认范围,即 对于要添加的每个附加作用域,请单击 Add more scopes(添加更多作用域)。 |
Authorization Type | 必需 | 选择 Group Membership 以根据 IdP 用户群组成员身份授予授权,或选择 User ID 以向单个用户授予授权。 |
Customize Groups Claim | 必需 | 包含主体的 IdP 用户群组成员信息的声明的标识符。接受默认值,除非 IdP 使用不同的声明,或者您需要自定义声明。仅当您选择 Group Membership 时才需要此字段。 默认值: |
Customize User Claim | 必需 | 包含用户主体身份的声明的标识符。接受默认值,除非 IdP 使用不同的声明。 默认值: 如果您的身份提供程序是Microsoft Entra ID并且您选择 User ID 作为 Authorization Type,则可以使用以下值之一:
|
使用劳动力身份验证添加数据库用户
打开 Add New Database User or Group(添加新的数据库用户)对话框。
单击 Add New Database User or Group(添加新的数据库用户)。
注意
在您将 Workforce IdP应用Atlas之前,此按钮显示 Add New Database User。
选择 Federated Auth(Atlas SQL)。
在 Authentication Method 部分,选择 Federated Auth。
注意
在为组织启用Workforce IdP 之前,您无法选中此框。
分配用户或群组权限。
要向新用户或群组分配权限,请执行以下一项或多项任务:
选择或添加自定义角色。
如果您定义了任何自定义角色,则可以展开Custom Roles部分,然后从Custom Roles下拉菜单中选择一个或多个角色。
单击Add Custom Role以添加更多自定义角色。
单击Custom Roles链接可查看项目的自定义角色。
展开Specific Privileges部分,然后从Specific Privileges下拉菜单中选择一个或多个权限。
单击Add Specific Privilege可添加更多权限。 这将为群组分配对各个数据库和集合的特定权限。
删除已应用的角色或特权。
- 单击Delete旁边
- 要删除的角色或特权。
注意
如果只选择了一个选项,Atlas 不会在 Built-in Role(内置角色)、Custom Role(自定义角色)或 Specific Privilege(特定权限)选项旁边显示 Delete(删除)图标。应用了其他角色或权限后,就可以删除选定的角色或权限。
Atlas 可以将一个内置角色、多个自定义角色和多个特定权限应用到 数据库群组。
使用 Workforce Identity Federation 将客户端连接到MongoDB
下面列出了使用 Workforce Identity Federation身份验证将客户端连接到MongoDB 的方法:
Compass v1.38 +
MongoDB Shell v2.1.4+
注意
如果配置了设备授权流程,则在与 mongosh 连接时必须传递 --oidcFlows=device-auth 标志。示例:
mongosh "<connection-string>" \ --authenticationMechanism MONGODB-OIDC \ --oidcFlows=device-auth
管理现有员工 Identity Federation 配置
查看劳动力身份提供程序配置
更新劳动力身份提供程序配置
查看和管理互联组织
Revoke JWKS
注意
仅当您管理自己的签名密钥时才使用以下过程。
请勿使用此功能轮换您的签名密钥。 轮换劳动力身份提供者签名密钥时, MongoDB会在现有访问权限令牌过期时自动获取 JWKS。
如果您的私钥遭到泄露,您可以立即撤销缓存在 MongoDB 节点中的 JSON Web 密钥集 (JWKS):
单击 Revoke(保存并关闭)。
单击 Revoke 后, MongoDB将通过 JWKS 端点获取新密钥。撤销 JWKS 后,您必须重新启动客户端(例如 mongosh 或Compass )。
删除劳动力身份提供商配置
要删除Workforce Identity Provider 配置,请执行以下操作:
在 Delete Identity Provider? 模式中,单击 Delete。
使用Atlas CLI托管 Workforce Identity Federation
您可以使用Atlas CLI管理组织的 Workforce Identity Federation 配置。
配置 Workforce Identity Federation 身份验证
要使用Atlas CLI创建 OIDC 身份提供程序,运行以下命令:
atlas federatedAuthentication federationSettings identityProvider create oidc [displayName] [options]
要学习;了解有关命令语法和参数的更多信息,请参阅有关 atlas federatedAuthentication federationSettings identityProvider create oidc 的Atlas CLI文档。
在组织中启用劳动力身份提供程序
要使用Atlas CLI将身份提供程序连接到组织,运行以下命令:
atlas federatedAuthentication federationSettings connectedOrgConfigs connect [options]
要学习;了解有关命令语法和参数的更多信息,请参阅 atlas federatedAuthentication federationSettingsconnectedOrgConfigs connect 的Atlas CLI文档。
查看劳动力身份提供程序配置
要列出所有身份提供程序,请执行以下操作:
要使用Atlas CLI列出联合设置中的身份提供程序,运行以下命令:
atlas federatedAuthentication federationSettings identityProvider list [options]
要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档,了解 atlas federatedAuthentication federationSettings identityProvider list。
要查看特定身份提供程序的详细信息,请执行以下操作:
要使用Atlas CLI描述联合设置中指定的身份提供程序,运行以下命令:
atlas federatedAuthentication federationSettings identityProvider describe <identityProviderId> [options]
要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档中的 atlas federatedAuthentication federationSettings identityProvider describe。
要查看联合设置:
要使用Atlas CLI返回指定组织的联合设置详细信息,运行以下命令:
atlas federatedAuthentication federationSettings describe [options]
要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档中的 atlas federatedAuthentication federationSettings describe。
更新劳动力身份提供程序配置
要使用Atlas CLI更新OIDC 身份提供程序,运行以下命令:
atlas federatedAuthentication federationSettings identityProvider update oidc [identityProviderId] [options]
要学习;了解有关命令语法和参数的更多信息,请参阅有关 Atlas federatedAuthentication federationSettings identityProvider 更新 oidc 的Atlas CLI文档。
查看和管理互联组织
要列出连接的组织,请执行以下操作:
要使用Atlas CLI列出已连接的组织配置,运行以下命令:
atlas federatedAuthentication federationSettings connectedOrgConfigs list [options]
要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档,了解 atlas federatedAuthentication federationSettingsconnectedOrgConfigs list。
要查看已连接组织的详细信息:
要使用Atlas CLI描述连接的组织配置,运行以下命令:
atlas federatedAuthentication federationSettings connectedOrgConfigs describe [options]
要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档中的 atlas federatedAuthentication federationSettingsconnectedOrgConfigs describe。
要更新连接的组织:
要使用Atlas CLI更新连接到一项联合设置的一项组织配置,运行以下命令:
atlas federatedAuthentication federationSettings connectedOrgConfigs update [options]
要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档中的 atlas federatedAuthentication federationSettingsconnectedOrgConfigs 更新。
要删除连接的组织:
要使用 Atlas CLI 删除已连接的组织配置,运行以下命令:
atlas federatedAuthentication federationSettings connectedOrgConfigs delete [options]
要学习;了解有关命令语法和参数的更多信息,请删除Atlas CLI文档中的 atlas federatedAuthentication federationSettingsconnectedOrgConfigsdelete。
Revoke JWKS
要使用Atlas CLI从联合设置中撤销指定身份提供程序的 JWK 令牌,运行以下命令:
atlas federatedAuthentication federationSettings identityProvider revokeJwk <identityProviderId> [options]
要学习;了解有关命令语法和参数的更多信息,请参阅 Atlas federatedAuthentication federationSettings identityProvider revokeJwk 的Atlas CLI文档。
删除劳动力身份提供商配置
要断开与组织的连接:
要使用Atlas CLI断开身份提供程序与组织的连接,运行以下命令:
atlas federatedAuthentication federationSettings connectedOrgConfigs disconnect [options]
要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档中的 atlas federatedAuthentication federationSettingsconnectedOrgConfigsdisconnect。
要删除身份提供程序,请执行以下操作:
要使用Atlas CLI从联合设置中删除指定的身份提供程序,运行以下命令:
atlas federatedAuthentication federationSettings identityProvider delete <identityProviderId> [options]
要学习有关命令语法和参数的更多信息,请参阅Atlas CLI文档中的atlas federatedAuthentication federationSettings identityProvider 删除。