[GODRIVER-935] Querying bitnami mongo cluster returns Authentication Failed error Created: 05/Apr/19  Updated: 27/Oct/23  Resolved: 25/Apr/19

Status: Closed
Project: Go Driver
Component/s: Authentication, Connections
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Santhosh Nagaraj S Assignee: Jeffrey Yemin
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

go version: 1.12
Mongo version: 3.4



 Description   

Using the mongo-driver I am able to connect to the replica set cluster and ping is successful but not able to run any queries.

All the queries return the following error:
auth error: unable to authenticate using mechanism "<Mechanism Name>": (AuthenticationFailed) auth failed

But I am able to connect to the db and make queries using mgo, pymongo and other drivers.

Code :

package main
import (
 "context"
 "fmt"
 "time"
 "go.mongodb.org/mongo-driver/bson"
 "go.mongodb.org/mongo-driver/mongo"
 "go.mongodb.org/mongo-driver/mongo/options"
 )
 
func main() {
 
	cred := options.Credential{
		AuthMechanism: "<Mechanism Name>",
		Username:      "<UserName>",
		Password:      "<Password>",
	}
	clientOptions := options.Client()
	clientOptions.ApplyURI("<connection string>")
	clientOptions.SetAuth(cred)
	clientOptions.SetDirect(true)
	clientOptions.SetReplicaSet("<replicaSet>")
	err := clientOptions.Validate()
	if err != nil {
		fmt.Println("Invalid client options:", err)
		return
	}
	client, err := mongo.NewClient(clientOptions)
	if err != nil {
		fmt.Println("cannot create client:", err)
		return
	}
 
	ctx, _ := context.WithTimeout(context.Background(), time.Duration(30)*time.Second)
	err = client.Connect(ctx)
	if err != nil {
		fmt.Println("connection error", err)
		return
	}
	err = client.Ping(ctx, nil)
	if err != nil {
		fmt.Println("ping error", err)
		return
	}
	fmt.Println("ping successful")
	Database := client.Database("collect-dev")
	fmt.Println(Database.ListCollections(ctx, bson.M{}))
}

 
The above code works as expected when trying to connect to standalone mongodb.

When i try to do the same using mgo or pymongo it works.

package main
 
import (
	"fmt"
	"time"
 
	"github.com/globalsign/mgo"
)
 
func main() {
	infog := &mgo.DialInfo{
		Addrs:          []string{"<host>"},
		Timeout:        60 * time.Second,
		Database:       "<dbName>",
		ReplicaSetName: "<replicaSet>",
		Username:       "<Username>",
		Password:       "<Password>",
		Direct:         true,
		Mechanism:      "<Mechanism>",
	}
 
	session, err := mgo.DialWithInfo(infog)
	if err != nil {
		fmt.Println("dial error:", err)
		return
	}
	err = session.Ping()
	if err != nil {
		fmt.Println("ping error:", err)
		return
	}
	fmt.Println("ping successful")
	db := session.DB("<dbName>")
	fmt.Println(db.CollectionNames())
}



 Comments   
Comment by Kristofer Brandow (Inactive) [ 25/Apr/19 ]

Closing due to inactivity.

Comment by Ian Whalen (Inactive) [ 08/Apr/19 ]

yolossn could you please provide the actual auth mechanism you're using so we can attempt to repro internally?

Generated at Thu Feb 08 08:35:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.