MongoDB提供一些内置角色,它给数据库系统提供了不同的访问级别。每个数据库都有内置的数据库用户角色和数据库管理角色。admin数据库则包含了额外的一些角色。

本页面简单描述了这些内置角色。每个角色所赋予的特定的权限,请看Build-in Roles参考页。



数据库用户角色

每个数据库包含如下角色:

Role

Short Description

read

For the specific privileges granted by the role, see read.

提供对于non-system collections和以下system collections(system.indexes,system.js和system.namespaces)的读权限。

 

readWrite

For the specific privileges granted by the role, see readWrite.

提供了所有read所具有的权限,同时还具有修改non-system collections以及system.js collection的权限。


数据库管理权限

每个数据库包含以下数据库管理权限:

Role

Short Description

dbAdmin

For the specific privileges granted by the role, see dbAdmin.

可以执行schema相关工作,创建索引/收集统计数据等。该角色没有用户和角色管理权限。

dbOwner

可以管理数据库。它包含了readWrite/dbAdmin/userAdmin的角色权限。

userAdmin

For the specific privileges granted by the role, see userAdmin.

可以在当前数据库创建和修改用户和角色。因为userAdmin允许相应用户将任何特权授予给任何用户,所以该角色可以间接给数据库提供超级用户的权限,如果作用到admin数据库,还可以对集群提供超级用户的权限。


集群管理权限

admin数据库为管理整个数据库系统提供了以下角色。这些角色包含了副本集和分片集群,但不限于此。

Role

Short Description

clusterAdmin

集群管理提供了集群管理的最高权限。该角色包含的权限涵盖clusterManager, clusterMonitor,hostManager。

另外,该角色可执行dropDatabase

clusterManager

For the specific privileges granted by the role, see clusterManager.

提供了管理和监控集群的功能。被赋予此角色的用户可以访问config/local数据库,这些数据库分别被用于分片和副本。

clusterMonitor

For the specific privileges granted by the role, see clusterMonitor.

为MongoDB Cloud Manager和Ops Manager监控agent提供只读访问权限。

hostManager

用于监控和管理server

For the specific privileges granted by the role, see hostManager.


备份和恢复权限:

admin数据库包含如下备份和恢复数据的角色。

Role

Short Description

backup

提供备份数据所需的特权。该角色提供足够的权限来使用MongoDB云管理备份agent/Ops Manager备份agent,或mongodump。

For the specific privileges granted by the role, see backup.

restore

Provides privileges needed to restore data with mongorestore without the --oplogReplay option or without system.profile collection data.

提供了使用mongorestore恢复数据的权限,mongorestore不能带有参数--oplogReplay,也不能使用system.profile collection的数据。

For the specific privileges granted by the role, see restore.


全数据库角色

admin数据库提供了以下角色可以应用到所有数据库,和单个数据库中的角色大致等同。

Role

Short Description

readAnyDatabase

和read提供相同的权限,只不过是该角色应用到所有数据库。该角色同时可以在整个集群上使用listDatabases命令。

For the specific privileges granted by the role, see readAnyDatabase.

readWriteAnyDatabase

和readWrite提供相同的权限,只不过是该角色应用到所有数据库。该角色同时可以在整个集群上使用listDatabases命令。

For the specific privileges granted by the role, see readWriteAnyDatabase.

userAdminAnyDatabase

和userAdmin提供相同的权限,只不过是该角色应用到所有数据库。

因为userAdminAnyDatabase允许所有权限赋予给所有用户,包括自身,所以间接提供了superuser权限。

For the specific privileges granted by the role, see userAdminAnyDatabase.

dbAdminAnyDatabase

和dbAdmin提供相同的权限,只不过是该角色应用到所有数据库。该角色同时可以在整个集群上使用listDatabases命令。

For the specific privileges granted by the role, see dbAdminAnyDatabase.


超级用户角色

以下角色对所有资源提供全部的权限:

Role

Short Description

root

Provides access to the operations and all the resources of thereadWriteAnyDatabasedbAdminAnyDatabaseuserAdminAnyDatabaseand clusterAdmin roles combined.

For the specific privileges granted by the role, see root.


Internal Role

内部角色

Role

Short Description

__system

Provides privileges to take any action against any object in the database.

Do not assign this role to user objects representing applications or human administrators, other than in exceptional circumstances.

For more information, see root.

 

https://docs.mongodb.com/manual/core/security-built-in-roles/