MongoDB用户及权限管理之角色说明的示例分析
admin
2023-05-27 09:01:28
0

mongodb安装完后默认是不开启auth模块的,普通用户和超级管理员均不通过认证就可操作。当然裸奔有风险,安全起见还是开启auth模块。

首先需要了解下面几点:

1、mongodb是没有默认管理员账号,所以要先添加管理员账号,然后开启权限认证。

2、切换到admin数据库,添加的账号才是管理员账号。

3、用户只能在用户所在数据库登录,包括管理员账号。

4、管理员可以管理所有数据库,但是不能直接管理其他数据库,要先在admin数据库认证后才可以。这一点比较怪。

1.用户权限角色说明

1.1  Database User Roles

  • read

允许用户读取指定数据库

Provides the ability to read data on allnon-system collections and on the following system collections: system.indexes,system.js, and system.namespaces collections.

拥有如下权限:

aggregate,checkShardingIndex,cloneCollectionAsCapped,collStats

count,dataSize,dbHash,dbStats,distinct,filemd5

geoNear,geoSearch,geoWalk,group

mapReduce (inline output only.),text (beta  feature.)

  • readWrite

允许用户读写指定数据库

Provides all the privileges of the readrole and the ability to modify data on all non-system collections and thesystem.js collection.

除了具有read权限,还拥有以下权限:

cloneCollection (as the target  database.),convertToCapped

create (and to create collections implicitly.)

drop(),dropIndexes,emptycapped,ensureIndex()

findAndModify,mapReduce (output to a collection.)

renameCollection (within the same database.)

read和readWrite只要就是对库中表的操作权限

1.2 Database Administration Roles

  • dbAdmin

允许用户在指定数据库中执行管理函数,如索引创建、删除,查看统计或访问system.profile

Provides the ability to performadministrative tasks such as schema-related tasks, indexing, gatheringstatistics. This role does not grant privileges for user and role management.

拥有如下权限:

clean,collMod,collStats,compact,convertToCapped

create,db.createCollection(),dbStats,drop(),dropIndexes,ensureIndex()

indexStats,profile,reIndex,renameCollection  (within a single database.),validate

  • dbOwner

Provides the ability to perform anyadministrative action on the database. This role combines the privilegesgranted by the readWrite, dbAdmin and userAdmin roles.

  • userAdmin

允许用户向system.users集合写入,可以找指定数据库里创建、删除和管理用户

Provides the ability to create and modifyroles and users on the current database. Since the userAdmin role allows usersto grant any privilege to any user, including themselves, the role alsoindirectly provides superuser access to either the database or, if scoped tothe admin database, the cluster.

1.3 Cluster Administration Roles

  • clusterAdmin

只在admin数据库中可用,赋予用户所有分片和复制集相关函数的管理权限。

Provides the greatest cluster-managementaccess. This role combines the privileges granted by the clusterManager,clusterMonitor, and hostManager roles. Additionally, the role provides thedropDatabase action.

拥有如下权限:

addShard,closeAllDatabases,connPoolStats,connPoolSync,_cpuProfilerStart

_cpuProfilerStop,cursorInfo,diagLogging,dropDatabase

enableSharding,flushRouterConfig,fsync,db.fsyncUnlock()

getCmdLineOpts,getLog,getParameter,getShardMap,getShardVersion

hostInfo,db.currentOp(),db.killOp(),listDatabases,listShards

logRotate,moveChunk,movePrimary,netstat,removeShard,unsetSharding

repairDatabase,replSetFreeze,replSetGetStatus,replSetInitiate

replSetMaintenance,replSetReconfig,replSetStepDown,replSetSyncFrom

resync,serverStatus,setParameter,setShardVersion,shardCollection

shardingState,shutdown,splitChunk,splitVector,split,top,touch

  • clusterManager

Provides management and monitoring actionson the cluster. A user with this role can access the config and localdatabases, which are used in sharding and replication, respectively.

  • clusterMonitor

Provides read-only access to monitoringtools, such as the MongoDB Cloud Manager and Ops Manager monitoring agent.

  • hostManager

Provides the ability to monitor and manageservers.

1.4 Backup and Restoration Roles

  • backup

Provides privileges needed to back up data.This role provides sufficient privileges to use the MongoDB Cloud Managerbackup agent, Ops Manager backup agent, or to use mongodump.

  • restore

Provides privileges needed to restore datawith mongorestore without the --oplogReplay option or without system.profilecollection data.

1.5 All-Database Roles

  • readAnyDatabase

只在admin数据库中可用,赋予用户所有数据库的读权限

Provides the same read-only permissions asread, except it applies to all but the local and config databases in thecluster. The role also provides the listDatabases action on the cluster as awhole.

  • readWriteAnyDatabase

只在admin数据库中可用,赋予用户所有数据库的读写权限

Provides the same read and writepermissions as readWrite, except it applies to all but the local and configdatabases in the cluster. The role also provides the listDatabases action onthe cluster as a whole.

  • userAdminAnyDatabase

只在admin数据库中可用,赋予用户所有数据库的userAdmin权限

Provides the same access to useradministration operations as userAdmin, except it applies to all but the localand config databases in the cluster.

Since the userAdminAnyDatabase role allowsusers to grant any privilege to any user, including themselves, the role alsoindirectly provides superuser access.

  • dbAdminAnyDatabase

只在admin数据库中可用,赋予用户所有数据库的dbAdmin权限。

Provides the same access to databaseadministration operations as dbAdmin, except it applies to all but the localand config databases in the cluster. The role also provides the listDatabasesaction on the cluster as a whole.

1.6 Superuser Roles

  • root

只在admin数据库中可用。超级账号,超级权限

Provides access to the operations and allthe resources of the readWriteAnyDatabase, dbAdminAnyDatabase,userAdminAnyDatabase, clusterAdmin, restore, and backup combined.

相关内容

热门资讯

伊朗与阿曼会谈最新细节曝光 美国有线电视新闻网(CNN)8月5日报道,伊朗和阿曼将敲定一项关于通过霍尔木兹海峡进行商业航运的框架...
大科学装置建设全面提速 创新成... 央视网消息(新闻联播):重大科技基础设施是建设科技强国的利器。今年以来,我国大科学装置建设全面提速,...
贝塔创新科技观察算力公有化趋势... 从公有云到公有算力网络:AI基础设施进入弹性调度时代 过去几年,市场更关注大模型参数、算法能力和应...
活力中国调研行丨激活创新源 合... 新华社合肥8月5日电 题:激活创新源 合肥大健康科研成果加速产业化 新华社记者高亢、张紫赟 近日,“...
凤凰连线:为何伊朗称“即使与阿... 据凤凰卫视报道,伊朗知情人士当地时间周三透露称,伊朗与阿曼就霍尔木兹海峡船舶通行安排,可能达成协议,...
伊朗称与阿曼就霍尔木兹海峡航运... 据凤凰卫视报道,伊朗外交部发言人巴加埃5日表示,伊朗与阿曼已就霍尔木兹海峡拟定航道的地理坐标达成一致...
予非知识图谱大模型完成生成式人... 近日,山东省网信办正式公布生成式人工智能服务备案名录,潍坊华创信息技术有限公司自主研发的“予非知识图...
学习语丨人工智能应该是造福全人... 近日,习近平总书记向2025世界智能产业博览会致贺信,指出:“人工智能应该是造福全人类的国际公共产品...
2026年交易全链路可追溯的智... 2026-08-05 12:10:48 作者:狼叫兽 2026年被视作智能体支付规模化落地的关键之年...
百余名中外专家齐聚海西 共话人... 8月4日,人工智能赋能的天文学开放科学会议(第二届)在青海省海西州盛大启幕。来自中国、美国、英国、法...