MongoDB Add Authentication
-
When adding authentication, two users are created, the root user for the admin library and the hap user for all business libraries.
-
The provided example uses
hTkfDMYJ7ZLsfor the root password andtC9S86SFWxgafor the hap password. Please replace these with your own, strong passwords in your actual setup.- To ensure compatibility and security, avoid special characters like "$", "&", or "@" in your custom passwords. These characters can interfere with regular expression parsing and may not be correctly passed to the container. Use hyphens "-" or underscores "_" instead.
-
Advance data backup is recommended before operation.
-
Microservices version: v3.7.0+.
-
If you've enabled the aggregate table feature, please refer to the corresponding documents to complete the creation of the aggregate table database and the corresponding roles and users, as well as adjust the replica set related parameters
-
Enter the mingdaoyun-sc container and log in to MongoDB
docker exec -it $(docker ps | grep mingdaoyun-sc | awk '{print $1}') mongo -
Create root users for the admin library and hap users for all business libraries in the mongo shell
use admindb.createUser({user:"root",pwd:"hTkfDMYJ7ZLs",roles:[{role:"root",db:"admin"}]})use MDLicensedb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDLicense"}]})use ClientLicensedb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"ClientLicense"}]})use commonbasedb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"commonbase"}]})use MDAlertdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDAlert"}]})use mdactionlogdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdactionlog"}]})use mdapprolesdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapproles"}]})use mdapprovedb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapprove"}]})use mdappsdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapps"}]})use mdattachmentdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdattachment"}]})use mdcalendardb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcalendar"}]})use mdcategorydb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcategory"}]})use MDChatTopdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDChatTop"}]})use mdcheckdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcheck"}]})use mddossierdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mddossier"}]})use mdemaildb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdemail"}]})use mdformdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdform"}]})use MDGroupdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDGroup"}]})use mdgroupsdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdgroups"}]})use MDHistorydb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDHistory"}]})use mdIdentificationdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdIdentification"}]})use mdinboxdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdinbox"}]})use mdkcdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdkc"}]})use mdmapdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdmap"}]})use mdmobileaddressdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdmobileaddress"}]})use MDNotificationdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDNotification"}]})use mdpostdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdpost"}]})use mdreportdatadb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdreportdata"}]})use mdrolesdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdroles"}]})use mdsearchdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdsearch"}]})use mdservicedatadb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdservicedata"}]})use mdsmsdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdsms"}]})use MDSsodb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDSso"}]})use mdtagdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdtag"}]})use mdtransferdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdtransfer"}]})use MDUserdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDUser"}]})use mdworkflowdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworkflow"}]})use mdworksheetdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworksheet"}]})use mdworkweixindb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworkweixin"}]})use mdwsrowsdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdwsrows"}]})use pushlogdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"pushlog"}]})use taskcenterdb.createUser({user:"hap",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"taskcenter"}]})use mdintegrationdb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdintegration"}]})use mdworksheetlogdb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdworksheetlog"}]})use mdworksheetsearchdb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdworksheetsearch"}]})use mddatapipelinedb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mddatapipeline"}]})use mdwfplugindb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdwfplugin"}]})use mdpaymentdb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdpayment"}]})use mdwfaidb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdwfai"}]})use mdopenauthdb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdopenauth"}]})use mdaisearchdb.createUser({user: "hap",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdaisearch"}]}) -
Modify the file docker-compose.yaml to add environment variables and port mapping.
Default path for file docker-compose.yaml: /data/mingdao/script/docker-compose.yaml
Add environment variables
ENV_MONGODB_DAEMON_ARGSandENV_MONGODB_URIunder the app service.ENV_MONGODB_DAEMON_ARGS: "--auth"ENV_MONGODB_URI: "mongodb://hap:tC9S86SFWxga@127.0.0.1:27017"Add port mapping under the sc service to map port 27017 in the container (you can leave port mapping off if don't need external access).
- 27017:27017Configuration example of file docker-compose.yaml
version: '3'services:app:image: registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-hap:7.3.5environment:ENV_ADDRESS_MAIN: "https://hap.domain.com"ENV_APP_VERSION: "7.3.5"ENV_API_TOKEN: "******"ENV_MONGODB_DAEMON_ARGS: "--auth" # AddENV_MONGODB_URI: "mongodb://hap:tC9S86SFWxga@sc:27017" # Add. Note to change it to the actual hap user password.ports:- 8880:8880volumes:- ./volume/data/:/data/- ../data:/data/mingdao/datasc:image: registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-sc:3.2.0environment:<<: *app-environmentports:- 27017:27017 # Add. MongoDB port mapping. If external access to MongoDB is not required, there is no need to add this port mappingvolumes:- ./volume/data/:/data/ -
Restart the microservice in the directory of Install Manager to take effect.
bash service.sh restartall