There are no users authenticated

HI Team,

after connecting to mongo , when im typing the command show dbsit is throwing the below error . Can you please help me. please find the below error and config file.

vagrant@m103:~$ cat /shared/mongod.conf
storage:
dbPath: /var/mongodb/db/
net:
bindIp: 192.168.103.100,localhost
port: 27000
security:
authorization: enabled

vagrant@m103:~$ mongo --host localhost:27000
MongoDB shell version v3.6.17
connecting to: mongodb://localhost:27000/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“10d348fd-5120-48aa-a2ce-9823056b7a0d”) }
MongoDB server version: 3.6.17
MongoDB Enterprise > show dbs
2020-02-02T07:10:21.422+0000 E QUERY [thread1] Error: listDatabases failed:{
“ok” : 0,
“errmsg” : “there are no users authenticated”,
“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

Just like it says, you need to login with some credentials to be able to run show dbs.

HI,

When im trying to create user , again it is giving the same error.

vagrant@m103:~ mongod --config /shared/mongod.conf --fork --logpath /shared/log/mongodb.log about to fork child process, waiting until server is ready for connections. forked process: 4017 child process started successfully, parent exiting vagrant@m103:~ mongo admin --host 192.168.103.100:27000 --eval ’
db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

MongoDB shell version v3.6.17
connecting to: mongodb://192.168.103.100:27000/admin?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“c64718a6-85c5-41c2-860e-e7c290b32edf”) }
MongoDB server version: 3.6.17
2020-02-02T09:03:30.708+0000 E QUERY [thread1] Error: couldn’t add user: there are no users authenticated :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell eval):2:1

The user has already been created. You need to login.

HI,

I have started the mongod with the new data directory , i think so user is not created yet .
this is the new empty database . im facing the issue for this lab only . in my earlier lab i was successfully created the user and i can see show dbs. in my default port mogod also i can see the show dbs .

The localhost exception, which allows to create the first user, is only possible via localhost. @prasantha_68763, since you connect with 192.168.103.100:27000 you are not connecting to localhost. So you get there are no users authenticated. But you cannot authenticate because there is no user created yet. You have to connect to 127.0.0.1:27000 to enable the localhost exception.

HI Steeve,

I have tried with local host also , still it is the same error .

vagrant@m103:~$ mongo admin --host 127.0.0.1:27000 --eval ’

 db.createUser({
  user: "m103-admin",
    pwd: "m103-pass",
    roles: [
     {role: "root", db: "admin"}
    ]
  })
'

MongoDB shell version v3.6.17
connecting to: mongodb://127.0.0.1:27000/admin?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“a7206b1e-3b2d-4ad4-a21e-d41fb680a10d”) }
MongoDB server version: 3.6.17
2020-02-03T00:27:27.889+0000 E QUERY [thread1] Error: couldn’t add user: there are no users authenticated :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell eval):2:1
vagrant@m103:~$

Then 007_jb was right

its a new empty database , i think user is not created yet . its a new data directory .but still let me try to login

You may restart mongod without

and then use db.getUsers() to find out.

HI Steeve ,

after authorization disbaled everything is working fine , but i believe as per our lab authorization should be enabled . please correct me if im wrong . please see the below out put before enable and after disable.

Before authorization enabled

vagrant@m103:~$ cat /shared/mongod.conf
storage:
dbPath: /var/mongodb/db/
net:
bindIp: 192.168.103.100,localhost
port: 27000
security:
authorization: enabled

vagrant@m103:~ mongod --config /shared/mongod.conf --fork --logpath /shared/log/mongodb.log about to fork child process, waiting until server is ready for connections. forked process: 5577 child process started successfully, parent exiting vagrant@m103:~ mongo --host localhost:27000
MongoDB shell version v3.6.17
connecting to: mongodb://localhost:27000/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“c1a1de27-b2f5-46de-9a0a-4b4205bfc660”) }
MongoDB server version: 3.6.17
MongoDB Enterprise > show dbs
2020-02-03T01:05:10.960+0000 E QUERY [thread1] Error: listDatabases failed:{
“ok” : 0,
“errmsg” : “there are no users authenticated”,
“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 > use admin
switched to db admin
MongoDB Enterprise > db.getUsers()
2020-02-03T01:05:48.552+0000 E QUERY [thread1] Error: there are no users authenticated :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.getUsers@src/mongo/shell/db.js:1686:1
@(shell):1:1
MongoDB Enterprise > exit

after authorization disbaled

vagrant@m103:~ cat /shared/mongod.conf storage: dbPath: /var/mongodb/db/ net: bindIp: 192.168.103.100,localhost port: 27000 #security: #authorization: enabled vagrant@m103:~ mongod --config /shared/mongod.conf --fork --logpath /shared/log/mongodb.log
about to fork child process, waiting until server is ready for connections.
forked process: 5621
child process started successfully, parent exiting
vagrant@m103:~$ mongo --host localhost:27000
MongoDB shell version v3.6.17
connecting to: mongodb://localhost:27000/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“9f84f6ec-5c50-443d-b1a3-191800ffbfc7”) }
MongoDB server version: 3.6.17
Server has startup warnings:
2020-02-03T01:11:50.291+0000 I STORAGE [initandlisten]
2020-02-03T01:11:50.291+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-02-03T01:11:50.291+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-02-03T01:11:51.106+0000 I CONTROL [initandlisten]
2020-02-03T01:11:51.106+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-02-03T01:11:51.106+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-02-03T01:11:51.106+0000 I CONTROL [initandlisten]
2020-02-03T01:11:51.106+0000 I CONTROL [initandlisten]
2020-02-03T01:11:51.107+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’.
2020-02-03T01:11:51.107+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2020-02-03T01:11:51.107+0000 I CONTROL [initandlisten]
2020-02-03T01:11:51.107+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2020-02-03T01:11:51.107+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2020-02-03T01:11:51.107+0000 I CONTROL [initandlisten]
MongoDB Enterprise > show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
MongoDB Enterprise > db.getUsers()

MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.getUsers()
[
{
“_id” : “admin.m103-admin”,
“userId” : UUID(“e211ea4c-2f0e-4b3c-9673-8659beb8aa92”),
“user” : “m103-admin”,
“db” : “admin”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
]
}
]
MongoDB Enterprise >

Yes, no, yes and yes.

The goals of the lab are

  1. have a user
  2. have authentication enable

Once you have both, you have to authenticate to do anything. We turn off authentication only to investigate if a user was created or not. You claimed that none was created but the server differ with

But you get the above when there is no user and you do not connect via localhost. By turning authentication off, you disable all security mechanisms. So you can investigate if there are users defined in the database, to create one if there is none, …

HI Steeve,

i have one more scenario , im sorry if im asking you more questions , this is about when authorization is enabled.

as per the lab it is empty and new database. but when im trying to create user i got use authenticated error . when im trying to get there were no users .

vagrant@m103:~$ mongo --host localhost:27000 --authenticationDatabase “admin” -u “m103-admin” -p
MongoDB shell version v3.6.17
Enter password:
connecting to: mongodb://localhost:27000/?authSource=admin&gssapiServiceName=mongodb
2020-02-03T00:42:04.192+0000 E QUERY [thread1] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:263:13

vagrant@m103:~$ mongo --host localhost:27000 --authenticationDatabase “admin” -u “m103-admin” -p
MongoDB shell version v3.6.17
Enter password:
connecting to: mongodb://localhost:27000/?authSource=admin&gssapiServiceName=mongodb
2020-02-03T00:42:04.192+0000 E QUERY [thread1] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:263:13

after authorization was disabled , when im trying create user it prompted user is already exists , im able to see the user .

so when the user was created in my empty database .

vagrant@m103:~$ mongo --host localhost:27000
MongoDB shell version v3.6.17
connecting to: mongodb://localhost:27000/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“6eb399c4-e0ac-463e-b654-b12ef0d76279”) }
MongoDB server version: 3.6.17
Server has startup warnings:
2020-02-03T00:45:54.483+0000 I STORAGE [initandlisten]
2020-02-03T00:45:54.483+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-02-03T00:45:54.483+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-02-03T00:45:55.315+0000 I CONTROL [initandlisten]
2020-02-03T00:45:55.315+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-02-03T00:45:55.315+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-02-03T00:45:55.315+0000 I CONTROL [initandlisten]
2020-02-03T00:45:55.315+0000 I CONTROL [initandlisten]
2020-02-03T00:45:55.315+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’.
2020-02-03T00:45:55.315+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2020-02-03T00:45:55.316+0000 I CONTROL [initandlisten]
2020-02-03T00:45:55.316+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2020-02-03T00:45:55.316+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2020-02-03T00:45:55.316+0000 I CONTROL [initandlisten]
MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.createUser({
… user: “m103-admin”,
… pwd: “m103-pass”,
… roles: [
… {role: “root”, db: “admin”}
… ]
… })
2020-02-03T01:01:13.764+0000 E QUERY [thread1] Error: couldn’t add user: User “m103-admin@admin” already exists :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1
MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.getUsers()
[
{
“_id” : “admin.m103-admin”,
“userId” : UUID(“e211ea4c-2f0e-4b3c-9673-8659beb8aa92”),
“user” : “m103-admin”,
“db” : “admin”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
]
}
]
MongoDB Enterprise >

HI @prasantha_68763,

Here, you might be entering incorrect password.

When you have the authorization enabled and the mongod instance is running, please use this connection string for connecting to your mongod instance.

 mongo --port 27000 -u m103-admin -p m103-pass

If you still get any error please share a screenshot of the output.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

2 Likes

If you get

then your database was not empty. And that you created the user at some point.

HI Ranjan,

its working fine

Closing this thread as the issue has been resolved.