Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Client Access Control: SCRAM-SHA-1 authentication failed, storedKey mismatch

Tags:

mongodb

I'm trying to activate user authorization on my local Mongo installation, but authentication keeps on failing. What can be the problem? Am I missing something?

I followed the steps outlined in "Installing on Windows" and "Enable Client Access Control":

1) Added a user

>mongo admin
MongoDB shell version: 3.2.7
connecting to: admin
> db.createUser({createUser:"admin",pwd:"admin",roles:["root"]})
Successfully added user: { "createUser" : "admin", "roles" : [ "root" ] }
>

2) Enabled Client Access Control in mongod.cfg:

systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db
security:
    authorization: enabled

3) Restarted mongod

4) Now logging in with the "right" credentials (the ones I just specified) always fails:

>mongo admin -u admin -p admin
MongoDB shell version: 3.2.7
connecting to: admin
2016-06-14T12:25:02.376+0200 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20
@(auth):6:1
@(auth):1:2

exception: login failed

The error in the logfile is: SCRAM-SHA-1 authentication failed for admin on admin from client 127.0.0.1 ; AuthenticationFailed: SCRAM-SHA-1 authentication failed, storedKey mismatch

Platform is Windows 10 x64, if that matters. MongoDB 64-bit 3.2.7 with OpenSSL.

like image 701
rustyx Avatar asked Jun 14 '16 11:06

rustyx


People also ask

What is scram in MongoDB?

Salted Challenge Response Authentication Mechanism (SCRAM) is the default authentication mechanism for MongoDB. When a user authenticates themselves, MongoDB uses SCRAM to verify the supplied user credentials against the user's name , password and authentication database.


2 Answers

As per the documentation, the object passed to createUser should contain a user property (along with the others):

db.createUser({ user : "admin", pwd : "admin", roles : ["root"] })
                ^^^^ not `createUser`
like image 94
robertklep Avatar answered Sep 26 '22 00:09

robertklep


Probably you're trying to recreate the database with new login and/or password. So, you need to exclude the "/db" folder. The database path's in the docker-compose.yml file. e.g.: "volumes: - ./db:/data/db".

like image 31
Carlos Brito Avatar answered Sep 22 '22 00:09

Carlos Brito