I would like to automate my script using mongosh but its show password in plaintext
mongosh --host XX --port XX --username XX --password XX --eval “use DBNAME” --eval “db.dropDatabase()”
I tried to use window authentication but its prompted password too.I am currently using mongodb 6.0 and i would like to seek advise on how to hide password in script above.
If you don’t want to specify the secret in plain text in the script file, then you have to pass the secret to the script from “somewhere”. That somewhere can be standard input or other external sources. Which is out of the scope of mongodb tool. (e.g. use a dedicated machine with admin/special access to run this script).
You want to store the raw secret at a safe place and then use a special mechanism to fetch it (e.g. encryption, access control).
On unix based system such as linux, it would be kind of trivial to do that with sudo.
You create your script as owned by root and then you give it read and executable permissions only to root. You would then create a sudoer entry for each user you want to give the right to run the script. The user would be able to execute the script but not read it.
I am not sure how this would work to really hide the password.
From what I understand, mongosh need to read the file 01login.js in order to execute it. So what stops the user running the command mongosh, to just cat (or notepad) the file 01login.js and see the password?
still suffer the issue that they are hidden but still accessible by people with minimal skills.
Your main system might be Windows, but you can easily and cheaply add something like a Raspberry Pi and implement your scripts using sudoers. Then you automate with systemd timers or cron. I used one to automate water recirculating pumps and parking lights for my apartment building. So what ever I do with my main machines do not ever intervene my automation.
A secondary effect, you will be initiated to the wonderful world of linux. You might like it. (oVo)