Authentication Error

Greetings to all.

I’m getting this error.

Capture

I even tried authenticating with this value using db.auth(‘m103-admin’,‘m103-pass’), still getting the same error.Please help.

Thanks in advance.

1 Like

Similarly, I’ve created the m103-admin user, but it is unable to perform any action. Here’s the shell:

MongoDB Enterprise > db.runCommand({connectionStatus:1})
{
“authInfo” : {
“authenticatedUsers” : [
{
“user” : “m103-admin”,
“db” : “admin”
}
],
“authenticatedUserRoles” : [
{
“role” : “dbAdmin”,
“db” : “admin”
},
{
“role” : “readWrite”,
“db” : “admin”
}
]
},
“ok” : 1
}
MongoDB Enterprise > show dbs
2019-09-24T22:45:20.127+0000 E QUERY [thread1] Error: listDatabases failed:{
“ok” : 0,
“errmsg” : “not authorized on admin to execute command { listDatabases: 1.0, lsid: { id: UUID(“6d5361b3-bde6-4cdf-b1e0-51fe1dc47558”) }, $db: “admin” }”,
“code” : 13,
“codeName” : “Unauthorized”
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:67:1
shellHelper.show@src/mongo/shell/utils.js:860:19
shellHelper@src/mongo/shell/utils.js:750:15
@(shellhelp2):1:1
MongoDB Enterprise >

@Arsh_Deep_Singh_26375 ensure that you’re using the admin database:

use admin
db.createUser(…)

@Michael_Williams_92594 it looks like you need to authorise with the admin user. Run this:

use admin
db.auth(“m103-admin”, “m103-pass”)

1 Like

Hi @Arsh_Deep_Singh_26375 and @Michael_Williams_92594 ,

If you have already created the user, please confirm if you authenticated the user in admin database as below:

MongoDB Enterprise >  use admin
MongoDB Enterprise > db.auth("m103-admin","m103-pass")

This should return 1.
If not, please feel free to get back to us.

Thanks,
Muskan
Curriculum Support Engineer

I ran the above and it does return a “1”.

@Michael_Williams_92594 according to your connection status this dbAdmin user has admin rights on the admin db alone, hence it’s not authorised to show dbs of other databases.

The role for m103-admin should have been the root user as instructed in the lab. Try not to alter the roles mentioned in this lab.

For your specific case, suggest you do the following to sync everything up:

  1. Log in as your current m103-admin user and find out who your actual root user is:
    use admin
    db.getUsers()
  2. From within the same mongo shell switch to the root user:
    db.auth("<root_user>", "<root_password>")
  3. Promote m103-admin to root user:
    db.updateUser("m103-admin", {roles: [{ db: "admin", role: "root" }]})
  4. From within the same mongo shell switch to the m103-admin root user:
    db.auth("m103-admin", "m103-pass")
  5. Delete the old root user:
    db.removeUser("<old_root_user>")

From here on, you’re good to go.

2 Likes

Thank you for the help. I performed step 1 above and there does not appear to be a root user.
MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.getUsers()
[
{
“_id” : “admin.m103-admin”,
“userId” : UUID(“778c268c-acd6-46fc-a937-937cfe56e1c6”),
“user” : “m103-admin”,
“db” : “admin”,
“roles” : [
{
“role” : “readWrite”,
“db” : “admin”
},
{
“role” : “dbAdmin”,
“db” : “admin”
}
]
}
]

I will start over and recreate the m103-admin user and update the results here.

OK, that worked. Thank you very much.

@Michael_Williams_92594 curious to know what you did because you said there was no root user?

I had created the user but somehow its permissions were wrong, it needed to be root, and I wasn’t correctly authenticating to it when connecting.

1 Like