Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb用户可以在没有权限的情况下使用数据库_Mongodb - Fatal编程技术网

Mongodb用户可以在没有权限的情况下使用数据库

Mongodb用户可以在没有权限的情况下使用数据库,mongodb,Mongodb,我有两个数据库(临时数据库和生产数据库)。另外,我有2个用户(staging_用户和production_用户)。但是用户可以在登录后使用生产数据库 mongo --authenticationDatabase staging -u staging_user -p *********** > use production switched to db production >db.getName() production > show collections accoun

我有两个数据库(临时数据库和生产数据库)。另外,我有2个用户(staging_用户和production_用户)。但是用户可以在登录后使用生产数据库

mongo --authenticationDatabase staging -u staging_user -p ***********

> use production
switched to db production

>db.getName()
production

> show collections
accounts

> db.runCommand({connectionStatus : 1})
{
    "authInfo" : {
        "authenticatedUsers" : [
            {
                "user" : "staging_user",
                "db" : "staging"
            }
        ],
        "authenticatedUserRoles" : [
            {
                "role" : "readWrite",
                "db" : "staging"
            }
        ]
    },
    "ok" : 1
}
getSiblingDb结果:

{
    "role" : "readWrite",
    "db" : "gepick_staging",
    "isBuiltin" : true,
    "roles" : [ ],
    "inheritedRoles" : [ ],
    "privileges" : [
        {
            "resource" : {
                "db" : "staging",
                "collection" : ""
            },
            "actions" : [
                "changeStream",
                "collStats",
                "convertToCapped",
                "createCollection",
                "createIndex",
                "dbHash",
                "dbStats",
                "dropCollection",
                "dropIndex",
                "emptycapped",
                "find",
                "insert",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead",
                "remove",
                "renameCollectionSameDB",
                "update"
            ]
        },
        {
            "resource" : {
                "db" : "staging",
                "collection" : "system.indexes"
            },
            "actions" : [
                "changeStream",
                "collStats",
                "dbHash",
                "dbStats",
                "find",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead"
            ]
        },
        {
            "resource" : {
                "db" : "staging",
                "collection" : "system.js"
            },
            "actions" : [
                "changeStream",
                "collStats",
                "convertToCapped",
                "createCollection",
                "createIndex",
                "dbHash",
                "dbStats",
                "dropCollection",
                "dropIndex",
                "emptycapped",
                "find",
                "insert",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead",
                "remove",
                "renameCollectionSameDB",
                "update"
            ]
        },
        {
            "resource" : {
                "db" : "staging",
                "collection" : "system.namespaces"
            },
            "actions" : [
                "changeStream",
                "collStats",
                "dbHash",
                "dbStats",
                "find",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead"
            ]
        }
    ],
    "inheritedPrivileges" : [
        {
            "resource" : {
                "db" : "staging",
                "collection" : ""
            },
            "actions" : [
                "changeStream",
                "collStats",
                "convertToCapped",
                "createCollection",
                "createIndex",
                "dbHash",
                "dbStats",
                "dropCollection",
                "dropIndex",
                "emptycapped",
                "find",
                "insert",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead",
                "remove",
                "renameCollectionSameDB",
                "update"
            ]
        },
        {
            "resource" : {
                "db" : "staging",
                "collection" : "system.indexes"
            },
            "actions" : [
                "changeStream",
                "collStats",
                "dbHash",
                "dbStats",
                "find",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead"
            ]
        },
        {
            "resource" : {
                "db" : "staging",
                "collection" : "system.js"
            },
            "actions" : [
                "changeStream",
                "collStats",
                "convertToCapped",
                "createCollection",
                "createIndex",
                "dbHash",
                "dbStats",
                "dropCollection",
                "dropIndex",
                "emptycapped",
                "find",
                "insert",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead",
                "remove",
                "renameCollectionSameDB",
                "update"
            ]
        },
        {
            "resource" : {
                "db" : "staging",
                "collection" : "system.namespaces"
            },
            "actions" : [
                "changeStream",
                "collStats",
                "dbHash",
                "dbStats",
                "find",
                "killCursors",
                "listCollections",
                "listIndexes",
                "planCacheRead"
            ]
        }
    ]
}

如何不允许登台用户使用生产数据库?

确保您已在配置中启用了auth,并重新启动mongodb

有关更多详细信息,请点击以下链接:

您是否授予此角色任何其他特权?检查
db.getSiblingDB(“staging”).getRole(“readWrite”,{showBuiltinRoles:true,showPrivileges:true})
确保设置为enabled@WernfriedDomscheit更新了由@Joe suggestion固定的getSiblingDB resultfixed帖子。数据库授权被禁用