MongoDB Add Authentication
-
Adding authentication will create two users, namely the root user of the admin library and the nocoly user of all business libraries.
-
The following steps take the root password as
hTkfDMYJ7ZLsand the nocoly password astC9S86SFWxgaas an example. Be sure to change the root and nocoly passwords in the actual configuration- To ensure compatibility, avoid using special characters such as "$", "&", "!" or "@" when customizing passwords. These characters may interfere with regular expression parsing. Please use hyphens "-" or underscores "_" instead
-
It is recommended to data backup in advance before operation.
-
Connect to MongoDB
docker exec -it $(docker ps | grep sc | awk '{print $1}') mongo -
Create the root user of the admin library and the nocoly user of all business libraries in the mongo shell
use admindb.createUser({user:"root",pwd:"hTkfDMYJ7ZLs",roles:[{role:"root",db:"admin"}]})use MDLicensedb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDLicense"}]})use ClientLicensedb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"ClientLicense"}]})use commonbasedb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"commonbase"}]})use MDAlertdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDAlert"}]})use mdactionlogdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdactionlog"}]})use mdapprolesdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapproles"}]})use mdapprovedb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapprove"}]})use mdappsdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapps"}]})use mdattachmentdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdattachment"}]})use mdcalendardb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcalendar"}]})use mdcategorydb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcategory"}]})use MDChatTopdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDChatTop"}]})use mdcheckdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcheck"}]})use mddossierdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mddossier"}]})use mdemaildb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdemail"}]})use mdformdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdform"}]})use MDGroupdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDGroup"}]})use mdgroupsdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdgroups"}]})use MDHistorydb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDHistory"}]})use mdIdentificationdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdIdentification"}]})use mdinboxdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdinbox"}]})use mdkcdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdkc"}]})use mdmapdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdmap"}]})use mdmobileaddressdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdmobileaddress"}]})use MDNotificationdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDNotification"}]})use mdpostdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdpost"}]})use mdreportdatadb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdreportdata"}]})use mdrolesdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdroles"}]})use mdsearchdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdsearch"}]})use mdservicedatadb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdservicedata"}]})use mdsmsdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdsms"}]})use MDSsodb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDSso"}]})use mdtagdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdtag"}]})use mdtransferdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdtransfer"}]})use MDUserdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDUser"}]})use mdworkflowdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworkflow"}]})use mdworksheetdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworksheet"}]})use mdworkweixindb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworkweixin"}]})use mdwsrowsdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdwsrows"}]})use pushlogdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"pushlog"}]})use taskcenterdb.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"taskcenter"}]})use mdintegrationdb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdintegration"}]})use mdworksheetlogdb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdworksheetlog"}]})use mdworksheetsearchdb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdworksheetsearch"}]})use mddatapipelinedb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mddatapipeline"}]})use mdwfplugindb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdwfplugin"}]})use mdpaymentdb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdpayment"}]})use mdwfaidb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdwfai"}]})use mdopenauthdb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdopenauth"}]})use mdaisearchdb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdaisearch"}]})use MDAgentInfradb.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "MDAgentInfra"}]}) -
Modify the docker-compose.yaml file and add environment variables and port mapping
Default path of docker-compose.yaml file: /data/hap/script/docker-compose.yaml
Add environment variables
ENV_MONGODB_DAEMON_ARGSandENV_MONGODB_URIunder the app serviceENV_MONGODB_DAEMON_ARGS: "--auth"ENV_MONGODB_URI: "mongodb://nocoly:tC9S86SFWxga@sc:27017"
Add a new port mapping under the sc service and map the 27017 port in the container (if there is no need to access mongodb externally, there is no need to add this port mapping)
- 27017:27017
Example of docker-compose.yaml configuration file modification
version: '3'
services:
core:
image: nocoly/core:7.4.2
environment: &app-environment
ENV_ADDRESS_MAIN: "https://example.domain.com"
ENV_APP_VERSION: "7.4.2"
ENV_API_TOKEN: "******"
ENV_MONGODB_DAEMON_ARGS: "--auth" #Add new variable
ENV_MONGODB_URI: "mongodb://nocoly:tC9S86SFWxga@sc:27017" #Add a new variable and change it to the actual nocoly user password.
ports:
- 8880:8880
volumes:
- ./volume/data/:/data/
- ../data:/data/hap/data
sc:
image: nocoly/sc:3.2.0
environment:
<<: *app-environment
ports:
- 27017:27017 #Added mongodb port mapping. If external access to mongodb is not required, there is no need to add this port mapping.
volumes:
- ./volume/data/:/data/
-
Restart the microservice in the directory where the installation manager is located to take effect.
bash service.sh restartall