mongodb - 未授权在 mongo 4.2 中对 testdb.system.indexes src/mongo/db/commands/find_cmd.cpp 170 进行查询

标签 mongodb mongodb-query mongobee

我最近从 4.0.2 升级到了 mongo 4.2.0。在以前的版本中,用户可以访问 system.indexes,但升级后,用户无法访问 system.indexes 集合。用户已具有读写角色。此外,我尝试提供 dbAdmin,但仍然没有成功。

为 mongo 启用调试日志后,它显示未授权查询 testdb.system.indexes src/mongo/db/commands/find_cmd.cpp 170

有人遇到过这个问题吗?

下面是

的输出

{
    "role" : "read",
    "db" : "testdb",
    "isBuiltin" : true,
    "roles" : [ ],
    "inheritedRoles" : [ ],
    "privileges" : [
        {
            "resource" : {
                "db" : "testdb",
                "collection" : ""
            },
            "actions" : [
                "changeStream",
                "collStats",
                "dbHash",
                "dbStats",
                "find",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead"
            ]
        },
        {
            "resource" : {
                "db" : "testdb",
                "collection" : "system.js"
            },
            "actions" : [
                "changeStream",
                "collStats",
                "dbHash",
                "dbStats",
                "find",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead"
            ]
        }
    ],
    "inheritedPrivileges" : [
        {
            "resource" : {
                "db" : "testdb",
                "collection" : ""
            },
            "actions" : [
                "changeStream",
                "collStats",
                "dbHash",
                "dbStats",
                "find",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead"
            ]
        },
        {
            "resource" : {
                "db" : "testdb",
                "collection" : "system.js"
            },
            "actions" : [
                "changeStream",
                "collStats",
                "dbHash",
                "dbStats",
                "find",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead"
            ]
        }
    ]
}

最佳答案

我可以通过为 system.indexes 集合创建新角色并将此角色附加到用户来解决此问题。

db.createRole({role : "readWriteSystem", privileges: [{resource: { db: "testdb", collection: "system.indexes" }, actions: [ "changeStream", "collStats", "convertToCapped", "createCollection", "createIndex", "dbHash", "dbStats", "dropCollection", "dropIndex", "emptycapped", "find", "insert", "killCursors", "listCollections", "listIndexes", "planCacheRead", "remove", "renameCollectionSameDB", "update" ]}], roles:[]})
db.grantRolesToUser('testuser', ['readWriteSystem'])

奇怪的是,当您通过替换二进制文件升级 mongo 时会发生此问题。

我尝试安装一个 4.2 mongo 的新实例,然后将数据复制到它,它工作正常。但由于某些技术原因,我无法在生产中执行此操作。


尊敬的 Mongo 团队,

我尝试使用 https://docs.mongodb.com/manual/tutorial/upgrade-revision/#upgrade-replace-binaries 升级 mongo ,但遇到了上述问题。我认为 doc 缺少与 system.indexes 访问相关更改

相关的一些细节

关于mongodb - 未授权在 mongo 4.2 中对 testdb.system.indexes src/mongo/db/commands/find_cmd.cpp 170 进行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57721306/

相关文章:

python - MongoDb:$按 $in 排序

python - 如何在 python 2.7 中使用 pymongo 进行多处理池

node.js - Mongodb 聚合 $push 与 $cond 和 $each

javascript - 我想使用 mongodb 的 _id 检索在特定日期插入的值

c# - 使用 Mongodb C# 驱动程序按 ID 字段更新文档

java - 自动生成 MongoDB 的 Spring 数据查询 : X most recent entries

node.js - MongoDB:如何按字段分组并获取最新结果?

spring - MongoDB 有哪些可用的版本控制工具

mongodb - 连接后 mongobee 在 Atlas 集群上读取 DBname.system.indexes 失败