User Authentication steps for mongodb3.X and mongodb3.x

Source: Internet
Author: User

User Authentication steps for mongodb3.X and mongodb3.x

Mongodb HAS added the SCRAM-HAS-1 method since version 3.0, but PHP does not support it. It supports the MONGODB-CR mode in version 2. X, which needs to be modified. Some people say that setParameter is added to the configuration document.

setParameter:      authenticationMechanisms: MONGODB-CR

Note that the indentation of the configuration file uses spaces, and the tab will report an error.

But it does not work. It may be applicable to versions earlier than 3.2, or some details have not been noticed. Then we continue to rely on the network and documentation and find another method. The following six steps are required:

To be compatible with versions earlier than 3.0, perform the following steps: 1. In the login use admin mode without auth enabled; db. createUser ({user: 'shang ', pwd: 'shang', roles: [{role: 'root', db: 'admin'}]}); // because this step is not executed, db. system. no data in version 2. Modify authcurrentVersionvar schema = db. system. version. findOne ({'_ id': 'authschema'}); schema. currentVersion = 3; db. system. version. save (schema); 3. drop the user who used SCRAM-HAS-1 authentication before using the revoke use admin; db. createUser ({user: 'shang ', pwd: 'shang', roles: [{role: 'root', db: 'admin'}]}); // now create is to use MONGODB-CR authentication user 5, to enable auth mode restart use admin; db. auth ('shang ', 'shang'); 6. You can also create other users to use robo; db. createUser ({user: 'robo', pwd: 'robo', roles: [{role: 'readwrite', db: 'robo'}]}); // tested, use Robomongo to connect. You can connect both of the two authentication methods.

Later I found that the initial modification was the authSchemaVersion parameter. I don't know if it is feasible to directly Add the following code to the configuration file? You can try it later. If it is confirmed that it is not possible, the system prompts "BadValue: Cannot use -- setParameter to set" authSchemaVersion "at startup ".

setParameter:    authSchemaVersion: 3

The following is a command for installing the configuration file and using the configuration file to the window service and starting it.

Configuration File mongo. export systemlog: destination: file path: D:/mongodb/data/log/mongod. logstorage: dbPath: D:/mongodb/data/dbnet: bindIp: 127.0.0.1 port: 27017 security: authorization: enabledsetParameter: authenticationmechanic ISMs: MONGODB-CR enableLocalhostAuthBypass: false logLevel: Login -- config D: /mongodb/mongod. cfg -- installnet start MongoDBnet stop MongoDB

Finally, let's talk about the roles in authentication.

The basic role userAdminAnyDatabase has the permission to assign roles and users, but there is no write query defect. root this is the Super administrator readWrite who has the read and write permissions. read the read permission to close the service db. shutdownServer ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.