笔记-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

有两种方式:

  1. 命令:mongod 命令带上—auth参数
  2. 配置文件:在配置文件中添加auth=true #具体可能会因为版本不同有所差别

2.      ROLE

mongodb内置了一些角色,也可以由用户创建,跟其它数据库差不多;

2.1.    Database User Roles

Every database includes the following roles:

最常用的两种角色。

Role

Short Description

read

Provides the ability to read data on all non-system collections and on the following system collections: system.indexessystem.js, and system.namespacescollections.

For the specific privileges granted by the role, see read.

readWrite

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

dbAdmin

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.

dbOwner

Provides the ability to perform any administrative action on the database. This role combines the privileges granted by the readWritedbAdmin and userAdmin 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 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

readAnyDatabase

readWriteAnyDatabase

userAdminAnyDatabase

dbAdminAnyDatabase

还有一个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-用户及角色的更多相关文章

  1. MONGODB用户、角色和权限管理

      最近遇到很多问MONGODB用户认证授权方面的问题,现在特记录下来,与大家共享. 一.概念理解 1.用户概念 Mongodb的用户是由 用户名+所属库名组成 例如: 登录mongo  testdb ...

  2. MongoDB用户,角色管理 --- MongoDB基础用法(三)

    用户管理 用户创建 MongoDB采用基于角色的访问控制(RBAC)来确定用户的访问. 授予用户一个或多个角色,确定用户对MongoDB资源的访问权限和用户可以执行哪些操作. 用户应该只有最小权限集才 ...

  3. PostgreSQL学习笔记(九) 用户、角色、权限管理

    PostgreSQL是一个多用户数据库,可以为不同用户指定允许的权限. 角色PostgreSQL使用角色的概念管理数据库访问权限. 根据角色自身的设置不同,一个角色可以看做是一个数据库用户,或者一组数 ...

  4. mongodb之用户/认证/角色/权限管理

    前言 用户权限管理很重要,只给需要的权限,防止应用系统漏洞导致脱库 认证和授权 Authentication 认证识别,解决我是谁 Authorization 操作授权,我能做什么 认证机制 MONG ...

  5. MongoDB 4.X 用户和角色权限管理总结

    关于MongoDB的用户和角色权限的梳理一直不太清晰,仔细阅读了下官方文档,并对此做个总结. 默认情况下,MongoDB实例启动运行时是没有启用用户访问权限控制的,也就是说,在实例本机服务器上都可以随 ...

  6. MongoDB 学习笔记 ---创建用户

    MongoDB安装好了之后,开始学习常用命令 首先,运行MongoDB, 记住,先不用带参数--auth /usr/local/mongodb/bin/mongod -dbpath=/usr/loca ...

  7. MongoDB 的用户和角色权限

    副本和分片集群的安全设置参考这个:高级:https://files.cnblogs.com/files/sanduzxcvbnm/mongodb_advance.pdf 默认情况下,MongoDB实例 ...

  8. MongoDB用户配置

    MongoDB学习笔记—权限管理 阅读目录 1.MongoDB权限介绍 2 MongoDB添加管理员账户 3 MongoDB开启用户权限验证 4 MongoDB的roles角色简单介绍 5 Mongo ...

  9. Linux实战教学笔记14:用户管理初级(下)

    第十四节 用户管理初级(下) 标签(空格分隔): Linux实战教学笔记-陈思齐 ---更多资料点我查看 1,用户查询相关命令id,finger,users,w,who,last,lastlog,gr ...

随机推荐

  1. vue项目依赖的安装

    npm install element-ui --save npm install vuex  --save npm install axios  --save npm install moment ...

  2. 转载UUID.randomUUID()

    UUID.randomUUID()生成唯一识别码 原创 清晨-阳光zx 最后发布于2019-04-11 20:54:40 阅读数 3039 收藏 发布于2019-04-11 20:54:40 分类专栏 ...

  3. oracle创建、删除索引等操作

    1.创建索引 create index 索引名 on 表名(列名); 2.删除索引 drop index 索引名; 3.创建组合索引 create index 索引名 on 表名(列名1,,列名2); ...

  4. Atcoder Beginner Contest 147D(按位处理)

    把每个数字每一位上二进制数字取出,求答案时直接用N个数里这一位是0的个数乘上这一位是1的个数然后乘上二的这一位次方,注意所有可能溢出的地方都要对mod取模. #define HAVE_STRUCT_T ...

  5. 编译原理--05 用C++手撕PL/0

    前言 目录 01 文法和语言.词法分析复习 02 自顶向下.自底向上的LR分析复习 03 语法制导翻译和中间代码生成复习 04 符号表.运行时存储组织和代码优化复习 05 用C++手撕PL/0 在之前 ...

  6. 原生JS实现旋转木马轮播图特效

    大概是这个样子: 首先来简单布局一下(emm...随便弄一下吧,反正主要是用js来整的) <!DOCTYPE html> <html lang="en"> ...

  7. linux 命令——screen

    最近遇到一个东西aria2,这个玩意,这个是啥呢?Aria2是一个轻量级Linux下载软件,支持HTTP/HTTPS, FTP, SFTP, BitTorrent和磁力链接(官方版),公司系统插件配套 ...

  8. js正则验证表达式验证

    /* 合法uri */ export function validateURL(textval) {  const urlregex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\ ...

  9. Draw.io--自认为最好用的流程图绘制软件

    draw.io 是一个强大简洁的在线的绘图网站,支持流程图,UML图,架构图,原型图等图标.支持Github,Google Drive, One drive等网盘同步,并且永久免费.如果觉得使用Web ...

  10. 【译】高级T-SQL进阶系列 (三)【中篇】:理解公共表表达式(CTEs)

    [译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文链接:传送门. 一个简单的CTE例子 如前所述,CTE‘s提供给你了一个方法来更容易的书写复杂的代码以提高其可读性.假设你有列表 ...