MongoDB-CR 身份验证失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29006887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:20:43  来源:igfitidea点击:

MongoDB-CR Authentication failed

mongodbspring-data-mongodb

提问by ashwini

I am getting following error while authenticating user : purchase_user@purchase failed. MongoDB-CR Authentication failed. Missing credentials in user document when I access webservice through browser.

验证用户时出现以下错误:purchase_user@purchase failed。MongoDB-CR 身份验证失败。当我通过浏览器访问网络服务时,用户文档中缺少凭据。

But I am able to authenticate purchase_user from mongo it returns 1 .

但我能够从 mongo 验证 purchase_user 它返回 1 。

回答by Vivex

go to mongoDB console and delete your current user & set authSchema version to 3 instead of 5 , follow these commands in mongo console -

转到 mongoDB 控制台并删除您当前的用户并将 authSchema 版本设置为 3 而不是 5 ,在 mongo 控制台中执行以下命令 -

mongo
use admin
db.system.users.remove({})    <== removing all users
db.system.version.remove({}) <== removing current version 
db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 })

Now restart the mongod and create new user then it should work fine.

现在重新启动 mongod 并创建新用户,然后它应该可以正常工作。

Note: use remove commands in test db only, if in production use update.

注意:仅在测试数据库中使用删除命令,如果在生产中使用更新。

Authentication information for Kubernetes Helm Chart

Kubernetes Helm Chart 的身份验证信息

If you delete the all users and authentication is enabled in the configuration (or --authparam which is set per default on the Kubernetes helm chart), it's not possible to access MongoDB any more. Its required to disable authentication, create a new user and then re-enable it.

如果您删除所有用户并在配置中启用身份验证(或--auth在 Kubernetes 掌舵图表上默认设置的参数),则无法再访问 MongoDB。它需要禁用身份验证,创建一个新用户,然后重新启用它。

On Kubernetes you need to edit the parameters and add --noauthas argument, since it's not the default there as on a classic installed MongoDB. Please see the CLI documentationfor more information about --noauthand the corresponding --auth.

在 Kubernetes 上,您需要编辑参数并将其添加--noauth为参数,因为它不像经典安装的 MongoDB 那样默认设置。请参阅CLI 文档了解更多信息--noauth和相应的--auth.

回答by Winston Lee

Had the same issue. What was happening to me was that when I use MongoDB 3 to create my user, it was using SCRAM-SHA-1 as it's authentication mechanism instead of MongoDB-CR. What I had to do was:

有同样的问题。发生在我身上的是,当我使用 MongoDB 3 创建我的用户时,它使用 SCRAM-SHA-1 作为身份验证机制而不是 MongoDB-CR。我必须做的是:

  1. List item
  2. Delete the created user.
  3. Modify the collection admin.system.version such that the authSchema's currentVersion is 3 instead of 5 (3 is using MongoDB-CR).
  4. Recreate your user.
  1. 项目清单
  2. 删除创建的用户。
  3. 修改集合 admin.system.version 使 authSchema 的 currentVersion 为 3 而不是 5(3 正在使用 MongoDB-CR)。
  4. 重新创建您的用户。

Should work without problems now.

现在应该可以正常工作了。

回答by acabra85

The step number 2. above is not detailed explicitly, I found this solution and worked for me.

上面的第 2 步没有明确详细说明,我找到了这个解决方案并对我来说有效。

var schema = db.system.version.findOne({"_id" : "authSchema"})
schema.currentVersion = 3
db.system.version.save(schema)

回答by Ahmed Haque

I think this is the answer you need:

我认为这是您需要的答案:

1) Start 3.0 without auth enabled. (Auth needs to be disabled otherwise you'll get the not authorized error).

1) 在未启用身份验证的情况下启动 3.0。(需要禁用身份验证,否则您将收到未授权错误)。

2) Run (after selecting "admin"use db):

2)运行(选择“admin”后使用db):

var schema = db.system.version.findOne({"_id" : "authSchema"})

schema.currentVersion = 3

db.system.version.save(schema)

var schema = db.system.version.findOne({"_id" : "authSchema"})

schema.currentVersion = 3

db.system.version.save(架构)

3) restart mongodb with auth enabled.

3)在启用身份验证的情况下重新启动mongodb。

4) Create a new admin user (the old one, the one you created before this workaround won't work).

4) 创建一个新的管理员用户(旧用户,您在此变通方法之前创建的用户将不起作用)。

Things should work now. This issue was driving me crazy as well.

现在应该可以了。这个问题也让我发疯。

Answer came from here: https://jira.mongodb.org/browse/SERVER-17459

答案来自这里:https: //jira.mongodb.org/browse/SERVER-17459

回答by Zubair Alam

Adding to above solution by Vivek & explanation taken from here

通过 Vivek 添加到上述解决方案并从此处获取解释

use admin
db.system.users.remove({})    <== removing all users
db.system.version.remove({}) <== removing current version 
db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 })
  • you only need to downgrade the schema to create MONGODB-CR users. Once they are there the old drivers will work regardless of the value of authSchemaVersion. However if you run authSchemaUpgrade to change from "3" to "5" the users will obviously be upgraded.
  • My comment regarding new users was that if you have existing SCRAM users and change the schema manually to "3" the user documents won't be consistent with the new schema. This is not enforced however but the SCRAM users will still work for any driver supporting SCRAM.
  • 您只需要降级架构即可创建 MONGODB-CR 用户。一旦它们在那里,无论 authSchemaVersion 的值如何,旧驱动程序都将工作。但是,如果您运行 authSchemaUpgrade 以将“3”更改为“5”,则用户显然会升级。
  • 我对新用户的评论是,如果您有现有的 SCRAM 用户并手动将架构更改为“3”,则用户文档将与新架构不一致。然而,这不是强制执行的,但是 SCRAM 用户仍然可以为任何支持 SCRAM 的驱动程序工作。

回答by sonal kumar sinha

Upgrade mongo-java-driver to 3.0.3 and use :-

将 mongo-java-driver 升级到 3.0.3 并使用:-

MongoCredential.createScramSha1Credential instead of MongoCredential.createMongoCRCredential

MongoCredential.createScramSha1Credential 而不是 MongoCredential.createMongoCRCredential

MongoCredential createMongoCRCredential = MongoCredential.createScramSha1Credential(mongoConfiguration.getDatabaseUserName(), mongoConfiguration.getAuthenticationDatabase(),mongoConfiguration.getDatabasePassword().toCharArray());

MongoCredential createMongoCRCredential = MongoCredential.createScramSha1Credential(mongoConfiguration.getDatabaseUserName(), mongoConfiguration.getAuthenticationDatabase(),mongoConfiguration.getDatabasePassword().toCharArray());

http://docs.mongodb.org/master/release-notes/3.0-scram/

http://docs.mongodb.org/master/release-notes/3.0-scram/

回答by Derrick Petzold

For me I was using a mongo 2 client trying to connect to a mongo 3 server. Upgrading the client fixed the issue.

对我来说,我正在使用 mongo 2 客户端尝试连接到 mongo 3 服务器。升级客户端解决了这个问题。

回答by technocrat

I was getting this error as well.

我也收到了这个错误。

Check your Spring Config file.. I had a constructor arg named "MONGODB-CR" which I swapped to "SCRAM-SHA-1" and it fixed my issue.

检查您的 Spring 配置文件。我有一个名为“MONGODB-CR”的构造函数 arg,我将其交换为“SCRAM-SHA-1”,它解决了我的问题。

tailing the mongodb log file helped me diagnose this.

拖尾 mongodb 日志文件帮助我诊断了这一点。

回答by rajivm1991

  • uninstall mongodb-clientspackages provided by Ubuntu
  • install mongodb-org-shellprovided by official MongoDB
  • 卸载Ubuntu 提供的mongodb-clients
  • 安装MongoDB官方提供的mongodb-org-shell

This solved the problem, because The unofficial mongodb package provided by Ubuntu is not maintained by MongoDB. You should always use the official MongoDB mongodb-org packages, which are kept up-to-date with the most recent major and minor MongoDB releases.

这样就解决了问题,因为 Ubuntu 提供的非官方 mongodb 包不是由 MongoDB 维护的。您应该始终使用官方的 MongoDB mongodb-org 包,这些包与最新的主要和次要 MongoDB 版本保持同步。

回答by Brad Hein

June 2018 I got this error after trying to connect to my Mongodb version 3.6 from an ancient client installed in /usr/bin. I installed the mongo DB in a separate folder outside of the OS standard directory, and so my installation was conflicting with the ancient version installed by the package manager.

2018 年 6 月,我尝试从 /usr/bin 中安装的古老客户端连接到我的 Mongodb 3.6 版后出现此错误。我将 mongo DB 安装在 OS 标准目录之外的单独文件夹中,因此我的安装与包管理器安装的旧版本冲突。