I had to create a new user in a MongoDB Server and grant it read-only permissions to a single database. Note that I am not the administrator here.
I connected with my user and executed the following code:
db.createUser({user: "newuser", pwd: "mypassword", roles: [{role: "read", db: "mydatabase"}]})
Then I started testing and I found that
- I can connect with this newly created
newuser
user both with Robo3T and Mongo Shell (mongo
command). - I can read the
mydatabase
database - I can still
WRITE
(insert, update etc) freely in this database - I can read anything from other databases in the server (I didnt try to write).
- I can connect with this database without passing username and password, with Robo3t AND Mongo Shell
- I can force a bad authentication by providing wrong username and passwords (when passed)
When I execute db.runCommand({connectionStatus : 1})
, I get this output:
{
"authInfo" : {
"authenticatedUsers" : [
{
"user" : "newuser",
"db" : "mydatabase"
}
],
"authenticatedUserRoles" : [
{
"role" : "read",
"db" : "mydatabase"
}
]
},
"ok" : 1,
...
}
With Mongo Shell I connect with this command (but also passing --authenticationDatabase
):
mongo --host mongodb://servers:ports/mydatabase?replicaSet=myreplicaset --username newuser --password mypassword
So my questions are very basic, I guess.
- Why can I connect without authenticating?
- Why can I still write with this read-only user?
- Why can I still access other databases with this user?
Thanks in advance!
@edit:
I wonder if it`s something related to this:
https://docs.mongodb.com/manual/tutorial/enable-authentication/
I ve seen some people (check this out) saying that forgot to enable access control. Since I am not the administrator of this database, I am still confused (i`m not a very experienced user)