Get the App
SLTechnology News&Howtos  ›  Database  › 

How to solve the problem of No permission of db.serverStatus () naming Executive Times in mongodb

Shulou Source: shulou.com Published: 2022-05-31 20:42:46 10月29日 Update

This article mainly introduces how to solve the problem of db.serverStatus () naming Executive Times without authority in mongodb, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

1. Problem description

An error message of "" errmsg ":" not authorized on admin to execute command {serverStatus: 1. 0} "is given when the db.serverStatus () command is executed.

By querying the permissions of admin is already the permissions of dbOwner, and then successively granted permissions such as dbadmin, the problem still exists.

Finally, the permission list of Mongodb is found, and the problem can be solved by giving root permissions, and then several other permissions are not allowed, which shows that db.serverStatus is a server-level command and requires the highest permissions of mongodb to execute.

The following is a simple process of dealing with the problem, which is shared with you for reference.

2. Error content

[root@ggnode2 ~] # mongo 10.130.170.112:27017/admin-u admin-pMongoDB shell version: 3.2.8Enter password:connecting to: 10.130.170.112:27017/adminMongoDB Enterprise > MongoDB Enterprise > db.serverStatus () {"ok": 0, "errmsg": "not authorized on admin to execute command {serverStatus: 1.0}", "code": 13}

3. Error analysis

As you can see from the error, admin does not have permission to execute the db.serverStatus () command.

MongoDB Enterprise > use admin

Switched to db admin

MongoDB Enterprise > show collections

System.users

System.version

MongoDB Enterprise > db.system.users.find ()

{"_ id": "admin.admin", "user": "admin", "db": "admin", "credentials": {"SCRAM-SHA-1": {"iterationCount": 10000, "salt": "BEN7SONYkewFMx3f67FNQw==", "storedKey": "HjlvcjSpXpSKetcUbJyj350Xgjk=", "serverKey": "k2WEf2cHGgg9n3tyEMJyuKaRt3U ="}, "roles": [{"role": "dbOwner" "db": "admin"}]}

According to the query results, admin has dbOwner role permissions, while root role permissions are required to execute the db.serverStatus () command.

4. Problem handling:

After querying the table system.users table, we can see that the admin user needs to be assigned the root role to execute the db.serverStatus () command.

The action commands that grant permissions to the role are as follows:

# Grant role permissions MongoDB Enterprise > db.grantRolesToUser ("admin", [{role: "root", db: "admin"}]) MongoDB Enterprise > # cancel role permissions MongoDB Enterprise > db.revokeRolesFromUser ("admin", [{role: "root", db: "admin"}] MongoDB Enterprise >

5. Problem solving

After giving permission to the root role, execute the db.serverStatus () command to OK. The result is as follows:

MongoDB Enterprise > db.serverStatus () MongoDB shell version: 3.2.8connecting to: 10.130.170.112:27017/admin {"host": "ggnode2", "advisoryHostFQDNs": [], "version": "3.2.8", "process": "mongod", "pid": NumberLong (23155), "uptime": 1470624, "uptimeMillis": NumberLong (1470624043), "uptimeEstimate": 1415522 LocalTime: ISODate ("2016-11-07T04:13:33.328Z"), "asserts": {"regular": 0, "warning": 0, "msg": 0, "user": 62, "rollovers": 0}, "connections": {"current": 1, "available": 818, "totalCreated": NumberLong (6025)} "extra_info": {"note": "fields vary by platform", "heap_usage_bytes": 60437840, "page_faults": 28}, "globalLock": {"totalTime": NumberLong ("1470624234000"), "currentQueue": {"total": 0, "readers": 0, "writers": 0} "activeClients": {"total": 8, "readers": 0, "writers": 0}, "locks": {… ... "storage": {"freelist": {"bucketExhausted": NumberLong (0), "requests": NumberLong (0), "scanned": NumberLong (0)}, "ttl": {"deletedDocuments": NumberLong (0), "passes": NumberLong (24508)} "ok": 1} Thank you for reading this article carefully. I hope the article "how to solve the problem of unauthorized access to db.serverStatus () naming Executive Times in mongodb" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Permissions questions commands roles articles errors queries Times content results reference processing highest value interest at the same time more friends servers query tables Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS MySQL vpn Xiaomi