Authentication on MacBook (M1) installation does not work as expected

Hi all,

I have a question concerning installing mongodb on my MacBook (M1) with security enabled.

In chapter 1, the instructor says that when entering the mongo shell for the first time, one can make use of the localhost exception. This exception makes sure one does not have to provide any credentials at all when singing in for the first time. But as soon as one is logged into the system, one has create an user on the admin database with the root role:

admin> db.createUser(
... {
..... user : "admin",
..... pwd : "admin",
..... roles : ["root"]
..... }
... );
{ ok: 1 }

Although this works perfectly fine, I expected to not being able to authenticate without providing any credentials when trying to access mongodb. Instead, mongosh allows me to authenticate without any credentials.

Is there anything wrong with my configuration or is this expected behaviour?

# Docs available on
# https://www.mongodb.com/docs/manual/reference/configuration-options/#configuration-file
systemLog:
  path: mongo_university/m103/chapter1/log/mongo.log
  destination: file
processManagement:
  fork: true
  pidFilePath: mongo_university/m103/chapter1/pid
net:
  bindIp: 127.0.0.1
  port: 27017
security:
  # when you start your instance, you have to create a database admin user. As soon as the user is created,
  # the localhost exception will close and you have to authenticate with the database administrator
  authorization: enabled
storage:
  dbPath: mongo_university/m103/chapter1/data/db

Thank you in advance!

Marco

Is acces control enabled,?
Did you bounce mongod after changing the config file?
Please show screenshot of the mongosh connection you made

Hi!

yes, access control is enabled. As you can see in the configuration file

security:
  # when you start your instance, you have to create a database admin user. As soon as the user is created,
  # the localhost exception will close and you have to authenticate with the database administrator
  authorization: enabled

What do you mean by bounce mongod?

The cmd was

mongosh --host "127.0.0.1" --port "27017" -u "admin" -p "admin" --authenticationDatabase "admin"

Bounce means stop/start mongod for the parameter to take effect incase you edited the file while it is up and running
I want to see the screenshot where you connected without giving credentials

As you can see there, no credentials necessary.

I just noticed what is going on. Whenever I connect to my database without any credentials, I am connect as an unauthenticated user. So …

Question answered.

Thank you!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.