0

OK SO land, I have exhausted all attempts to find an answer for my issue.

I have a RoR app running Mongoid 3.16 and a remote server with Mongodb 3.05. Both servers are on the same network and I am using internal IP address to connect.

The problem that I am having is trying to secure the connection. First off, if I try to add the app IP to the bind_ip in the mongod.conf file I get an error:

Cannot assign requested address for socket: app_ip_address

Here is the bind_ip in the mongod.conf:

#bind_ip=127.0.0.1,app_ip_address

If I uncomment it and try to restart mongodb it gives me the error about "Cannot assign requested address..." So I can connect from the app to mongodb IF I leave the bind_ip commented out. I do not like this idea because it will allow any connection.

My mongoid.yml file is:

production:
  sessions:
    default:
      database: my_database
      hosts:
        - mongodb_server_ip:27017

I also set up the database to have a user but if I set the auth to true for Mongodb, it will allow connection to the "my_database" without authorization, but cannot read the data unless I authenticate again (which I can do command line but not via the mongoid.yml file)

For example if I connect command line from the app server with:

mongo mongoddb_server_ip:27017/my_database

That works but when I try to view collections I have to db.auth(....) to see them.

I guess that if I can config the mongoid.yml with the username/password for mongodb that would work but I cannot figure out how to do that.

Update 11/23:

OK, I set the mongod.conf file to auth = true. Now I can connect from the app server via ssh:

mongo mnogodb_server_ip:27017/my_database --username some_username --password some_password

That allows me to connect and access all collections etc. Now that I am requiring authentication I updated my mongoid.yml file as so:

production:
  sessions:
    default:
      database: my_database
      username: some_username
      password: some_password
      hosts:
        - mongodb_server_ip:27017

I restart the server and I cannot connect to the remote db.

Bob Roberts
  • 1,013
  • 9
  • 15

1 Answers1

0

Well, after all of this I find out that moped 2 does not support authentication for MongoDB 3+.

see here:

Rails Mongoid fails to authenticate - failed with error 13: "not authorized for query on my_db.my_collection"

Community
  • 1
  • 1
Bob Roberts
  • 1,013
  • 9
  • 15