You can create custom roles in Atlas when the built-in roles don't include your desired set of privileges. Atlas applies each database user's custom roles together with:
Any built-in roles you assign when you add a database user or modify a database user.
Any specific privileges you assign when you add a database user or modify a database user.
您可以为每个数据库用户分配多个自定义角色。
注意
免费集群和 Flex 集群限制
Changes to custom roles might take up to 30 seconds to deploy in Free clusters and Flex clusters.
The privilege actions available for custom roles and the custom roles API represent a subset of the privilege actions available for built-in roles.
要查看自定义角色特权列表,请参阅 API 参考资料。
Considerations
重要
You must use the Atlas CLI, Atlas Administration API, Atlas UI, or a supported integration to add, modify, or delete database roles on Atlas clusters. Otherwise, Atlas rolls back any role modifications.
您最多可以向单个数据库用户分配 20 个自定义角色
You can create up to 100 custom roles per project by default. IMPORTANT: If you require more custom roles per project, you can increase the number of custom roles up to a maximum of 1400 through the Atlas Administration API using the Set One Project Limit endpoint.
Atlas 审核项目操作日志中的自定义 MongoDB 角色的创建、删除和更新操作
如果为用户分配了多个角色,而这些角色授予 某个对象的权限相互冲突,则 Atlas 会尊重任何角色内的 最高权限。
例如:
您创建两个自定义角色,并将其分配给用户 A:
The first custom role grants only
readprivileges on your database. It also grants bypassDocumentValidation on your database.The second role grants
dbAdminprivileges on your database. It doesn't grant bypassDocumentValidation, which is an implicit denial of bypass permissions.
用户 A 将拥有数据库的所有
dbAdmin特权,因为dbAdmin是更高的数据库访问权限。用户 A 还可以 bypassDocumentValidation,因为 bypassDocumentValidation 是更高的绕过权限。
必需的访问权限
要配置自定义数据库角色,您必须拥有 Atlas 的 Organization Owner、Project Owner 或 Project Database Access Admin 访问权限。
添加自定义角色
如需使用 Atlas CLI 创建项目的自定义数据库角色,请运行以下命令:
atlas customDbRoles create <roleName> [options]
要了解有关命令语法和参数的更多信息,请参阅 Atlas CLI 文档中的 atlas customDbRoles create。
要通过 Atlas 管理 API 创建自定义角色,请参阅创建一个。
请按照以下步骤通过 Atlas 用户界面创建自定义角色:
AtlasGoDatabase & Network Access在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
The Database & Network Access page displays after you complete the preceding steps.
输入角色信息。
字段 | 说明 |
|---|---|
Custom Role Name | 自定义角色的名称。 重要:指定的角色名称只能包含字母、数字、下划线或连字符。此外,不能指定满足以下任何条件的角色名称:
|
Action or Role | Privileges granted by the role. Click the dropdown to view the list of available privilege actions and roles. Atlas 将操作和角色分为以下类别:
从单一类别中选择操作或角色。一旦选择了某个操作或角色,Atlas 就会禁用其他类别,但以下情况除外。如果您从 Global Actions and Roles 选择操作/角色,您仍然可以从 Custom Roles 选择操作/角色。 要授予其他类别中的操作和角色,请单击 Add an action or role 新增一行。 Atlas 会禁用项目中任何集群版本都无法使用的操作。自定义角色是在项目级别定义的,并且必须与项目集群使用的每个 MongoDB 版本兼容。 |
Database | 授予所选操作和角色的数据库(如果适用)。 要指定数据库,请键入数据库名称或选择 Apply to any database。 WARNING: If you select Apply to any database, the roles grants permissions for actions on the 对于 Collection Actions 和 Database Actions and Roles 类别下的所有角色和操作,此字段是必填字段。 |
Collection | 授予操作和角色的指定数据库内的集合(如果适用)。 要指定集合,请键入集合名称或选择 Apply to any collection。 警告:如果选择 Apply to any collection,则角色将授予对 对于 Collection Actions 下的所有角色和操作,此字段是必填字段。 |
要对多个数据库和集合授予同一组权限,请单击 Add a database or collection。
查看自定义角色
如需使用 Atlas CLI 列出项目的所有自定义数据库角色,请运行以下命令:
atlas customDbRoles list [options]
如需使用 Atlas CLI 返回指定项目中单个自定义数据库角色的详细信息,请运行以下命令:
atlas customDbRoles describe <roleName> [options]
要详细了解先前命令的语法和参数,请参阅 Atlas CLI 文档中的 atlas customDbRoles list 和 atlas customDbRoles describe。
要通过 Atlas 管理 API 查看自定义角色,请参阅获取全部。
要通过 Atlas 用户界面查看自定义角色:
AtlasGoDatabase & Network Access在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
The Database & Network Access page displays after you complete the preceding steps.
修改自定义角色
如需使用 Atlas CLI 更新项目的自定义数据库角色, 请运行以下命令:
atlas customDbRoles update <roleName> [options]
要了解有关命令语法和参数的更多信息,请参阅 Atlas CLI 文档中的 atlas customDbRoles update。
要通过 Atlas 管理 API 修改自定义角色,请参阅更新一个。
请按照以下步骤通过 Atlas 用户界面修改自定义角色:
AtlasGoDatabase & Network Access在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
The Database & Network Access page displays after you complete the preceding steps.
删除自定义角色
如需使用 Atlas CLI 删除项目的自定义数据库角色, 请运行以下命令:
atlas customDbRoles delete <roleName> [options]
To learn more about the command syntax and parameters, see the Atlas CLI documentation for atlas customDbRoles delete.
要通过 Atlas 管理 API 删除自定义角色,请参阅删除一个。
请按照以下步骤通过 Atlas 用户界面删除自定义角色:
AtlasGoDatabase & Network Access在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
The Database & Network Access page displays after you complete the preceding steps.
出现以下情况时无法删除自定义角色:
删除角色后,一个或多个子角色将没有父角色或操作。
当删除角色会导致一个或多个数据库用户没有角色时。
分配自定义角色
添加数据库用户或修改数据库用户时,可以在 Atlas 用户界面中分配自定义角色。要通过 Atlas Administration API 分配自定义角色,请参阅创建数据库用户或更新数据库用户。