arqui78 / rock-php

Automatically exported from code.google.com/p/rock-php
0 stars 0 forks source link

"Unauthorised" error on getCollectionNames with MongoDB 2.4 and non admin user #243

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Configure MongoDB with authentication, create a user on a database
2.Try to log on with rockmongo with this user (non admin) on this particular 
database
3.Unable to get the list of collections, error message (see hardcopy)

RockMongo Version (1.1.5)
Operation System (Windows 7 and Ubuntu 12.04)
PHP Version (5.3)
php_mongo Version (1.3.1)
MongoDB version (2.4.1, ...)

This is due to new behaviour of execute in Mongo 2.4 thar requires admin 
privileges, see here:
   http://stackoverflow.com/questions/15694165/php-mongodb-driver-gives-unauthorized-error-when-running-mongodb-execute-wi

Found a workaround (for php_mongo = 1.3.6 on Linux), in file app/models/ 
replace line 31: 
   $names = self::exec($db, 'function (){ return db.getCollectionNames(); }');
by
   $names = db.getCollectionNames();

This function does not seems to be available in latest build (1.3.2RC1) of PHP 
driver for Windows (event if PHP doc says it is available for PECL mongo 
>=1.3.0)

Original issue reported on code.google.com by acord...@tftlabs.com on 4 Apr 2013 at 1:44

Attachments:

GoogleCodeExporter commented 8 years ago
My above correction on my Linux box was Ok with rockmongo 1.1.2 with php driver 
1.3.6 and Mongo 2.4.1.

I upgraded to rockmongo 1.1.5, and now it is not working again, with another 
error:
   Failed to connect to: 127.0.0.1:27017: Authentication failed on database 'admin' with username 'xxxxx': auth fails

If I can trust the mongodb log file, the authentication with the non admin user 
is Ok, then it tries to find something in the admin db, which is not 
authorized...

Changing back to rockmongo 1.1.2 let it work again...

Well...

Original comment by acord...@tftlabs.com on 4 Apr 2013 at 3:59

Attachments:

GoogleCodeExporter commented 8 years ago
the same thing happened to me. rockmongo1.1.5

Original comment by hk.y...@gmail.com on 9 Apr 2013 at 9:26

GoogleCodeExporter commented 8 years ago
app/controllers/server.php
修改 class ServerController doIndex方法:
$db = $this->_mongo->selectDB("admin");
为
$selectedDB = "admin";
if(isset($_SESSION["login"]) && isset($_SESSION["login"]["db"]) && 
trim($_SESSION["login"]["db"]) != ""){
    $selectedDB = trim($_SESSION["login"]["db"]);
}

$db = $this->_mongo->selectDB($selectedDB);

app/lib/mongo/RMongo.php
修改 class RMongo listDBs方法
return $this->_mongo->listDBs();
为
try{
    $dbs = $this->_mongo->listDBs();
}catch(Exception $e){
    $dbs = array("ok"=>0,"databases"=>array(),"totalSize"=>-1);
}
return $dbs;

Original comment by hk.y...@gmail.com on 9 Apr 2013 at 12:49

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Great! Your suggestion seems to work.
Thanks

Original comment by acord...@tftlabs.com on 15 Apr 2013 at 4:43

GoogleCodeExporter commented 8 years ago
Hi,
After inserting the suggestion above the authentication issue was resolved. The 
only problem is that now I can't perform any action on the collections and it 
keeps returning a "Criteria must be a valid JSON object" error (see attached 
file). 
It even occurs when submitting an empty query... 

Original comment by y...@wibbitz.com on 23 Apr 2013 at 9:20

Attachments:

GoogleCodeExporter commented 8 years ago
Can you show details about that?

The only appearence of "Criteria must be a valid JSON object" is line 209 in 
app/controllers/collection.php,when eval fails.

$this->message = "Criteria must be a valid " . (($format == "json") ? "JSON 
object" : "array");

Original comment by hk.y...@gmail.com on 23 Apr 2013 at 4:15

GoogleCodeExporter commented 8 years ago
I narrow it down a little bit: 
When I switch to Query[Array] everything seems to be working.
I guess that the problem is with the _runJson() method in 
app/classes/VarEval.php
which calls the execute() method.,

Original comment by yonil...@gmail.com on 24 Apr 2013 at 7:52

GoogleCodeExporter commented 8 years ago
I got the same problem.

rockmongo-on-windows-v0.0.4
Operation System (Windows 7 )
MongoDB version (2.4.3)

app/controllers/server.php would be fixed as above
app/lib/mongo/RMongo.php i can't find listDBs() Function!

after sign in with a normal user name i got always the exception!

Execute failed:unauthorized
function (){ return db.getCollectionNames(); }

Can someone help me?

Thanks!

Original comment by wan...@schaeffler.com on 24 Jun 2013 at 6:43

GoogleCodeExporter commented 8 years ago
I got the same problem as above.

rockmongo-on-windows-v0.0.4
Operation System (Windows 7 )

Execute failed:unauthorized
function (){ return db.getCollectionNames(); }

hlp plz.

Original comment by krisho...@gmail.com on 28 Jul 2013 at 11:02

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Problem solved:  Add clusterAdmin role to the user you login as in the admin 
database. Restart mongo. 

I also have in place the snipit of code from message #3 above and this works 
but I don't know at this point if that snipit of code was necessary.

Even though you do not have clusters this role is needed for listDatabases to 
work. This command is also the basis of the mongo shell command show dbs. You 
can test if you have mongo setup right by using this command in the shell.

Remember to change the role. Restart mongo. Get back into the mongo shell. use 
admin. db.auth(), then test with show dbs.

Original comment by develope...@gmail.com on 1 Aug 2013 at 7:56

GoogleCodeExporter commented 8 years ago
rockmongo-on-windows-v0.0.4
Operation System (Windows 7 )
MongoDB version (2.4.3)

Is it possible to solve the problem in windows? 

Original comment by wan...@schaeffler.com on 8 Apr 2014 at 1:32

GoogleCodeExporter commented 8 years ago
rockmongo-on-windows-v0.0.4
Operation System (Windows 7 )
MongoDB version (2.4.3)

Is it possible to solve the problem in windows? 

I ask again. 

The rockMongo is very useful tool. I can't find the other admin ui to replace 
it.
But only this auth problem. 

How can i solve the problem during correcting the php codes?

Please help me!

Original comment by wan...@schaeffler.com on 9 Apr 2014 at 1:35