MongoSecurityException: Exception authenticating MongoCredential

Hi Team,

Facing issues with MongoSecurityException while trying to connect with mongo server using URI,

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName=‘test’, source=‘dbName’, password=, mechanismProperties=}

Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): ‘Authentication failed.’ on server localhost:33132. The full response is {“ok”: 0.0, “errmsg”: “Authentication failed.”, “code”: 18, “codeName”: “AuthenticationFailed”}

The environment is ppc64le/UBI 8.3 (RHEL 8.3 based container environment).
MongoDB server version: 4.4.4
Mongo driver version: 3.12.8

Mongo server container logs:
MongoDB server version: 4.4.4

Successfully added user: {
        "user" : "test",
        "roles" : [
                {
                        "role" : "root",
                        "db" : "admin"
                },
                "readWriteAnyDatabase"
        ]
}

From mongo client:
Create a MongoClient(MongoClientURI) instance with MongoClientURI(mongodb://test:password@hostip:port/dbName) and connect with server.

Any pointers help would be great.
Revert back, if more information required.

Thanks in advance!!

Hi there,

I suspect the issue is with the connection string. Appending /dbName to it indicates that the credential is defined in the dbName database, but it’s likely that it’s actually defined in the admin database. Try removing /dbName from the connection string and see if it works.

Regards,
Jeff

2 Likes

Hi Jeff,

Thank you very much for your support.
I checked by removing the /dbName from the MongoClientURI(mongodb://user:pass@host:port).

No positive results and getting the below failure,

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName=‘test’, source=‘admin’, password=, mechanismProperties=}

Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): ‘Authentication failed.’ on server hostip:port. The full response is {“ok”: 0.0, “errmsg”: “Authentication failed.”, “code”: 18, “codeName”: “AuthenticationFailed”}

FYI, I tried the same code with x86_64 and no authentication errors observed. This is specific to PowerPc64.

Regards,
Maniraj

I don’t know what this could be. There should be no different in the behavior of the driver or the JVM on PowerPc64 that would affect authentication.

1 Like

Okay.

At first, faced issue as mentioned below,

com.mongodb.MongoNodeIsRecoveringException: Command failed with error 11600 (InterruptedAtShutdown): ‘Index build failed: 03c6cb78-341b-4789-bf06-b1872ed7876a: Collection graylog.grants ( 01a76922-bca4-43a7-a3ad-790b57c17002 ) :: caused by :: interrupted at shutdown’ on server docker0 Ip:33792. The full response is {“ok”: 0.0, “errmsg”: “Index build failed: 03c6cb78-341b-4789-bf06-b1872ed7876a: Collection graylog.grants ( 01a76922-bca4-43a7-a3ad-790b57c17002 ) :: caused by :: interrupted at shutdown”, “code”: 11600, “codeName”: “InterruptedAtShutdown”}

com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): ‘command dropDatabase requires authentication’ on server docker0 Ip:33792. The full response is {“ok”: 0.0, “errmsg”: “command dropDatabase requires authentication”, “code”: 13, “codeName”: “Unauthorized”}

To resolve this issue added user:pass@ to the MogoClientURI and finally ended with “com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName=‘test’” issue.

Any pointers help would be great. Thanks.

Hi,

As Jeff says there shouldn’t be any behavioural difference between authentication and server architectures.

The exception:

Command failed with error 18 (AuthenticationFailed): ‘Authentication failed.’ on server hostip:port. 
The full response is {“ok”: 0.0, “errmsg”: “Authentication failed.”, “code”: 18, “codeName”: 
“AuthenticationFailed”}

Looks as expected with an invalid username / password combination.

com.mongodb.MongoSecurityException: Exception authenticating
MongoCredential{mechanism=SCRAM-SHA-1, userName=‘test’, source=‘admin’, password=,
mechanismProperties=}

Shows that it is failing but using the expected mechanism against the admin database. You could try an connection string that sets the authSource and authMechanism explicitly:

mongodb://test:pwd@host1/?authSource=admin&authMechanism=SCRAM-SHA-1

Can you connect via the command line without the Java driver?

mongo --port 27017 -u test -p pwd --authenticationDatabase 'admin'

If that fails it indicates the issue is not with the java driver

Ross

1 Like

Hi Ross,

I have checked via the command line and it’s working,

sh-4.4$ mongo --port 27017 -u test -p pass --authenticationDatabase ‘admin’
MongoDB shell version v4.4.4
connecting to: mongodb://localhost:27017/?authSource=admin&compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“d6d2f296-c4e2-42cc-aaf8-f41962e0de56”) }
MongoDB server version: 4.4.4
The server generated these startup warnings when booting:
2021-05-14T11:58:05.616+00:00: Soft rlimits too low
2021-05-14T11:58:05.616+00:00: lockedMemoryBytes: 65536
2021-05-14T11:58:05.616+00:00: minLockedMemoryBytes: 1048576
MongoDB Enterprise > show users;
MongoDB Enterprise >

No improvement by changing the URI as below,
mongodb://test:pass@host1:port/?authSource=admin&authMechanism=SCRAM-SHA-1

The exception:

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName=‘test’, source=‘admin’, password=, mechanismProperties=}

Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): ‘Authentication failed.’ on server docker0 Ip:34121. The full response is {“ok”: 0.0, “errmsg”: “Authentication failed.”, “code”: 18, “codeName”: “AuthenticationFailed”}

Thanks.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.