笔记-mongodb-用户及角色
笔记-mongodb-用户及角色
1. users
其实mongodb支持多种验证方式,本文只提及最简单也最常用的方式。
1.1. Authentication Database
When adding a user, you create the user in a specific database. This database is the authentication database for the user.
A user can have privileges across different databases; that is, a user’s privileges are not limited to their authentication database. By assigning to the user roles in other databases, a user created in one database can have permissions to act on other databases. For more information on roles, see Role-Based Access Control.
The user’s name and authentication database serve as a unique identifier for that user. That is, if two users have the same name but are created in different databases, they are two separate users. If you intend to have a single user with permissions on multiple databases, create a single user with roles in the applicable databases instead of creating the user multiple times in different databases.
1.mongodb的用户是依赖于database的;一个用户可以描述为username@database,不同数据库下的同名用户视为不同的用户;
2.用户的权限是可以跨database的,这依赖于role;
1.2. Authenticate a User
验证用户有两种方式:
mongod命令
db.auth()方法
1.3. create user
使用createUser()方法创建用户。
use reporting
db.createUser(
{
user: "reportsUser",
pwd: "12345678",
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
role代表角色,在下面的章节中会列出常用role;
db代表数据库。
1.4. 启用验证enable auth
有两种方式:
- 命令:mongod 命令带上—auth参数
- 配置文件:在配置文件中添加auth=true #具体可能会因为版本不同有所差别
2. ROLE
mongodb内置了一些角色,也可以由用户创建,跟其它数据库差不多;
2.1. Database User Roles
Every database includes the following roles:
最常用的两种角色。
Role |
Short Description |
Provides the ability to read data on all non-system collections and on the following system collections: system.indexes, system.js, and system.namespacescollections. For the specific privileges granted by the role, see read. |
|
Provides all the privileges of the read role and the ability to modify data on all non-system collections and the system.js collection. For the specific privileges granted by the role, see readWrite. |
2.2. Database Administration Roles
Every database includes the following database administration roles:
Role |
Short Description |
Provides the ability to perform administrative tasks such as schema-related tasks, indexing, gathering statistics. This role does not grant privileges for user and role management. For the specific privileges granted by the role, see dbAdmin. |
|
Provides the ability to perform any administrative action on the database. This role combines the privileges granted by the readWrite, dbAdmin and userAdmin roles. |
|
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 the admin database, the cluster. For the specific privileges granted by the role, see userAdmin. |
2.3. All-Database Roles
Changed in version 3.4.
These roles in the admin database apply to all but the local and config databases in a mongod instance:
Role |
Short Description |
略 |
|
略 |
|
略 |
|
略 |
还有一个super role角色叫root,基本就是上面四个角色的合体版。
2.4. collection-level access control
在角色中可以设置privileges属性,它提供了针对集合层级的权限控制。
privileges: [
{ resource: { db: "products", collection: "inventory" }, actions: [ "find", "update", "insert" ] },
{ resource: { db: "products", collection: "orders" }, actions: [ "find" ] }
]
创建角色:
use admin
db.createRole(
{
role: "manageOpRole",
privileges: [
{ resource: { cluster: true }, actions: [ "killop", "inprog" ] },
{ resource: { db: "", collection: "" }, actions: [ "killCursors" ] }
],
roles: []
}
)
笔记-mongodb-用户及角色的更多相关文章
- MONGODB用户、角色和权限管理
最近遇到很多问MONGODB用户认证授权方面的问题,现在特记录下来,与大家共享. 一.概念理解 1.用户概念 Mongodb的用户是由 用户名+所属库名组成 例如: 登录mongo testdb ...
- MongoDB用户,角色管理 --- MongoDB基础用法(三)
用户管理 用户创建 MongoDB采用基于角色的访问控制(RBAC)来确定用户的访问. 授予用户一个或多个角色,确定用户对MongoDB资源的访问权限和用户可以执行哪些操作. 用户应该只有最小权限集才 ...
- PostgreSQL学习笔记(九) 用户、角色、权限管理
PostgreSQL是一个多用户数据库,可以为不同用户指定允许的权限. 角色PostgreSQL使用角色的概念管理数据库访问权限. 根据角色自身的设置不同,一个角色可以看做是一个数据库用户,或者一组数 ...
- mongodb之用户/认证/角色/权限管理
前言 用户权限管理很重要,只给需要的权限,防止应用系统漏洞导致脱库 认证和授权 Authentication 认证识别,解决我是谁 Authorization 操作授权,我能做什么 认证机制 MONG ...
- MongoDB 4.X 用户和角色权限管理总结
关于MongoDB的用户和角色权限的梳理一直不太清晰,仔细阅读了下官方文档,并对此做个总结. 默认情况下,MongoDB实例启动运行时是没有启用用户访问权限控制的,也就是说,在实例本机服务器上都可以随 ...
- MongoDB 学习笔记 ---创建用户
MongoDB安装好了之后,开始学习常用命令 首先,运行MongoDB, 记住,先不用带参数--auth /usr/local/mongodb/bin/mongod -dbpath=/usr/loca ...
- MongoDB 的用户和角色权限
副本和分片集群的安全设置参考这个:高级:https://files.cnblogs.com/files/sanduzxcvbnm/mongodb_advance.pdf 默认情况下,MongoDB实例 ...
- MongoDB用户配置
MongoDB学习笔记—权限管理 阅读目录 1.MongoDB权限介绍 2 MongoDB添加管理员账户 3 MongoDB开启用户权限验证 4 MongoDB的roles角色简单介绍 5 Mongo ...
- Linux实战教学笔记14:用户管理初级(下)
第十四节 用户管理初级(下) 标签(空格分隔): Linux实战教学笔记-陈思齐 ---更多资料点我查看 1,用户查询相关命令id,finger,users,w,who,last,lastlog,gr ...
随机推荐
- Java面向对象编程 -6.6
数组倒序 做法一:定义一个新的数组而后按照逆序的方式保存 public static void main(String[] args) { int arr[] = new int[] {1,2,3,4 ...
- Codeforces Round #621 (Div. 1 + Div. 2) D
题意: 给n,m,k,有n个点,m条线,距离都是一: 有k个特殊点,选择其中两个,进行相连,距离变为1,使得原本的最短路,经过相连改变小或者不变,最终结果是所有结果里面的最大距离. 思路: 选择i,j ...
- 问题:宿主机访问不到虚拟机内的docker容器
问题描述:初学Docker,主机Windows 10,虚拟机Cent OS7 运行了一个docker容器(Tomcat7),宿主机无法访问容器运行的服务. 问题原因:宿主机无法访问docker容器ip ...
- js将后台传入得时间格式化
//格式化时间函数Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月 ...
- jmeter plugin manager安装插件
https://jmeter-plugins.org/wiki/PluginsManager/ 以websocket 插件为例 先安装plugin manger 第二步:打开jmetre optio ...
- 排序算法之希尔排序的python实现
希尔排序(Shell’s Sort)是插入排序的一种,是直接插入排序算法的一种更高版本的改进版本. 希尔排序的工作原理 如下: (1)把记录按步长gap分组,对每组记录采用直接插入排序方法进行排序: ...
- django admin后台(数据库简单管理后台)
只需要简单的几行胆码就可以生成一个完整的管理后台 这个就是django魅力之一 创建超级用户 python manage.py createsuperuser ---- 之后会提示输入用慕名 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 K. Center
这题对于能加入最多边缘点的center点,这个点就是最优的center ,对于center点,总共是n^2的,顶多也就1e6,所以直接双重循环就行了, 然后map<pair,set >映射 ...
- pycharm中可以运行的程序,在命令行中运行提示模块不存在的问题
运行模块(包含main函数的模块),在模块开头添加以下代码,原因是pycharm运行python脚本时,会自动添加以下代码,将当前库加入到系统库目录集合中,在命令行中运行需要手动添加import os ...
- (转)基于快速排序的TOPK算法
基于快速排序的TOPK算法 转自:http://blog.csdn.net/fanzitao/article/details/7617223 思想: 类似于快速排序,首先选择一个划分元,如果这个划分元 ...