Hygieia: MongoDB Authentication exception while running api using docker

Created on 1 Dec 2016  Â·  5Comments  Â·  Source: hygieia/hygieia

Hi,
I'm not sure why there is an authentication issue while starting api using docker. I gave the correct username and password even. But not sure why authentication fails. Could someone please help me here what is wrong with my configuration?

Please see the logs below.

I tried even with dashboarduser/dbpassword even.
Im trying to start api on 8082 port as 8080 is used by other.

Note: it works when I tried java -jar api.jar --spring.config.location=dashboard.properties

[oracle@XXXXX01 api]$ docker run -t -p 8082:8082 -v /logs:/hygieia/logs -e
"SPRING_DATA_MONGODB_HOST=192.168.XXX.XXX" -e "SPRING_DATA_MONGODB_PORT=27017" -e "SPRING_DATA_MONGODB_USERNAME=dbuser" -e "SPRING_DATA_MONGODB_PASSWORD=dbpass" -i hygieia-api:latest**

SPRING_DATA_MONGODB_HOST: 192.168.XXX.XXX
SPRING_DATA_MONGODB_PORT: 27017
SPRING_DATA_MONGODB_USERNAME: dbuser

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.5.RELEASE)

2016-12-01 14:46:06,816 INFO  com.capitalone.dashboard.Application - Starting Application v2.0.4-SNAPSHOT on f7aa827b2d8b with PID 7 (/hygieia/api.jar started by root in /hygieia)
2016-12-01 14:46:07,042 INFO  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3d716584: startup date [Thu Dec 01 14:46:07 UTC 2016]; root of context hierarchy
2016-12-01 14:46:13,762 INFO  o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-12-01 14:46:13,918 INFO  o.h.validator.internal.util.Version - HV000001: Hibernate Validator 5.1.3.Final
2016-12-01 14:46:15,717 INFO  o.s.b.c.e.t.TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 8080 (http)
2016-12-01 14:46:16,865 INFO  o.a.catalina.core.StandardService - Starting service Tomcat
2016-12-01 14:46:16,870 INFO  o.a.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/8.0.23
2016-12-01 14:46:17,197 INFO  o.a.c.c.C.[.[localhost].[/api] - Initializing Spring embedded WebApplicationContext
2016-12-01 14:46:17,199 INFO  o.s.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 10156 ms
2016-12-01 14:46:17,939 INFO  c.c.dashboard.config.MongoConfig - ReplicaSetfalse
2016-12-01 14:46:17,945 INFO  c.c.dashboard.config.MongoConfig - Initializing Mongo Client server at: 192.168.XXX.XXX:27017
2016-12-01 14:46:18,179 INFO  org.mongodb.driver.cluster - Cluster created with settings {hosts=[192.168.XXX.XXX:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2016-12-01 14:46:18,256 INFO  c.c.dashboard.config.MongoConfig - Connecting to Mongo: Mongo{options=MongoClientOptions{description='null', readPreference=primary, writeConcern=WriteConcern{w=1, wtimeout=0, fsync=false, j=false, codecRegistry=org.bson.codecs.configuration.ProvidersCodecRegistry@27926884, minConnectionsPerHost=0, maxConnectionsPerHost=100, threadsAllowedToBlockForConnectionMultiplier=5, serverSelectionTimeout=30000, maxWaitTime=120000, maxConnectionIdleTime=0, maxConnectionLifeTime=0, connectTimeout=10000, socketTimeout=0, socketKeepAlive=false, sslEnabled=false, sslInvalidHostNamesAllowed=false, alwaysUseMBeans=false, heartbeatFrequency=10000, minHeartbeatFrequency=500, heartbeatConnectTimeout=20000, heartbeatSocketTimeout=20000, localThreshold=15, requiredReplicaSetName='null', dbDecoderFactory=com.mongodb.DefaultDBDecoder$1@659004c5, dbEncoderFactory=com.mongodb.DefaultDBEncoder$1@2fc1e4cd, socketFactory=javax.net.DefaultSocketFactory@41c0c59e, cursorFinalizerEnabled=true, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitQueueSize=500, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, keepAlive=false, receiveBufferSize=0, sendBufferSize=0}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=20000, readTimeoutMS=20000, keepAlive=false, receiveBufferSize=0, sendBufferSize=0}}}
2016-12-01 14:46:18,450 INFO  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server 192.168.XXX.XXX:27017
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='dbuser', source='dashboarddb', password=<hidden>, mechanismProperties={}}
        at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:61) ~[mongo-java-driver-3.0.2.jar!/:na]
        at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:99) ~[mongo-java-driver-3.0.2.jar!/:na]
        at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:44) ~[mongo-java-driver-3.0.2.jar!/:na]
        at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongo-java-driver-3.0.2.jar!/:na]
        at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127) ~[mongo-java-driver-3.0.2.jar!/:na]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server 192.168.XXX.XXX:27017. The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }
        at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:168) ~[mongo-java-driver-3.0.2.jar!/:na]
        at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123) ~[mongo-java-driver-3.0.2.jar!/:na]
        at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32) ~[mongo-java-driver-3.0.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:95) ~[mongo-java-driver-3.0.2.jar!/:na]
        at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:45) ~[mongo-java-driver-3.0.2.jar!/:na]
        ... 5 common frames omitted
2016-12-01 14:46:19,082 INFO  o.s.b.c.e.ServletRegistrationBean - Mapping servlet: 'dispatcherServlet' to [/]
2016-12-01 14:46:19,098 INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
2016-12-01 14:46:19,100 INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'loggingFilter' to: [/*]
2016-12-01 14:46:19,410 INFO  org.mongodb.driver.cluster - No server chosen by PrimaryServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=192.168.XXX.XXX:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='dbuser', source='dashboarddb', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server 192.168.XX.XXX:27017. The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }}}]}. Waiting for 30000 ms before timing out

Most helpful comment

@vishnuvangala @elangesk
If you use dashboarddb then the role would be

{ role: "readWrite", db: "dashboarddb" }

instead of

{ role: "readWrite", db: "dashboard" } 

And the corresponding properties file should have

dbname=dashboarddb
dbusername=dashboarduser
dbpassword=dbpassword

All 5 comments

@vishnuvangala
I also encountered the same issue and solve to follow below steps:

  1. Point mongoDb directory:
    mongod --dbpath < path to the data directory>
  2. Create database
    ```
    mongo
    MongoDB shell version: 3.0.4
    connecting to: test

use dashboarddb
switched to db dashboarddb
db.createUser({
user: "dashboarduser",
pwd: "dbpassword",
roles: [
{ role: "readWrite", db: "dashboard" }
]
})
Output similar to below should be seen in your mongo shell
Successfully added user: {
"user" : "dashboarduser",
"roles" : [
{
"role" : "readWrite",
"db" : "dashboard"
}
]
}
```

  1. Give DB credentials and port properly in you dashboard.properties then
    java -jar api.jar --spring.config.location=dashboard.properties

@vishnuvangala @elangesk
If you use dashboarddb then the role would be

{ role: "readWrite", db: "dashboarddb" }

instead of

{ role: "readWrite", db: "dashboard" } 

And the corresponding properties file should have

dbname=dashboarddb
dbusername=dashboarduser
dbpassword=dbpassword

Thanks @elangesk @satishc1 ,
Finally I could resolve this authentication issue but unable to access the api even after starting with below command.. not sure what went wrong.. but able to authenticate successfully with below command...
But I have a quick question...
In order to setup Hygieia, should I run API, UI and mongoDB mandatorly in docker container? or can I also start with normal commands instead of running in docker container? Please suggest. I see some difficulty while running through docker and even in setting up this HYGIEIA.. if someone could help me in setting up through chat/live.. that would be great.

Modified command used to run api using docker which resolved the mongo authentication issue:

docker run \
  -t \
  -p 8082:8082 \
  -v /logs:/hygieia/logs \
  -e "SPRING_DATA_MONGODB_HOST=192.168.XX.XXX" \
  -e "SPRING_DATA_MONGODB_PORT=27017" \
  -e "SPRING_DATA_MONGODB_DATABASE=dashboarddb" \
  -e "SPRING_DATA_MONGODB_USERNAME=dashboarduser" \
  -e "SPRING_DATA_MONGODB_PASSWORD=dbpassword" \
  -i hygieia-api:latest

Glad to see your issue is resolved.

Docker is not required in order to run Hygieia - please see the setup instructions for the respective layer of Hygieia that you are trying to run:
https://github.com/capitalone/Hygieia/blob/master/Setup.md

ie. for the API layer, you should be able to do:

mvn install
java -jar api.jar --spring.config.location=dashboard.properties

@mrpudn,
Yeah.. I understood that Docker is not mandatory after reviewing the document again. Looks like the setup document was messedup and confusing for the beginners who setup HYGIEIA.

Seriously, it was so simple to setup.. now, Im encountering with a different issue.. Unable to login to portal.. running the api on 8082 port.. looks like Im missing something.. If required I will raise a different issue.

Regards,
Vishnu

Was this page helpful?
0 / 5 - 0 ratings