- Security >
- Security Reference >
- 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 on the following system collections:
system.indexes,system.js, andsystem.namespacescollections. The role provides read access by granting the following actions:
Database Administration Roles¶
Every database includes the following database administration roles:
-
dbAdmin¶ Provides the following actions on the database’s
system.indexes,system.namespaces, andsystem.profilecollections:collStatsdbHashdbStatsfindkillCursorslistIndexeslistCollectionsdropCollectionandcreateCollectiononsystem.profileonly
Changed in version 2.6.4:
dbAdminadded thecreateCollectionfor thesystem.profilecollection. Previous versions only had thedropCollectionon thesystem.profilecollection.Provides the following actions on all non-system collections. This role does not include full read access on non-system collections:
-
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. This role also indirectly provides superuser access to either the database or, if scoped to the
admindatabase, the cluster. TheuserAdminrole allows users to grant any user any privilege, including themselves.The
userAdminrole explicitly provides the following actions:
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¶ 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.Provides the following actions on the cluster as a whole:
addShardapplicationMessagecleanupOrphanedflushRouterConfiglistShardsremoveShardreplSetConfigurereplSetGetConfigreplSetGetStatusreplSetStateChangeresync
Provides the following actions on all databases in the cluster:
On the
configdatabase, provides the following actions on thesettingscollection:On the
configdatabase, provides the following actions on all configuration collections and on thesystem.indexes,system.js, andsystem.namespacescollections:On the
localdatabase, provides the following actions on thereplsetcollection:
-
clusterMonitor¶ Provides read-only access to monitoring tools, such as the MongoDB Cloud Manager and Ops Manager monitoring agent.
Provides the following actions on the cluster as a whole:
connPoolStatscursorInfogetCmdLineOptsgetLoggetParametergetShardMaphostInfoinproglistDatabaseslistShardsnetstatreplSetGetStatusreplSetGetConfigserverStatusshardingStatetop
Provides the following actions on all databases in the cluster:
Provides the
findaction on allsystem.profilecollections in the cluster.Provides the following actions on the
configdatabase’s configuration collections andsystem.indexes,system.js, andsystem.namespacescollections:
-
hostManager¶ Provides the ability to monitor and manage servers.
Provides the following actions on the cluster as a whole:
applicationMessagecloseAllDatabasesconnPoolSynccpuProfilerdiagLoggingflushRouterConfigfsyncinvalidateUserCachekilloplogRotateresyncsetParametershutdowntouchunlock
Provides the following actions on all databases in the cluster:
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.Provides the
listDatabasesaction on the cluster as a whole.Provides the
listCollectionsaction on all databases.Provides the
listIndexesaction for all collections.Provides the
bypassDocumentValidationaction for collections that have document validation.Provides the
findaction on the following:- all non-system collections in the cluster
- all the following system collections in the cluster:
system.indexes,system.namespaces, andsystem.js - the
admin.system.usersandadmin.system.rolescollections - the
config.settingscollection - legacy
system.userscollections from versions of MongoDB prior to 2.6
Changed in version 3.2.1: The
backuprole provides additional privileges to back up thesystem.profilecollections that exist when running with database profiling. Previously, users required an additionalreadaccess on this collection.
-
restore¶ 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 actions on all non-system collections and
system.jscollections in the cluster; on theadmin.system.usersandadmin.system.rolescollections in theadmindatabase; and on legacysystem.userscollections from versions of MongoDB prior to 2.6:Provides the
listCollectionsaction on all databases.Provides the following additional actions on
admin.system.usersand legacysystem.userscollections:Provides the
findaction on all thesystem.namespacescollections in the cluster.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.
All-Database Roles¶
The admin database provides the following roles that apply to all
databases in a mongod instance and are roughly equivalent to their
single-database equivalents:
-
readAnyDatabase¶ Provides the same read-only permissions as
read, except it applies to all databases in the cluster. The role also provides thelistDatabasesaction on the cluster as a whole.
-
readWriteAnyDatabase¶ Provides the same read and write permissions as
readWrite, except it applies to all databases in the cluster. The role also provides thelistDatabasesaction on the cluster as a whole.
-
userAdminAnyDatabase¶ Provides the same access to user administration operations as
userAdmin, except it applies to all databases in the cluster. The role also provides the following actions on the cluster as a whole:The role also provides the following actions on the
admin.system.usersandadmin.system.rolescollections on theadmindatabase, and on legacysystem.userscollections from versions of MongoDB prior to 2.6:Changed in version 2.6.4:
userAdminAnyDatabaseadded the following permissions on theadmin.system.usersandadmin.system.rolescollections:The
userAdminAnyDatabaserole does not restrict the permissions 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.
-
dbAdminAnyDatabase¶ Provides the same access to database administration operations as
dbAdmin, except it applies to all databases in the cluster. The role also provides thelistDatabasesaction on the cluster as a whole.
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:
-
root¶ Provides access to the operations and all the resources of the
readWriteAnyDatabase,dbAdminAnyDatabase,userAdminAnyDatabase,clusterAdminroles,restorecombined.
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.