[SERVER-32421] Mongo is not accepting password as a parameter Created: 20/Dec/17  Updated: 27/Oct/23  Resolved: 10/Jan/18

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.2.11
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: t.jones Assignee: ADAM Martin (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Debian 9.3 x64


Backwards Compatibility: Fully Compatible
Participants:

 Description   

While connecting to MongoDB 3.2 via "mongo" from Debian 9 shell it seems that the password can only be typed manually after being promted for it. Example:

mongo hostname:port/database -u username -p

The goal, however, is for the user to be able to pass the password along with other parameters. Example:

mongo hostname:port/database -u username -p password

Repro steps:

  • install Debian 9
  • install MongoDB 3.2 using Debian packages
  • add some user to MongoDB
  • enable authentication in config file
  • restart MongoDB
  • try connecting

Expected result:

  • User is able to pass the password along other connection parameters and is able to login successfully.

Actual result:

  • User is still prompted for password despite already passing it with other parameters.
  • The problem does not occur for Debian 8 and MongoDB 2.4.
  • The problem does not occur for Debian 9 and MongoDB 3.2 when using mongodump / mongorestore.

According to the documentation, passing password as a parameter is possible, so what's going on here?
https://docs.mongodb.com/v3.2/reference/program/mongo/



 Comments   
Comment by ADAM Martin (Inactive) [ 10/Jan/18 ]

This appears to work correctly in the shell for version 3.6. This issue has been fixed in current versions of the shell. If you are unable to use the workaround for this issue, please upgrade to a later version of the MongoDB Shell.

Comment by t.jones [ 02/Jan/18 ]

adam.martin I did some testing and indeed I can now connect with space between -p and password:

mongo hostname:port/database -u username -p

I tested on Debian 8.10 with Mongo installed from MongoDB's repos: https://docs.mongodb.com/master/tutorial/install-mongodb-on-debian/

# dpkg -l | grep mongo
ii  mongodb-org                          3.6.1                              amd64        MongoDB open source document-oriented database system (metapackage)
ii  mongodb-org-mongos                   3.6.1                              amd64        MongoDB sharded cluster query router
ii  mongodb-org-server                   3.6.1                              amd64        MongoDB database server
ii  mongodb-org-shell                    3.6.1                              amd64        MongoDB shell client
ii  mongodb-org-tools                    3.6.1                              amd64        MongoDB tools

I'd like to point out, however, that this testing scenario is not exactly perfect for me:

  • I did not test whether previous versions of Mongo coming from mentioned repo had the same issue (I can only confirm that the bug exists for Debian 9's native MongoDB package)
  • my own environment uses Debian 9, for which MongoDB's repos are not available (they're available only for up to Debian 8)
  • my own environment uses Debian 9's native repos, for which the latest MongoDB version is 3.2 (and it's likely that it's going stay with this number for a long time) so I am not able to test any of the latest commits
Comment by ADAM Martin (Inactive) [ 29/Dec/17 ]

Hello t.jones,

I've performed a small test of this behavior on our master branch, and it seems that the shell accepts a password without a space between "-p" and the password text. Can you confirm that this is now fixed for your use case with 3.6's shell?

Comment by t.jones [ 21/Dec/17 ]

mark.agarunov, thanks for the feedback. The workaround is suprisingly trivial, so I am totally OK with using it until the fix appears. Thanks!

Comment by Mark Agarunov [ 20/Dec/17 ]

Hello t.jones,

Thank you for the report. After some testing, I'm able to reproduce this issue and am investigating the cause. However, as a workaround it appears that if you do not leave a space between the -p flag and the password, it logs in as expected:

vagrant@stretch:~$ mongo -u test -p test
MongoDB shell version: 3.2.11
Enter password:
connecting to: test
>
bye

vagrant@stretch:~$ mongo -u test -ptest
MongoDB shell version: 3.2.11
connecting to: test
>

Thanks,
Mark

Generated at Thu Feb 08 04:30:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.