mongod默认启动不加任何参数时,是没有身份认证的,任何人都可以登录上进行任何操作

启动时添加--auth可以使用身份验证模式

使用mongod -f mongod.conf配置文件启动时,配置文件的security.authorization为enabled,也是使用身份认证模式

同时使用配置文件若想强制不使用身份验证则添加--noauth参数

若首次启动即添加身份认证,因为mongodb的身份只能使用客户端连接后

use admin

再在admin下使用

db.createUser(canshu)

创建对应用户

所以,可能会令一个用户也添加不了。

其实这是多虑的,mongodb添加了Localhost Exception

官方文档:

The localhost exception allows you to enable authorization before creating the first user in the system. When active, the localhost exception allows connections from the localhost interface to create the first user on theadmin database. The exception applies only when there are no users created in the MongoDB instance.

Changed in version 3.0: The localhost exception changed so that these connections only have access to create the first user on the admin database. In previous versions, connections that gained access using the localhost exception had unrestricted access to the MongoDB instance.

If you use the localhost exception when deploying a new MongoDB system, the first user you create must be in the admin database with privileges to create other users, such as a user with the userAdmin oruserAdminAnyDatabase role. See Enable Client Access Control and Create a User Administrator for more information.

即允许使用localhost(127.0.0.1)的客户端连接

在系统中没有用户时

第一次连接进来产生例外,允许创建一个用户

(类似于mysql安装时设置root的密码)

创建带权限用户步骤:

1、use admin;

只有在admin上才能创建高权限账户,即用于所有数据库管理权限的用户。

2、db.createUser({user:"root",pwd:"root",roles:[{role:"root",db:"admin"}]})

db.createUser({user:"admin",pwd:"admin",roles:[{role:"userAdminAnyDatabase",db:"admin"},{role:"dbAdminAnyDatabase",db:"admin"},{role:"readWriteAnyDatabase",db:"admin"}]})

参数为一个js对象,参考上面。

常用的roles

 root:即root权限,可以管理所有的数据库及用户,拥有所有角色的所有权限。只能创建在admin上

 userAdminAnyDatabase:拥有所有数据库的用户管理权限

 dbAdminAnyDatabase:拥有所有数据库的数据库管理权限

 readWriteAnyDatabase:拥有所有数据库的读写权限

 这些角色都只能创建在admin数据库上。

 去掉AnyDatabase后可以创建在普通数据库上。

一旦执行过一次createUser,Localhost Exception立即消失,只能通过验证后才能进行创建操作

 db.auth("root","root")。

3、修改一个用户

 db.updateUser("admin",{roles:[{role:"userAdminAnyDatabase",db:"admin"},{role:"dbAdminAnyDatabase",db:"admin"},{role:"readWriteAnyDatabase",db:"admin"}]})

4、删除一个用户

 db.dropUser("admin")

同时,若想开启http接口访问功能,则不能使用身份验证模式

虽然在使用验证模式时,访问http接口会弹出输入用户名和密码的窗口(http默认支持身份认证),但是其实mongodb不支持这种身份验证。

官方说明:

While MongoDB Enterprise does support Kerberos authentication, Kerberos is not supported in HTTP status interface in any version of MongoDB.

Changed in version 3.0.

Neither the HTTP status interface nor the REST API support the SCRAM-SHA-1 challenge-response user authentication mechanism introduced in version 3.0.

SCRAM-SHA-1 is the default mechanism for MongoDB versions beginning with the 3.0 series. However, if you are upgrading a MongoDB 2.6 instances that already have users credentials, MongoDB will continue to use MONGODB-CR for challenge-response authentication until you upgrade the authentication schema. Even when using the MONGODB-CR authentication mechanism, clients and drivers that support MongoDB 3.0 features (see Driver Compatibility Changes) will use the SCRAM communication protocol.

由此可见,不支持,只能关闭身份认证再访问了。

http://docs.mongodb.org/manual/core/authentication/#authentication-scram-sha-1

注意:

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

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

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

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

MongoDb安全配置:简单的身份认证的更多相关文章

  1. RESTful Api 身份认证安全性设计

    REST是一种软件架构风格.RESTful Api 是基于 HTTP 协议的 Api,是无状态传输.它的核心是将所有的 Api 都理解为一个网络资源.将所有的客户端和服务器的状态转移(动作)封装到 H ...

  2. Nancy 学习-身份认证(Forms authentication) 继续跨平台

    开源 示例代码:https://github.com/linezero/NancyDemo 上篇讲解Nancy的Basic Authentication,现在来学习Nancy 的Forms身份认证. ...

  3. RESTful Api 身份认证中的安全性设计探讨

    REST 是一种软件架构风格.RESTful Api 是基于 HTTP 协议的 Api,是无状态传输.它的核心是将所有的 Api 都理解为一个网络资源.将所有的客户端和服务器的状态转移(动作)封装到 ...

  4. Shiro之身份认证、与spring集成(入门级)

    目录 1. Shro的概念 2. Shiro的简单身份认证实现 3. Shiro与spring对身份认证的实现 前言: Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在 JavaSE 环境 ...

  5. SpringBoot学习:整合shiro(身份认证和权限认证),使用EhCache缓存

    项目下载地址:http://download.csdn.NET/detail/aqsunkai/9805821 (一)在pom.xml中添加依赖: <properties> <shi ...

  6. Shiro身份认证---转

    目录 1. Shro的概念 2. Shiro的简单身份认证实现 3. Shiro与spring对身份认证的实现 前言: Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在 JavaSE 环境 ...

  7. 【Shiro】Apache Shiro架构之身份认证(Authentication)

    Shiro系列文章: [Shiro]Apache Shiro架构之权限认证(Authorization) [Shiro]Apache Shiro架构之集成web [Shiro]Apache Shiro ...

  8. django身份认证、权限认证、频率校验使用及源码分析

    一. 身份认证源码分析 1.1 APIView源码的分析 APIView源码之前分析过https://www.cnblogs.com/maoruqiang/p/11135335.html,里面主要将r ...

  9. SharePoint 2013 配置基于表单的身份认证

    前 言 这里简单介绍一下为SharePoint 2013 配置基于表单的身份认证,简单的说,就是用Net提供的工具创建数据库,然后配置SharePoint 管理中心.STS服务.Web应用程序的三处w ...

随机推荐

  1. 深入浅出 Java Concurrency (14): 锁机制 part 9 读写锁 (ReentrantReadWriteLock) (2)

      这一节主要是谈谈读写锁的实现. 上一节中提到,ReadWriteLock看起来有两个锁:readLock/writeLock.如果真的是两个锁的话,它们之间又是如何相互影响的呢? 事实上在Reen ...

  2. php对业务平台接口调用的封装格式

    1.封装类示例:E:\html\pim\php_mcloud_cas\util\UmcPlatform.class.php <?php class Util_UmcPlatform{ const ...

  3. Configuring Transitive IPMP on Solaris 11

    http://www.tokiwinter.com/configuring-transitive-ipmp-on-solaris-11/ We all know the pain of configu ...

  4. Python实践练习:strip()的正则表达式版本

    题目: 写一个函数,它接受一个字符串,做的事情和 strip()字符串方法一样.如果只传入了要去除的字符串,没有其他参数,那么就从该字符串首尾去除空白字符.否则,函数第二个参数指定的字符将从该字符串中 ...

  5. ARM汇编 均值滤波实验

    实验要求是排序后去掉最大值最小值,然后把剩下的求平均数. 排序可以用之前的冒泡排序,关键的问题是求平均数.因为ARM没有除法,应该怎么求平均数呢? 最简单的方法就是减法了,用被除数一直减除数,看减了多 ...

  6. ubuntu 桥接备忘

    apt install birdge-utils       用于桥接网卡的工具,如命令brctl root@ubuntu:/etc/network# vim interfaces auto br0 ...

  7. springMVC环境搭建(1)

    工作一年以来,写的都是.net,最近比较闲,想把之前学过的java相关的东西捡起来,也学点新的东西.以前做过SSH架构,一直好奇spring mvc是怎么样的,所以今天试试看. 总体的代码结构 手动输 ...

  8. Linux实战教学笔记30:Nginx反向代理与负载均衡应用实践

    1.1 集群简介 简单地说,集群就是指一组(若干个)相互独立的计算机,利用高速通信网络组成的一个较大的计算机服务系统,每个集群节点(即集群中的每台计算机)都是运行各自服务的独立服务器.这些服务器之间可 ...

  9. ios加载本地html

    UIWebView加载工程本地网页与本地图片 - (void)viewDidLoad { [super viewDidLoad]; NSString *filePath = [[NSBundle ma ...

  10. 在tomcat中的conf文件夹下找server.conf 配置如下代码,可省略项目名路径访问 如 localhost:8080 即可访问到项目

    <Context path="" docBase="C:\Workspaces\Projects\SLSaleSystem_dw\WebRoot" rel ...