Autentication failed when using host=ip, but succeed with localhost

Hi,

I try to set up a mongodb database locally but would like to access it with host=ip address instead of host=localhost.

After setting up my users (admin, root + other users) through mongosh on 127.0.0.1:27017 (localhost), everything works fine when testing. It recognized the user i just created.

However, when trying to login to mongo via host=ip address, mongosh still logs in fine but cannot recognize the admin user.

I’m very confused about this behaviour, and this is preventing me login with a client with ip address (which i need because i want to use a docker container to then access my local mongo database).

I would appreciate some help here :slight_smile:
Thanks!

PS: See attached screenshots of the 2 different behaviours.


It look like you are connecting to 2 different instances of mongod.

The one in 127.0.0.1 generates introduction messages that are different from the ones generated by the one at 192.168.1.119. In particular the one at 127.0.0.1 warns you that Access control is not enabled.

We need the output of the following commands. We need the output from both terminals, the one you use to connect to 127… and the one you use to connect to 192…

ps -aef | grep [m]ongo
ss -tlnp 

Hi Steeve,

Thanks for the reply!

First i need to precise i run mongo on a windows machine. My ip addres 192.168.1.119 is the one i fixed on my network (i tried at least - wifi network).
I ran the commands i posted earlier on the same terminal back-to-back, while mongod was running in an other terminal.

The fact that the introductory message when login on localhost(127.0.0.1) mentionned that “Access control is not enabled” is indeed strange. In my mongod.conf, i have security authorization = enabled.

The other weird thing is that on localhost, when i request the list of db users, i can see my admin user in the admin database. However, when login on 192…, when i request the list of users and roles, i see no users (see attachments).

As i’m running my terminal on windows, the ss command is not working as it is a linux command, though i’m attaching the equivalent with netstat.

I am attaching a couple of screenshots that i hope can help:

  • mongod_conf.png → see binIp, port and authorization
  • mogosh_admin_user_locahost.png → details of admin user when login on localhost
  • mongosh_no_user_recognized_on_ip_192.png → no user found when login on ip=192.168.1.119
  • ps_grep_mongo.png (command ps -aef | grep [m]ongo, you requested)
  • routing_table_netstat_r.png
  • net_stat_o.txt (should be the ~equivalent to the “ss -tlnp” if i’m not mistaken?)

Appreciate the help,
Thanks

mongo_conf.png
mongod_conf

mongosh_admin_user_localhost.png
mongosh_admin_user_localhost

mongosh_no_user_recognized_on_ip_192.png

ps_grep_mongo.png
ps_grep_mongo

routing_table_netstat_r.png

net_stat_o.txt
netstat_o.txt (11.0 KB)

Your netstat output seems to confirms that

The 127.0.0.1 seems to be on k8s while the 192… is not.

Just filtering by port 27017, this is what i see from my 2 ip addresses.
Any idea how to solve this issue?

Proto Local Address Foreign Address State PID
TCP 127.0.0.1:27017 kubernetes:50497 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:50498 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:50499 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:50500 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:50501 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:50502 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:50503 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:55095 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:55096 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:55097 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:55128 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:55129 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:55130 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:63075 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:63076 ESTABLISHED 5868
TCP 127.0.0.1:27017 kubernetes:63077 ESTABLISHED 5868
TCP 192.168.1.119:62175 host:27017 ESTABLISHED 23136
TCP 192.168.1.119:62176 host:27017 ESTABLISHED 23136
TCP 192.168.1.119:62177 host:27017 ESTABLISHED 23136
TCP 192.168.1.119:62178 host:27017 ESTABLISHED 23136

In our case we are interested with the LISTENING ports rather than ESTABLISHED.

The first step would be to stop the windows instances that listen on 192…119:27017.

Then it is possible that traffic is automatically re-directed to the k8s instances once the first step is done.

If not, then you have to do port forwarding for 192…119:27017 the same port forwarding that you have done for 127…1:27017.

But since your goal is

you should simply get rid of the k8s instance and just use the Windows version.