- 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.js
collection.Aside
Starting in MongoDB 4.2, the role no longer provides privileges to access the
system.namespaces
collection 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.namespaces
collection, 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
listDatabases
privilege action, users can run thelistDatabases
command 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 withauthorizedDatabases
option unspecified or set totrue
.
- For MongoDB 4.0.5:
- If the user does not have the
listDatabases
privilege action, users can run thelistDatabases
command to return a list of databases for which the user has thefind
action privilege if the command is run withauthorizedDatabases
option unspecified or set totrue
.
- For MongoDB 4.0.0-4.0.4:
- If the user does not have the
listDatabases
privilege action, users can run thelistDatabases
command to return a list of databases for which the user has thefind
action 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.profile
Aside
Starting in version 4.2, MongoDB removes the
system.indexes
andsystem.namespaces
collections. As such, thedbAdmin
role no longer provides privileges to access these collections. Direct access to these collections has been deprecated since MongoDB 3.0.In earlier versions, the
dbAdmin
role provides the aforementioned privilege actions (exceptdropCollection
andcreateCollection
) onsystem.indexes
andsystem.namespaces
collections, thereby allowing direct access to thesystem.indexes
andsystem.namespaces
collections.All non-system collections (i.e. database resource) For these collections,
dbAdmin
does 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
,dbAdmin
anduserAdmin
roles.
-
userAdmin
¶ Provides the ability to create and modify roles and users on the current database. Since the
userAdmin
role 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 theadmin
database, the cluster.The
userAdmin
role explicitly provides the following actions:changeCustomData
changePassword
createRole
createUser
dropRole
dropUser
grantRole
revokeRole
setAuthenticationRestriction
viewRole
viewUser
Warning
It is important to understand the security implications of granting the
userAdmin
role: a user with this role for a database can assign themselves any privilege on that database. Granting theuserAdmin
role on theadmin
database has further security implications as this indirectly provides superuser access to a cluster. Withadmin
scope a user with theuserAdmin
role 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
, andhostManager
roles. Additionally, the role provides thedropDatabase
action.
-
clusterManager
¶ Changed in version 3.4.
Provides management and monitoring actions on the cluster. A user with this role can access the
config
andlocal
databases, which are used in sharding and replication, respectively.Resource Actions cluster addShard
appendOplogNote
applicationMessage
cleanupOrphaned
flushRouterConfig
getDefaultRWConcern
(New in version 4.4)listSessions
(New in version 3.6)listShards
removeShard
replSetConfigure
replSetGetConfig
replSetGetStatus
replSetStateChange
resync
setDefaultRWConcern
(New in version 4.4)setFeatureCompatibilityVersion
setFreeMonitoring
All databases clearJumboFlag
(New in 4.2.3 and 4.0.15)enableSharding
refineCollectionShardKey
(New in 4.4)moveChunk
splitChunk
splitVector
clusterManager
provides additional privileges for theconfig
andlocal
databases.On the
config
database, permits the following actions:Resource Actions All non-system collections in the config
databasesystem.js
Aside
Starting in version 4.2, MongoDB removes the
system.indexes
andsystem.namespaces
collections. As such, theclusterManager
role no longer provides privileges to access these collections. Direct access to these collections has been deprecated since MongoDB 3.0.In earlier versions, the
clusterManager
role provides the aforementioned privilege actions on thesystem.indexes
andsystem.namespaces
collections, thereby allowing direct access to thesystem.indexes
andsystem.namespaces
collections.On the
local
database, permits the following actions:Resource Actions All non-system collections in the local
databasesystem.replset
collection
-
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)connPoolStats
getCmdLineOpts
getDefaultRWConcern
(New in version 4.4)getLog
getParameter
getShardMap
hostInfo
inprog
listDatabases
listSessions
(New in version 3.6)listShards
netstat
replSetGetConfig
replSetGetStatus
serverStatus
setFreeMonitoring
(New in version 4.0)shardingState
top
Permits the following actions on all databases in the cluster:
collStats
dbStats
getShardVersion
indexStats
useUUID
(New in version 3.6)
Permits the
find
action on allsystem.profile
collections in the cluster.On the
config
database, permits the following actions:Resource Actions All non-system collections in the config
databasesystem.js
collectionAside
Starting in version 4.2, MongoDB removes the
system.indexes
andsystem.namespaces
collections. As such, theclusterMonitor
role 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.indexes
andsystem.namespaces
collections, thereby allowing direct access to thesystem.indexes
andsystem.namespaces
collections.On the
local
database, permits the following actions:Resource Actions All collections in the local
databasesystem.js
collectionStarting in version 4.2, MongoDB removes the
system.indexes
andsystem.namespaces
collections. As such, theclusterMonitor
role 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.indexes
andsystem.namespaces
collections, thereby allowing direct access to thesystem.indexes
andsystem.namespaces
collections.system.replset
,find
-
hostManager
¶ Provides the ability to monitor and manage servers.
On the cluster as a whole, provides the following actions:
invalidateUserCache
killAnyCursor
(New in version 4.0)killAnySession
(New in version 3.6)killop
logRotate
4.4 Change
Starting in version 4.4,
hostManager
no longer provides thecpuProfiler
privilege 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
mongodump
to back up an entiremongod
instance.Provides the
insert
andupdate
actions on themms.backup
collection in theadmin
database and on thesettings
collection in theconfig
database.On anyResource, provides the
listDatabases
actionlistCollections
actionlistIndexes
action
On the cluster as a whole, provides the
appendOplogNote
getParameter
listDatabases
serverStatus
(Starting in MongoDB 4.2)
Provides the
find
action on the following:all non-system collections in the cluster, including those in the
config
andlocal
databasesThe following system collections in the cluster:
system.js
, andsystem.profile
the
admin.system.users
andadmin.system.roles
collectionsthe
config.settings
collectionlegacy
system.users
collections from versions of MongoDB prior to 2.6
Provides the
insert
andupdate
actions on theconfig.settings
collection.Changed in version 3.2.1: The
backup
role provides additional privileges to back up thesystem.profile
collection that exists when running with database profiling. Previously, users requiredread
access on this collection.
-
restore
¶ Changed in version 3.6: Provides
convertToCapped
on non-system collections.Provides the necessary privileges to restore data from backups if the data does not include
system.profile
collection data and you runmongorestore
without the--oplogReplay
option.If the backup data includes
system.profile
collection data or you run with--oplogReplay
, you need additional privileges:system.profile
If the backup data includes
system.profile
collection data and the target database does not contain thesystem.profile
collection,mongorestore
attempts to create the collection even though the program does not actually restoresystem.profile
documents. As such, the user requires additional privileges to performcreateCollection
andconvertToCapped
actions on thesystem.profile
collection for a database.Both the built-in roles
dbAdmin
anddbAdminAnyDatabase
provide the additional privileges.--oplogReplay
To run with
--oplogReplay
, create a user-defined role that hasanyAction
on anyResource.Grant only to users who must run
mongorestore
with--oplogReplay
.Provides the following action on the cluster as a whole:
Provides the following actions on all non-system collections:
bypassDocumentValidation
changeCustomData
changePassword
collMod
convertToCapped
createCollection
createIndex
createRole
createUser
dropCollection
dropRole
dropUser
grantRole
insert
revokeRole
viewRole
viewUser
Provides the following actions on
system.js
collection:Provides the following action on anyResource:
Provides the following actions on all non-system collections on the
config
and thelocal
databases:Provides the following actions on
admin.system.version
Provides the following action on
admin.system.roles
Provides the following actions on
admin.system.users
and legacysystem.users
collections:bypassDocumentValidation
collMod
createCollection
createIndex
dropCollection
find
insert
remove
update
Although,
restore
includes the ability to modify the documents in theadmin.system.users
collection using normal modification operations, only modify these data using the user management methods.Aside
Starting in version 4.2, MongoDB removes the
system.namespaces
collection. As such, therestore
role no longer provides privileges to access these collections. Direct access to these collections has been deprecated since MongoDB 3.0.In earlier versions, the
restore
role provides the aforementioned privilege actions on thesystem.namespaces
collection, 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
read
on all databases exceptlocal
andconfig
. The role also provides thelistDatabases
action on the cluster as a whole.Changed in version 3.4: Prior to 3.4,
readAnyDatabase
includeslocal
andconfig
databases. To provideread
privileges on thelocal
database, create a user in theadmin
database withread
role in thelocal
database.See also the
clusterManager
andclusterMonitor
roles for access to theconfig
andlocal
databases.
-
readWriteAnyDatabase
¶ Provides the same privileges as
readWrite
on all databases exceptlocal
andconfig
. The role also provides thelistDatabases
action on the cluster as a whole.Changed in version 3.4: Prior to 3.4,
readWriteAnyDatabase
includeslocal
andconfig
databases. To providereadWrite
privileges on thelocal
database, create a user in theadmin
database withreadWrite
role in thelocal
database.See also the
clusterManager
andclusterMonitor
roles for access to theconfig
andlocal
databases.
-
userAdminAnyDatabase
¶ Provides the same access to user administration operations as
userAdmin
on all databases exceptlocal
andconfig
.userAdminAnyDatabase
also provides the following privilege actions on the cluster:The role also provides the following privilege actions on the
system.users
andsystem.roles
collections on theadmin
database, and on legacysystem.users
collections from versions of MongoDB prior to 2.6:Changed in version 2.6.4:
userAdminAnyDatabase
added the following privilege actions on theadmin.system.users
andadmin.system.roles
collections:The
userAdminAnyDatabase
role does not restrict the privileges that a user can grant. As a result,userAdminAnyDatabase
users 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:
userAdminAnyDatabase
no longer applies to thelocal
andconfig
databases.See also the
clusterManager
andclusterMonitor
roles for access to theconfig
andlocal
databases.
-
dbAdminAnyDatabase
¶ Provides the same privileges as
dbAdmin
on all databases exceptlocal
andconfig
. The role also provides thelistDatabases
action on the cluster as a whole.Changed in version 3.4: Prior to 3.4,
dbAdminAnyDatabase
includeslocal
andconfig
databases. To providedbAdmin
privileges on thelocal
database, create a user in theadmin
database withdbAdmin
role in thelocal
database.See also the
clusterManager
andclusterMonitor
roles for access to theconfig
andlocal
databases.
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:
dbOwner
role, when scoped to theadmin
databaseuserAdmin
role, when scoped to theadmin
databaseuserAdminAnyDatabase
role
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
mongos
instances. 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
applyOps
commands, do not assign this role. Instead, create a user-defined role that grantsanyAction
on anyResource and ensure that only the users who need access to these operations have this access.