Gabriela Silva
Gabriela Silva

Reputation: 27

Cygnus and mongodb: Authentication failed

I'm trying to use cygnus and mongdb with docker.

My docker-compose:

cygnus:
    image: fiware/cygnus-ngsi:1.7.1
    hostname: cygnus
    container_name: cygnus
    volumes:
      - ./config/cygnus/agent.conf:/opt/apache-flume/conf/agent.conf
    links:
      - mysql-cygnus:mysql-cygnus
    external_links:
      - mongodb:mongodb
    expose:
      - "5050"
    ports:
      - "5050:5050"
    environment:
      - CYGNUS_MONGO_HOSTS=mongodb:27017
      - CYGNUS_MONGO_USER=cygnus
      - CYGNUS_MONGO_PASS=f10t_Mongo
      - CYGNUS_LOG_LEVEL=INFO

...

mongodb:
    image: mongo:3.4.7
    hostname: mongodb
    image: aashreys/mongo-auth:latest
    expose: 
      - "27017"
    ports:
      - "27017:27017"
    environment:
      - AUTH=yes
      - MONGODB_ADMIN_USER=admin_cygnus
      - MONGODB_ADMIN_PASS=admin_cygnus 
    expose:
      - "27017"
    ports:
      - "27017:27017"

My agent.conf

cygnus-ngsi.sinks.mongo-sink.mongo_hosts = mongodb:27017
cygnus-ngsi.sinks.mongo-sink.mongo_username = cygnus
cygnus-ngsi.sinks.mongo-sink.mongo_password = f10t_Mongo

But I got in cygnus log:

msg=com.telefonica.iot.cygnus.sinks.NGSISink[533] : Persistence error.     
Message: -, Timed out after 30000 ms while waiting for a server that matches PrimaryServerSelector. 
Client view of cluster state is {type=UNKNOWN, servers=[{address=mongodb:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='cygnus', source='cygnus_imd', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException:
Command failed with error 18: 'Authentication failed.' on server mongodb:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}]

and mongo log:

2018-04-25T20:59:19.684+0000 I ACCESS   [conn136] SCRAM-SHA-1 authentication failed for cygnus on cygnus_imd from client 172.18.0.4:37250 ; UserNotFound: Could not find user cygnus@cygnus_imd

I resolved the problem creating the user inside the database cygnus_imd:

use cygnus_imd
db.createUser(
   {
     user: "cygnus",
     pwd: "f10t_Mongo",
     roles: [ "readWrite", "dbAdmin" ]
   }
);

But I don't think that is a good solution, because I can't create a user for each dataset of my cygnus, it should be done automatically. I think that the authentication doesn't work with a database empty. But at the begin, all databases are empties. So I don't know how fix it.

Upvotes: 0

Views: 374

Answers (1)

Dalton C&#233;zane
Dalton C&#233;zane

Reputation: 3782

I think you can not avoid this when dealing with authentication. As the purpose of an authentication mechanism is ensuring the identification of an entity, maybe you can use a unique identification (user) for a group of datasets. If there is no security problems, maybe the admin user can be used, since you are specifying dbAdmin as one role for the user.

Upvotes: 1

Related Questions