(2018-01-25 15:52:29)
转载▼
标签: mongodb shard 最小权限 shardcollection privileges | 分类: 数据库 |
---|
操作需求是为程序用户提供一个最小权限,满足以下操作需求:
通过这样限制,最多只会影响到指定的数据库, 避免因为程序问题或者其他外部因素导致数据处理逻辑出问题而影响到整个集群。
以myDb.myCollection
为例,对collection开启shard,需要进行以下操作:
所以需要相应的权限来运行以上3个操作命令。 参考官网文档描述,需要给用户提供两个权限:
enableSharding
command and can shard a collection using the shardCollection
command. Apply this action to database or collection resources.
db.collection.createIndex()
method and the createIndexes
command. Apply this action to database or collection resources.
因为原来项目用户关于业务数据库的角色就已经是dbOwner
,
因此,再创建一个具有开启shard相关操作权限的角色,授予项目数据库用户即可实现最小权限控制。
首先创建新的角色,提供上述的两个操作权限。
这里命名为opShardRole
,可以根据实际需求更改:
use myDb;
db.createRole({
role: "opShardRole",
privileges:[
{
resource:{db:"myDb", collection:""},
actions:["enableSharding, "createIndex"]
}
],
roles:[]
}
)
然后将opShardRole
角色grant给项目用户,这里假设用户名为project_user
:
db.grantRolesToUser("project_user",[{role:"opShardRole", db:"myDb"}])
至此,操作完成,可以通过项目用户进行测试开启shard相关操作有无问题。
切换到业务db,并检查相关的用户及角色:
可以看到,opShardRole
这个角色确实已经有了对业务数据库myDb
的所需shard操作权限,
同时,project_user
这个用户也已经有了opShardRole
角色授权。
分享:
(adsbygoogle = window.adsbygoogle || []).push({});
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有