- Security >
- Role-Based Access Control >
- Built-In Roles
Built-In Roles¶
On this page
MongoDB grants access to data and commands through role-based authorization and provides built-in roles that provide the different levels of access commonly needed in a database system. You can additionally create user-defined roles.
A role grants privileges to perform sets of actions on defined resources. A given role applies to the database on which it is defined and can grant access down to a collection level of granularity.
Each of MongoDB’s built-in roles defines access at the database level for all non-system collections in the role’s database and at the collection level for all system collections.
MongoDB provides the built-in database user and
database administration roles on
every database. MongoDB provides all other built-in roles only on the
admin database.
This section describes the privileges for each built-in role. You can also
view the privileges for a built-in role at any time by issuing the
rolesInfo command with the showPrivileges and
showBuiltinRoles fields both set to true.
Database User Roles¶
Every database includes the following client roles:
-
read¶ Provides the ability to read data on all non-system collections and the
system.jscollection.Aside
Starting in MongoDB 4.2, the role no longer provides privileges to access the
system.namespacescollection directly. Direct access to the collection has been deprecated since MongoDB 3.0.In earlier versions, the role provided the aforementioned privilege actions on the
system.namespacescollection, thereby allowing direct access.The role provides read access by granting the following actions:
- For MongoDB 4.0.6+:
- If the user does not have the
listDatabasesprivilege action, users can run thelistDatabasescommand to return a list of databases for which the user has privileges (including databases for which the user has privileges on specific collections) if the command is run withauthorizedDatabasesoption unspecified or set totrue.
- For MongoDB 4.0.5:
- If the user does not have the
listDatabasesprivilege action, users can run thelistDatabasescommand to return a list of databases for which the user has thefindaction privilege if the command is run withauthorizedDatabasesoption unspecified or set totrue.
- For MongoDB 4.0.0-4.0.4:
- If the user does not have the
listDatabasesprivilege action, users can run thelistDatabasescommand to return a list of databases for which the user has thefindaction privilege.
Database Administration Roles¶
Every database includes the following database administration roles:
-
dbAdmin¶ Provides the ability to perform administrative tasks such as schema-related tasks, indexing, and gathering statistics. This role does not grant privileges for user and role management.
Specifically, the role provides the following privileges:
Resource Permitted Actions system.profileAside
Starting in version 4.2, MongoDB removes the
system.indexesandsystem.namespacescollections. As such, thedbAdminrole no longer provides privileges to access these collections. Direct access to these collections has been deprecated since MongoDB 3.0.In earlier versions, the
dbAdminrole provides the aforementioned privilege actions (exceptdropCollectionandcreateCollection) onsystem.indexesandsystem.namespacescollections, thereby allowing direct access to thesystem.indexesandsystem.namespacescollections.All non-system collections (i.e. database resource) For these collections,
dbAdmindoes not include full read access (i.e.find).
-
dbOwner¶ The database owner can perform any administrative action on the database. This role combines the privileges granted by the
readWrite,dbAdminanduserAdminroles.
-
userAdmin¶ Provides the ability to create and modify roles and users on the current database. Since the
userAdminrole allows users to grant any privilege to any user, including themselves, the role also indirectly provides superuser access to either the database or, if scoped to theadmindatabase, the cluster.The
userAdminrole explicitly provides the following actions:changeCustomDatachangePasswordcreateRolecreateUserdropRoledropUsergrantRolerevokeRolesetAuthenticationRestrictionviewRoleviewUser
Warning
It is important to understand the security implications of granting the
userAdminrole: a user with this role for a database can assign themselves any privilege on that database. Granting theuserAdminrole on theadmindatabase has further security implications as this indirectly provides superuser access to a cluster. Withadminscope a user with theuserAdminrole can grant cluster-wide roles or privileges includinguserAdminAnyDatabase.
Cluster Administration Roles¶
The admin database includes the following roles for administering the
whole system rather than just a single database. These roles include but are
not limited to replica set and sharded cluster administrative
functions.
-
clusterAdmin¶ Provides the greatest cluster-management access. This role combines the privileges granted by the
clusterManager,clusterMonitor, andhostManagerroles. Additionally, the role provides thedropDatabaseaction.
-
clusterManager¶ Changed in version 3.4.
Provides management and monitoring actions on the cluster. A user with this role can access the
configandlocaldatabases, which are used in sharding and replication, respectively.Resource Actions cluster addShardappendOplogNoteapplicationMessagecleanupOrphanedflushRouterConfiggetDefaultRWConcern(New in version 4.4)listSessions(New in version 3.6)listShardsremoveShard
replSetConfigurereplSetGetConfigreplSetGetStatusreplSetStateChangeresyncsetDefaultRWConcern(New in version 4.4)setFeatureCompatibilityVersionsetFreeMonitoring
All databases clearJumboFlag(New in 4.2.3 and 4.0.15)enableShardingrefineCollectionShardKey(New in 4.4)moveChunksplitChunksplitVector
clusterManagerprovides additional privileges for theconfigandlocaldatabases.On the
configdatabase, permits the following actions:Resource Actions All non-system collections in the configdatabasesystem.jsAside
Starting in version 4.2, MongoDB removes the
system.indexesandsystem.namespacescollections. As such, theclusterManagerrole no longer provides privileges to access these collections. Direct access to these collections has been deprecated since MongoDB 3.0.In earlier versions, the
clusterManagerrole provides the aforementioned privilege actions on thesystem.indexesandsystem.namespacescollections, thereby allowing direct access to thesystem.indexesandsystem.namespacescollections.On the
localdatabase, permits the following actions:Resource Actions All non-system collections in the localdatabasesystem.replsetcollection
-
clusterMonitor¶ Changed in version 3.4.
Provides read-only access to monitoring tools, such as the MongoDB Cloud Manager and Ops Manager monitoring agent.
Permits the following actions on the cluster as a whole:
checkFreeMonitoringStatus(New in version 4.0)connPoolStatsgetCmdLineOptsgetDefaultRWConcern(New in version 4.4)getLoggetParametergetShardMaphostInfoinproglistDatabases
listSessions(New in version 3.6)listShardsnetstatreplSetGetConfigreplSetGetStatusserverStatussetFreeMonitoring(New in version 4.0)shardingStatetop
Permits the following actions on all databases in the cluster:
collStatsdbStatsgetShardVersionindexStatsuseUUID(New in version 3.6)
Permits the
findaction on allsystem.profilecollections in the cluster.On the
configdatabase, permits the following actions:Resource Actions All non-system collections in the configdatabasesystem.jscollectionAside
Starting in version 4.2, MongoDB removes the
system.indexesandsystem.namespacescollections. As such, theclusterMonitorrole no longer provides privileges to access these collections. Direct access to these collections has been deprecated since MongoDB 3.0.In earlier versions, the role provides the aforementioned privilege actions on the
system.indexesandsystem.namespacescollections, thereby allowing direct access to thesystem.indexesandsystem.namespacescollections.On the
localdatabase, permits the following actions:Resource Actions All collections in the localdatabasesystem.jscollectionStarting in version 4.2, MongoDB removes the
system.indexesandsystem.namespacescollections. As such, theclusterMonitorrole no longer provides privileges to access these collections. Direct access to these collections has been deprecated since MongoDB 3.0.In earlier versions, the role provides the aforementioned privilege actions on the
system.indexesandsystem.namespacescollections, thereby allowing direct access to thesystem.indexesandsystem.namespacescollections.system.replset,find
-
hostManager¶ Provides the ability to monitor and manage servers.
On the cluster as a whole, provides the following actions:
invalidateUserCachekillAnyCursor(New in version 4.0)killAnySession(New in version 3.6)killoplogRotate
4.4 Change
Starting in version 4.4,
hostManagerno longer provides thecpuProfilerprivilege action on the cluster.On all databases in the cluster, provides the following actions:
Backup and Restoration Roles¶
The admin database includes the following roles for backing up and
restoring data:
-
backup¶ Provides minimal privileges needed for backing up data. This role provides sufficient privileges to use the MongoDB Cloud Manager backup agent, Ops Manager backup agent, or to use
mongodumpto back up an entiremongodinstance.Provides the
insertandupdateactions on themms.backupcollection in theadmindatabase and on thesettingscollection in theconfigdatabase.On anyResource, provides the
listDatabasesactionlistCollectionsactionlistIndexesaction
On the cluster as a whole, provides the
appendOplogNotegetParameterlistDatabasesserverStatus(Starting in MongoDB 4.2)
Provides the
findaction on the following:all non-system collections in the cluster, including those in the
configandlocaldatabasesThe following system collections in the cluster:
system.js, andsystem.profilethe
admin.system.usersandadmin.system.rolescollectionsthe
config.settingscollectionlegacy
system.userscollections from versions of MongoDB prior to 2.6
Provides the
insertandupdateactions on theconfig.settingscollection.Changed in version 3.2.1: The
backuprole provides additional privileges to back up thesystem.profilecollection that exists when running with database profiling. Previously, users requiredreadaccess on this collection.
-
restore¶ Changed in version 3.6: Provides
convertToCappedon non-system collections.Provides the necessary privileges to restore data from backups if the data does not include
system.profilecollection data and you runmongorestorewithout the--oplogReplayoption.If the backup data includes
system.profilecollection data or you run with--oplogReplay, you need additional privileges:system.profileIf the backup data includes
system.profilecollection data and the target database does not contain thesystem.profilecollection,mongorestoreattempts to create the collection even though the program does not actually restoresystem.profiledocuments. As such, the user requires additional privileges to performcreateCollectionandconvertToCappedactions on thesystem.profilecollection for a database.Both the built-in roles
dbAdminanddbAdminAnyDatabaseprovide the additional privileges.--oplogReplayTo run with
--oplogReplay, create a user-defined role that hasanyActionon anyResource.Grant only to users who must run
mongorestorewith--oplogReplay.Provides the following action on the cluster as a whole:
Provides the following actions on all non-system collections:
bypassDocumentValidationchangeCustomDatachangePasswordcollModconvertToCappedcreateCollectioncreateIndexcreateRolecreateUserdropCollectiondropRoledropUsergrantRoleinsertrevokeRoleviewRoleviewUser
Provides the following actions on
system.jscollection:Provides the following action on anyResource:
Provides the following actions on all non-system collections on the
configand thelocaldatabases:Provides the following actions on
admin.system.versionProvides the following action on
admin.system.rolesProvides the following actions on
admin.system.usersand legacysystem.userscollections:bypassDocumentValidationcollModcreateCollectioncreateIndexdropCollectionfindinsertremoveupdate
Although,
restoreincludes the ability to modify the documents in theadmin.system.userscollection using normal modification operations, only modify these data using the user management methods.Aside
Starting in version 4.2, MongoDB removes the
system.namespacescollection. As such, therestorerole no longer provides privileges to access these collections. Direct access to these collections has been deprecated since MongoDB 3.0.In earlier versions, the
restorerole provides the aforementioned privilege actions on thesystem.namespacescollection, thereby allowing direct access to the collection.
All-Database Roles¶
Changed in version 3.4.
The following roles are available on the admin database and provide
privileges which apply to all databases except local and
config:
-
readAnyDatabase¶ Provides the same read-only privileges as
readon all databases exceptlocalandconfig. The role also provides thelistDatabasesaction on the cluster as a whole.Changed in version 3.4: Prior to 3.4,
readAnyDatabaseincludeslocalandconfigdatabases. To providereadprivileges on thelocaldatabase, create a user in theadmindatabase withreadrole in thelocaldatabase.See also the
clusterManagerandclusterMonitorroles for access to theconfigandlocaldatabases.
-
readWriteAnyDatabase¶ Provides the same privileges as
readWriteon all databases exceptlocalandconfig. The role also provides thelistDatabasesaction on the cluster as a whole.Changed in version 3.4: Prior to 3.4,
readWriteAnyDatabaseincludeslocalandconfigdatabases. To providereadWriteprivileges on thelocaldatabase, create a user in theadmindatabase withreadWriterole in thelocaldatabase.See also the
clusterManagerandclusterMonitorroles for access to theconfigandlocaldatabases.
-
userAdminAnyDatabase¶ Provides the same access to user administration operations as
userAdminon all databases exceptlocalandconfig.userAdminAnyDatabasealso provides the following privilege actions on the cluster:The role also provides the following privilege actions on the
system.usersandsystem.rolescollections on theadmindatabase, and on legacysystem.userscollections from versions of MongoDB prior to 2.6:Changed in version 2.6.4:
userAdminAnyDatabaseadded the following privilege actions on theadmin.system.usersandadmin.system.rolescollections:The
userAdminAnyDatabaserole does not restrict the privileges that a user can grant. As a result,userAdminAnyDatabaseusers can grant themselves privileges in excess of their current privileges and even can grant themselves all privileges, even though the role does not explicitly authorize privileges beyond user administration. This role is effectively a MongoDB system superuser.Changed in version 3.4:
userAdminAnyDatabaseno longer applies to thelocalandconfigdatabases.See also the
clusterManagerandclusterMonitorroles for access to theconfigandlocaldatabases.
-
dbAdminAnyDatabase¶ Provides the same privileges as
dbAdminon all databases exceptlocalandconfig. The role also provides thelistDatabasesaction on the cluster as a whole.Changed in version 3.4: Prior to 3.4,
dbAdminAnyDatabaseincludeslocalandconfigdatabases. To providedbAdminprivileges on thelocaldatabase, create a user in theadmindatabase withdbAdminrole in thelocaldatabase.See also the
clusterManagerandclusterMonitorroles for access to theconfigandlocaldatabases.
Superuser Roles¶
Several roles provide either indirect or direct system-wide superuser access.
The following roles provide the ability to assign any user any privilege on any database, which means that users with one of these roles can assign themselves any privilege on any database:
dbOwnerrole, when scoped to theadmindatabaseuserAdminrole, when scoped to theadmindatabaseuserAdminAnyDatabaserole
The following role provides full privileges on all resources:
Internal Role¶
-
__system¶ MongoDB assigns this role to user objects that represent cluster members, such as replica set members and
mongosinstances. The role entitles its holder 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.
If you need access to all actions on all resources, for example to run
applyOpscommands, do not assign this role. Instead, create a user-defined role that grantsanyActionon anyResource and ensure that only the users who need access to these operations have this access.