Skip to main content

MongoDB Add Authentication

tip
  • 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 hTkfDMYJ7ZLs and the nocoly password as tC9S86SFWxga as 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.

  1. Connect to MongoDB

    docker exec -it $(docker ps | grep sc | awk '{print $1}') mongo
  2. Create the root user of the admin library and the nocoly user of all business libraries in the mongo shell

    use admin
    db.createUser({user:"root",pwd:"hTkfDMYJ7ZLs",roles:[{role:"root",db:"admin"}]})
    use MDLicense
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDLicense"}]})
    use ClientLicense
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"ClientLicense"}]})
    use commonbase
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"commonbase"}]})
    use MDAlert
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDAlert"}]})
    use mdactionlog
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdactionlog"}]})
    use mdapproles
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapproles"}]})
    use mdapprove
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapprove"}]})
    use mdapps
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdapps"}]})
    use mdattachment
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdattachment"}]})
    use mdcalendar
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcalendar"}]})
    use mdcategory
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcategory"}]})
    use MDChatTop
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDChatTop"}]})
    use mdcheck
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdcheck"}]})
    use mddossier
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mddossier"}]})
    use mdemail
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdemail"}]})
    use mdform
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdform"}]})
    use MDGroup
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDGroup"}]})
    use mdgroups
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdgroups"}]})
    use MDHistory
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDHistory"}]})
    use mdIdentification
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdIdentification"}]})
    use mdinbox
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdinbox"}]})
    use mdkc
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdkc"}]})
    use mdmap
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdmap"}]})
    use mdmobileaddress
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdmobileaddress"}]})
    use MDNotification
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDNotification"}]})
    use mdpost
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdpost"}]})
    use mdreportdata
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdreportdata"}]})
    use mdroles
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdroles"}]})
    use mdsearch
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdsearch"}]})
    use mdservicedata
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdservicedata"}]})
    use mdsms
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdsms"}]})
    use MDSso
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDSso"}]})
    use mdtag
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdtag"}]})
    use mdtransfer
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdtransfer"}]})
    use MDUser
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"MDUser"}]})
    use mdworkflow
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworkflow"}]})
    use mdworksheet
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworksheet"}]})
    use mdworkweixin
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdworkweixin"}]})
    use mdwsrows
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"mdwsrows"}]})
    use pushlog
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"pushlog"}]})
    use taskcenter
    db.createUser({user:"nocoly",pwd:"tC9S86SFWxga",roles:[{role:"readWrite",db:"taskcenter"}]})
    use mdintegration
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdintegration"}]})
    use mdworksheetlog
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdworksheetlog"}]})
    use mdworksheetsearch
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdworksheetsearch"}]})
    use mddatapipeline
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mddatapipeline"}]})
    use mdwfplugin
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdwfplugin"}]})
    use mdpayment
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdpayment"}]})
    use mdwfai
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdwfai"}]})
    use mdopenauth
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdopenauth"}]})
    use mdaisearch
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "mdaisearch"}]})
    use MDAgentInfra
    db.createUser({user: "nocoly",pwd: "tC9S86SFWxga",roles: [{role: "readWrite",db: "MDAgentInfra"}]})
  3. 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_ARGS and ENV_MONGODB_URI under the app service

    ENV_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/
  1. Restart the microservice in the directory where the installation manager is located to take effect.

    bash service.sh restartall