When authentication must specific database which user are.
When creating new user must specific database that user would like to have a specific provileges.
> use admin switched to db admin > db.auth("myUserAdmin", "P@ssw0rd1") 1 > use settrade switched to db settrade > db.createUser( ... { ... user: "mayfly", ... pwd: "P@ssw0rd1", ... roles: [ { role: "readWrite", db: "settrade" }, ... { role: "read", db: "pantip" } ] ... } ... ) Successfully added user: { "user" : "mayfly", "roles" : [ { "role" : "readWrite", "db" : "settrade" }, { "role" : "read", "db" : "pantip" } ] } > db.system.users.find() { "_id" : ObjectId("586db42d5b10326487fc702e"), "user" : "mayfly", "pwd" : "04acf20f8062345c503b5296ce094b59", "roles" : [ "readWrite" ] } { "_id" : ObjectId("586db82b5b10326487fc70ab"), "user" : "termitequeen", "pwd" : "7027db6319fd71eba513904a3f9aff4e", "roles" : [ "dbAdmin" ] } > use admin switched to db admin > db.system.users.find() { "_id" : "admin.myUserAdmin", "user" : "myUserAdmin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "/Il1MVz+E6PswLoN1RNBGw==", "storedKey" : "njrNzk1dnB5fjQTzmwZgVZ3NtBs=", "serverKey" : "pOgAZRsLN1Gr82y4Y7ZElshExlw=" } }, "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] } { "_id" : "settrade.queen", "user" : "queen", "db" : "settrade", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "NWY5bEymoPHiDxt9tFFrgA==", "storedKey" : "iLUtPZvZoX1PAYOek2xPmMN8npE=", "serverKey" : "fY25R+QqcyiRrCh6C0HbOOqAFSQ=" } }, "roles" : [ { "role" : "userAdmin", "db" : "settrade" }, { "role" : "dbOwner", "db" : "settrade" } ] } { "_id" : "settrade.tester", "user" : "tester", "db" : "settrade", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "rhNPFiBo1HPPFV3yveruSA==", "storedKey" : "OYw6GgZE/oXTgw1PTeGC2CD80io=", "serverKey" : "sPtXbzs4lzpp0+nLOa9dAuBCVRw=" } }, "roles" : [ { "role" : "readWrite", "db" : "settrade" }, { "role" : "read", "db" : "pantip" } ] } { "_id" : "settrade.mayfly", "user" : "mayfly", "db" : "settrade", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "j6uKBrG9tWOI/Tr09MM9zA==", "storedKey" : "VIntdHaC91hTWytj071wrI6T/pI=", "serverKey" : "bhitcPVJSz4VsIxZcC5LvP2tS4o=" } }, "roles" : [ { "role" : "readWrite", "db" : "settrade" }, { "role" : "read", "db" : "pantip" } ] } > db.createUser( ... { ... user: "nutt", ... pwd: "P@ssw0rd1", ... roles: [ { role: "root", db: "admin" } ] ... } ... ) Successfully added user: { "user" : "nutt", "roles" : [ { "role" : "root", "db" : "admin" } ] } > db.system.users.find() { "_id" : "admin.myUserAdmin", "user" : "myUserAdmin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "/Il1MVz+E6PswLoN1RNBGw==", "storedKey" : "njrNzk1dnB5fjQTzmwZgVZ3NtBs=", "serverKey" : "pOgAZRsLN1Gr82y4Y7ZElshExlw=" } }, "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] } { "_id" : "settrade.queen", "user" : "queen", "db" : "settrade", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "NWY5bEymoPHiDxt9tFFrgA==", "storedKey" : "iLUtPZvZoX1PAYOek2xPmMN8npE=", "serverKey" : "fY25R+QqcyiRrCh6C0HbOOqAFSQ=" } }, "roles" : [ { "role" : "userAdmin", "db" : "settrade" }, { "role" : "dbOwner", "db" : "settrade" } ] } { "_id" : "settrade.tester", "user" : "tester", "db" : "settrade", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "rhNPFiBo1HPPFV3yveruSA==", "storedKey" : "OYw6GgZE/oXTgw1PTeGC2CD80io=", "serverKey" : "sPtXbzs4lzpp0+nLOa9dAuBCVRw=" } }, "roles" : [ { "role" : "readWrite", "db" : "settrade" }, { "role" : "read", "db" : "pantip" } ] } { "_id" : "settrade.mayfly", "user" : "mayfly", "db" : "settrade", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "j6uKBrG9tWOI/Tr09MM9zA==", "storedKey" : "VIntdHaC91hTWytj071wrI6T/pI=", "serverKey" : "bhitcPVJSz4VsIxZcC5LvP2tS4o=" } }, "roles" : [ { "role" : "readWrite", "db" : "settrade" }, { "role" : "read", "db" : "pantip" } ] } { "_id" : "admin.nutt", "user" : "nutt", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "dOXFYnX4lqt9+sn3Tel5eg==", "storedKey" : "wIsiKjB324I+lzac3/Dio+kmFe0=", "serverKey" : "2Z/g2ScIF6N46WcpjO88fzX57FY=" } }, "roles" : [ { "role" : "root", "db" : "admin" } ] }
No comments:
Post a Comment