简体   繁体   English

无法通过mongo的官方node.js驱动程序进行身份验证,只能通过mongo shell进行身份验证。 (MongoDB Cloud Manager副本部署)

[英]Can not authenticate via mongo's official node.js driver, only mongo shell. (MongoDB Cloud Manager replica deployment)

I am trying to authenticate to my replica set, which was deployed via Mongo Cloud Manager, but I can not figure out why it fails. 我正在尝试对通过Mongo Cloud Manager部署的副本集进行身份验证,但我不知道为什么它会失败。

Here are my users on database abcd : 这是我在数据库abcd上的用户:

abcdRepliaSet:PRIMARY> use abcd
switched to db abcd
show users
abcdRepliaSet:PRIMARY> show users
{
 "_id" : "abcd.abcdAppUser",
 "user" : "abcdAppUser",
 "db" : "abcd",
 "roles" : [
 {
 "role" : "readWrite",
 "db" : "abcd"
 }
 ]
}

and I can successfully connect to it via mongo shell: 我可以通过mongo shell成功连接到它:

mongo adbcd-mongo-mms.cloudapp.net:57002 -u adbcd AppUser -p hidden --authenticationDatabase adbcd

However, I can not using this simple code: 但是,我不能使用以下简单代码:

MongoClient.connect("mongodb://abcdAppUser:hidden@abcd-mongo-mms.cloudapp.net:57001,abcd-mongo-mms.cloudapp.net:57002,abcd-mongo-mms.cloudapp.net:57003/abcd?replicaSet=abcdRepliaSet&authSource=abcd&authMechanism=SCRAM-SHA-1",
 function(err, db) {
 if(err) throw err;
 else console.log(db);
});

I am also pretty sure my authMechanism is SCRAM-SHA-1 as I've added the user using mongoldb v. 3.0.7 and I've also confirmed it using: 我也很确定我的authMechanism是SCRAM-SHA-1,因为我已经使用mongoldb v。3.0.7添加了用户,并且还通过以下方式确认了它:

db.system.users.find({user:"abcdAppUser"}).pretty()

Here is mongod's log when I try to auth via the nodejs app: 当我尝试通过nodejs应用进行身份验证时,这是mongod的日志:

2015-12-22T13:31:33.823+0000 I ACCESS   [conn30286] SCRAM-SHA-1 authentication failed for abcdAppUser on abcd from client 10.0.0.10 ; AuthenticationFailed SCRAM-SHA-1 authentication failed, storedKey mismatch
2015-12-22T13:31:33.894+0000 I ACCESS   [conn30288] SCRAM-SHA-1 authentication failed for abcdAppUser on abcd from client 10.0.0.10 ; AuthenticationFailed SCRAM-SHA-1 authentication failed, storedKey mismatch
2015-12-22T13:31:34.051+0000 I ACCESS   [conn30287] SCRAM-SHA-1 authentication failed for abcdAppUser on abcd from client 10.0.0.10 ; AuthenticationFailed SCRAM-SHA-1 authentication failed, storedKey mismatch
2015-12-22T13:31:34.124+0000 I ACCESS   [conn30289] SCRAM-SHA-1 authentication failed for abcdAppUser on abcd from client 10.0.0.10 ; AuthenticationFailed SCRAM-SHA-1 authentication failed, storedKey mismatch
2015-12-22T13:31:34.206+0000 I ACCESS   [conn30290] SCRAM-SHA-1 authentication failed for abcdAppUser on abcd from client 10.0.0.10 ; AuthenticationFailed SCRAM-SHA-1 authentication failed, storedKey mismatch
2015-12-22T13:31:34.263+0000 I NETWORK  [conn30288] end connection 94.61.85.76:53102 (17 connections now open)
2015-12-22T13:31:34.264+0000 I NETWORK  [conn30286] end connection 94.61.85.76:61293 (17 connections now open)
2015-12-22T13:31:34.263+0000 I NETWORK  [conn30287] end connection 94.61.85.76:58194 (17 connections now open)
2015-12-22T13:31:34.263+0000 I NETWORK  [conn30289] end connection 94.61.85.76:58537 (17 connections now open)
2015-12-22T13:31:34.264+0000 I NETWORK  [conn30290] end connection 94.61.85.76:57720 (13 connections now open)
2015-12-22T13:31:37.185+0000 I NETWORK  [conn30281] end connection 10.0.0.8:34322 (12 connections now open)

I also made sure my node.js driver was compatible with SCRAM and it is. 我还确保我的node.js驱动程序与SCRAM兼容并且兼容。 At this point, I can't really understand why it fails... Any help would be most welcome! 在这一点上,我还真不明白为什么它会失败...非常欢迎任何帮助!

Thank you in advance. 先感谢您。

Regards, Pedro 佩德罗

Well, I'm not sure what I did wrong, but I've now upgraded the authSchema (pretty sure it was already on v.5, anyways), deleted the same user, and added it back again with the exact same password and roles. 好吧,我不确定我做错了什么,但是我现在已经升级了authSchema(很确定它已经在v.5上了),删除了相同的用户,然后使用完全相同的密码再次添加了它,并且角色。 It now works. 现在可以使用了。 Go figure... Also, this might have been due to https://docs.mongodb.org/v3.0/release-notes/3.0-scram/#upgrade-mongodb-cr-to-scram but I'm not sure as I've now idea what version was installed before (dev environment, so excuse me the lack of proper logging :P) 去图...此外,这可能是由于https://docs.mongodb.org/v3.0/release-notes/3.0-scram/#upgrade-mongodb-cr-to-scram引起的,但我不是确定,因为我现在已经知道以前安装了什么版本(开发环境,所以请原谅缺少适当的日志记录:P)

Anyway, thought this answer would eventually help someone in the future... 无论如何,以为这个答案最终会在将来对某人有所帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM