Auth Failed trying to connect from a Fantom script to a MongoDB hosted in MongoLab. What's wrong? - mongodb

I'm trying to connect to a remote MongoDB v3.0.8 hosted in MongoLab using a Fantom v1.0.67 script. The driver I'm using is afMongo v1.0.4. The connection line is:
mongoClient := MongoClient(
ActorPool(),
`mongodb://mydbuser:mydbpassword#ds0#####.mongolab.com:#####/mymongodb`
)
Please note that the placeholders mydbuser, mydbpassword and ##### are replaced with the correct values. The connection is successful when I run the following command from a shell:
mongo ds0#####.mongolab.com:#####/mymongodb -u mydbuser -p mydbpassword
but from the Fantom script, I get this error:
afMongo::MongoCmdErr: Command 'authenticate' failed. MongoDB says: auth failed
afMongo::Operation.runCommand (Operation.fan:36)
afMongo::Operation.runCommand (Operation.fan)
afMongo::Connection$.authenticate (Connection.fan:34)
afMongo::TcpConnection.authenticate (Connection.fan:51)
afMongo::ConnectionManagerPooled.checkOut (ConnectionManagerPooled.fan:458)
afMongo::ConnectionManagerPooled.leaseConnection (ConnectionManagerPooled.fan:320)
afMongo::Cmd.run (Cmd.fan:71)
afMongo::Database.runCmd (Database.fan:36)
afMongo::MongoClient.runAdminCmd (MongoClient.fan:107)
afMongo::MongoClient.buildInfo (MongoClient.fan:64)
afMongo::MongoClient.startup (MongoClient.fan:119)
afMongo::MongoClient.makeFromUri$ (MongoClient.fan:41)
afMongo::MongoClient.makeFromUri$ (MongoClient.fan)
afMongo::MongoClient.makeFromUri (MongoClient.fan:38)
I have also tried Robomongo v0.8.4 with a similar result: A pop-up dialog saying...
Successfully connected to ds0#####.mongolab.com:#####
Authorization failed
I ran the Fantom script as well as Robomongo connecting and authenticating successfully against MongoDB v2.6.3 and v3.0.8 databases hosted locally.
My Java version is Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
I don't know if Robomongo or Fantom/afMongo depend on a Java or System library that is out of date.
What is wrong or what I should be checking, please?

The auth failures in both Robomongo v0.8.4 and afMongo 1.0.4 are due to a new authentication mechanism in MongoDB v3 called SCRAM-SHA-1.
afMongo has been updated with an implementation of SCRAM-SHA-1 over SASL. It auto detects Mongo v3 databases and switches the auth protocol, falling back to the older MONGODB-CR when needed - see this commit.
These changes haven't been released yet because it depends on a new method Buf.pbk(...) that is only available in Fantom 1.0.68 - which itself is unreleased. An updated afMongo v1.0.6 will be released as soon as Fantom 1.0.68 is.
You could compile Fantom 1.0.68 and afMongo 1.0.6 from source, but to be honest, the easiest fix (in the meantime) is to just use a v2.6 MongoDB database.
Note that, if needed, the MongoChef GUI client can authenticate against MongoDB v3 databases.

Related

Mongodb "auth fails" with mongodb php driver and new php library

Using the new mongodb driver: https://github.com/mongodb/mongo-php-driver and the new php library for it: https://github.com/mongodb/mongo-php-library I am getting "auth fails" trying to perform a simple find() query.
In the following code, the connection string follows the pattern mongodb://user:password#mongoinstance:port/database. The connection string works with find() using the old legacy mongo driver, but not the new mongodb driver. The new mongodb is correctly installed in php and displays in phpinfo, the only breaking change we needed to make was to use "new MongoDB\Client" instead of new MongoClient for the legacy mongo driver.
However, when I try to run the following find(), I get auth fails exception in vendor/mongodb/mongodb/src/Operation/Find.php line 179
Using legacy mongo driver there are no problems. Any ideas on the auth fails? What is the mongodb driver failing on exactly? Correct credentials for database and collection are being passed in the mongodb://string. Works in legacy fails with new driver and library.
Environment:
Windows 10
Wamp
PHP 5.5.12
Mongodb driver 1.1.4
Latest version of new php library (Installed with composer: composer require "mongodb/mongodb=^1.0.0")
Mongo instance version 2.4.6
I just had the same error and found out that I had to place the database-name in the connection string.
The documentation here says:
If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database.
And the user I'm using has no rights to the admin-database, so this is why I received the authentication error.
I advise you to check this too. You can't provide the database-name the same way as with the MongoClient via the connection options.
So here's the solution. After 3 days of banging my head against a wall it turns out the new mongodb driver parses the mongodb uri differently than the legacy mongo driver. My password had a % sign in it. As soon as I changed the % sign to something else everything worked as expected.

Dart - error when trying to authenticate with mongodb

After running:
import 'package:mongo_dart/mongo_dart.dart';
//Create account with given credentials
createAccount(Map<String, String> credentials) async {
Db db = new Db('mongodb://127.0.0.1/exampledb');
await db.open();
await db.authenticate("user", "password");
//TODO: Post credentials into DB
}
I get an error on the Dart server saying:
Unhandled exception:
Uncaught Error: {ok: 0.0, errmsg: auth failed, code: 18}
And a different error comes up up on the mongod server:
2015-09-27T20:04:25.921+0100 I ACCESS [conn1] Failed to authenticate user#exampledb with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentia
ls missing in the user document
The only time when the authentication has succeeded and has allowed me access to the database is when I am using the command prompt.
Example:
$ use exampledb
$ db.auth("user", "password")
How can I make my Dart script gain access to my local mongodb, using the authenticate method?
Fresh update:
Since version 0.2.5 mongo_dart supports SCRAM-SHA-1 authentification mechanism. It used by default in connections to MongoDb 3
Update:
That seems to be rather widespread problem with some drivers, programs e.t.c not supporting yet new authentication mechanism (SCRAM-SHA-1) of mongodb 3.0
By default, mongodb 3.0, do not create credentials in old format (MONGODB-CR) while creating new users.
There is round-about solution, that force mongodb 3.0 and upper version use MONGODB-CR mode while creating users.
Look for example solution at https://jira.mongodb.org/browse/SERVER-17459
As stated in that thread
both new drivers and legacy software work with that solution
Obviously best solution for mongo_dart would be to add implementation of new authentication mode to the driver. Can not give any date, but I think it should be first feature that I can take in consideration as soon as I have some time for mongo_dart.
And obviously it would be great if somebody beat me at that with pull request :)
Original answer
I've reproduced that error in my environment too.
Error appears to be related to changed default authentication mode in version 3.0 of MongoDb. I'll update this answer, when the problem will be resolved
I tried that in my mongodb 4.0.10 and mongo_dart 0.3.6 and the authentication went all right and correct just update your components if you didn't yet and everything will be fine.
PS: I know I am late but hope someone get used from my "Note".

Can't authenticate against Mongodb 3.0.1 member added to a 2.6.8 replica set

We have a replica set running 2.6.8, and I'm trying to add a member running 3.0.1 with the WiredTiger engine. I'm attempting to do a rolling update of the replica set to 3.0.1 by replacing one member at a time. The data seems to have replicated, but I am unable to authenticate using the mongo shell.
MongoDB shell version: 3.0.1
connecting to: test
rs:SECONDARY> use admin
switched to db admin
rs:SECONDARY> db.auth("admin", "password")
Error: 18 Authentication failed.
0
The log is also full of the following:
Failed to authenticate admin#admin with mechanism MONGODB-CR: AuthenticationFailed UserNotFound Could not find user admin#admin
Failed to authenticate user#collection with mechanism MONGODB-CR: AuthenticationFailed UserNotFound Could not find user user#collection
I'm not sure if the users didn't replicate along with the data, or if this is something to do with the authentication mechanism changing in 3.0.
I'm only seeing this issue on our production replica set. I first tried in on our testing replica set and had no issues. I've tried it multiple times in production, each time launching a new clean AWS instance, and each time I have the same issue. The only difference between production and testing are the IPs and the amount of data. Production has >2TB of data, while testing has a <1GB. Monogdb is running on Amazon Linux, using packages from the http://repo.mongodb.org/yum/redhat/6/mongodb-org/3.0/x86_64/ yum repository.
The problem was that the authorization schema was still using the version 2.4 schema, even though all members of the replica set were running 2.6.
Mongodb < 3.0.2 doesn't check this before syncing, but they changed it in 3.0.2 to give an error before trying to sync.
Run db.getSiblingDB("admin").runCommand({authSchemaUpgrade: 1 }); on the primary of the replica set before adding the version 3 member.

How is MongoDb installed by Meteor?

I'm new to both Meteor.js and MongoDB and after installing Meteor in the official way described I wonder how to connect to my MongoDB.
MongoDB was installed by Meteor during the installation and everything works fine but now I would like to have a look into it with another tool (like RazorSQL) to see what's in there.
But the standard connection parameters (localhost:27017) doesn't work, what can I do? Login? Password?
Update: February 2014 - Meteor 0.7.1 - The meteor port has been shifted to 3001 instead of 3002. So instead of adding two to the port meteor runs on, you add 1 instead.
MongoDB's database is installed in the meteor package containing your files in a hidden folder called .meteor. To access it from a remote tool simply add 2 to whatever your web server port is while meteor is running. It will be stored in the meteor database
e.g
http://localhost:3000 would have its mongodb server running at mongodb://localhost:3002/meteor there is no username/password on this instance if you ran it with meteor or meteor run
To get the Meteor Mongo url and port, first run your Meteor app using meteor run then run meteor mongo in a different terminal tab. You should see an output like this
[meteor-app] meteor mongo
MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:3001/meteor
this means that your Meteor Mongo is running at 127.0.0.1:3001.
If you are running your Meteor app with meteor run then you neither need username/password nor authentication configuration just make sure that you set your default database name as meteor

Heroku could not authenticate mongolab

It was corrected two days ago. And yesterday I committed some changes to heroku and the application crashed, I found from heroku logs that:
/app/.bundle/gems/ruby/1.9.1/gems/mongo-1.4.0/lib/mongo/db.rb:137:in `issue_authentication': Failed to authenticate user 'larryzhao' on db 'uthenera' (Mongo::AuthenticationError)
I even explicitly input the host/port/username/password/db name into mongoid.yml, still it could not get pass authentication.
I tried both database in Rackspace and in Amazon, but neither could authenticate.
Have you met with that before? Is there anything else I could check on Heroku besides heroku logs ?
Thanks.
Today I encountered the same on Heroku:
Mongo::AuthenticationError: Failed to authenticate user 'heroku_app111' on db 'heroku_app111'.
from /home/ad/.rvm/gems/ruby-2.1.3#app/gems/mongo-1.11.1/lib/mongo/functional/authentication.rb:205:in `issue_authentication'
It's not because of this RUBY-890 bug, but because MongoLab upgraded to MongoDB 3.0 which uses SCRAM-SHA-1 challenge-response user authentication mechanism. So I needed latest ruby mongo driver version which is counting with this. In my case latest 1.x branch.
The minimum driver versions that support SCRAM-SHA-1 are:
Driver Language Version
C 1.1.0
C++ 1.0.0
C# 1.10
Java 2.13
Node.js 1.4.29
Perl 0.708.0.0
PHP 1.6
Python 2.8
Motor 0.4
Ruby 1.12
Scala 2.8.0
Of course you have to be sure your credentils are ok :)
Make sure you're using the right username to connect to your database. The username you use to log into mongolab.com is different from the one attached to the 'uthenera' database. Have a look at the Users tab for that database at mongolab.com to see what database user(s) you've configured.
Hope that helps. Feel free to email support#mongolab.com if you need further assistance.
-Robert
You can get your database username and password using:
heroku config | grep MONGODB_URI
The response is in this format:
MONGOLAB_URI: mongodb://username:password#mlab.com:12345/db