mongoDB:禁用用户 - auth,但请保持群集auth

发布于 2025-02-12 13:40:21 字数 1533 浏览 0 评论 0原文

我是我想禁用用户auth的MongoDB(5.0)副本集,但保持cluster auth on。

我所做的是:

  1. sudo systemctl stop mongod.service - 停止服务
  2. sudo vi /etc/systemd/systemd/system/mongod.service.service - 编辑该行:

execstart =/usr/bin/mongod -bind_ip localhost,<我的ip> - replset mongodb - auth - auth-clusterauthmode = keyfile -ekeyfile =/etc/mongodb/keyfile

to

execstart =/usr/usr/bin/bin/mongod - bind_ip localhost,< my ip> - replset mongodb -clusterauthmode = keyfile -ekeyfile =/etc/mongodb/keyfile

  1. sudo systemctl daemon-reload - 重新加载服务
  2. sudo systemctl start mongod.service start mongod.service - 启动服务

,然后在单独的计算机上,我去验证了我的验证更改。

$ pip3 install pymongo==3.12.1
$ python3

from pymongo import MongoClient
PORT=27017
ADDR=<my ip>
connection = ADDR + ":" + str(PORT)
client = MongoClient(connection, replicaset="mongodb")
client.admin.command("replSetGetStatus")

在其中报告pymongo.errors.operationfailure:命令用户Ininfo需要身份验证

有趣的是,当我重做步骤1-4时。但是更改2。execstart =/usr/bin/mongod -bind_ip localhost,&lt; my ip&gt; - replset mongodb。我能够无问题地重新运行上述实验。

因此,这是我的问题:

  1. 我认为标志clusterauthmode = keyfile -keyfile =/etc/mongodb/keyfile仅适用于群集认证的coplicas。是真的吗?
  2. 如果1。是正确的,那么为什么我不能使用这些字段从集群外部访问群集?
  3. 有没有更好的方法来验证AUTH?我在这里看到了其他一些使用Shell脚本但对我不起作用的帖子。

I am a pre-existing MongoDB (5.0) replica set that I would like to disable user auth for, but keep cluster auth on.

What I did was:

  1. sudo systemctl stop mongod.service - stop the service
  2. sudo vi /etc/systemd/system/mongod.service -
    edit the line:

ExecStart=/usr/bin/mongod --bind_ip localhost,<my ip> --replSet mongodb --auth --clusterAuthMode=keyFile --keyFile=/etc/mongodb/keyFile

to

ExecStart=/usr/bin/mongod --bind_ip localhost,<my ip> --replSet mongodb --clusterAuthMode=keyFile --keyFile=/etc/mongodb/keyFile

  1. sudo systemctl daemon-reload - reload service
  2. sudo systemctl start mongod.service - start service

Then on a separate machine, I went to verify my auth changes.

$ pip3 install pymongo==3.12.1
$ python3

from pymongo import MongoClient
PORT=27017
ADDR=<my ip>
connection = ADDR + ":" + str(PORT)
client = MongoClient(connection, replicaset="mongodb")
client.admin.command("replSetGetStatus")

which reports pymongo.errors.OperationFailure: command usersInfo requires authentication.

Interestingly enough when I redo steps 1-4. but change 2. to ExecStart=/usr/bin/mongod --bind_ip localhost,<my ip> --replSet mongodb. I am able to re-run the above experiment without issue.

So here are my questions:

  1. I thought the flags clusterAuthMode=keyFile --keyFile=/etc/mongodb/keyFile were only for replicas in the cluster authenticating others. Is that true?
  2. If 1. is correct then why can I not access my cluster from outside the cluster with these fields?
  3. Is there a better way to verify auth? I saw some other posts on here that used a shell script but did not work for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢华的一滴泪 2025-02-19 13:40:21

正如@wernfried domscheit所说:

As @Wernfried Domscheit commented:

So essentially you cannot have cluster auth without user auth

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文