[CSHARP-1060] Authentication is not done for DBCollection.createIndex() Created: 09/Sep/14  Updated: 04/Apr/15  Resolved: 04/Apr/15

Status: Closed
Project: C# Driver
Component/s: Connectivity
Affects Version/s: 1.9, 1.9.1, 1.9.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Vibhu Kasrija Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7



 Description   

I have enabled auth on MongoDB and created an admin user using:

db.createUser(
  {  
    user: "admin",
    pwd: "***", 
    roles:
    [  
      { role: "root", db: "admin"  }, 
      { role: "dbAdminAnyDatabase", db: "admin" },
      { role: "readWriteAnyDatabase", db: "admin" },
      { role: "readWrite", db: "deadline7db" },  
      { role: "dbOwner", db: "deadline7db" },  
      { role: "dbAdmin", db: "deadline7db" },  
      { role: "readWrite", db: "admin" },  
      { role: "dbOwner", db: "deadline7db_Jobs" },  
      { role: "dbOwner", db: "deadline7db_Tasks" },  
      { role: "dbAdmin", db: "deadline7db_Jobs" },  
    ]  
  }  
)  

When I am trying to connect my application to this database using this user and password, it is connecting fine but throwing an error when trying to create index on deadline7db_Jobs.Job collection.

Below is the error:

Command 'createIndexes' failed: not authorized on deadline7db_Jobs to execute command { createIndexes: "Jobs", indexes: [ { ns: "deadline7db_Jobs.Jobs", name: "Stat_1_Props.Pool_1_Props.Grp_1_IsSub_1", key: { Stat: 1, Props.Pool: 1, Props.Grp: 1, IsSub: 1 } } ] } (response: { "ok" : 0.0, "errmsg" : "not authorized on deadline7db_Jobs to execute command { createIndexes: \"Jobs\", indexes: [ { ns: \"deadline7db_Jobs.Jobs\", name: \"Stat_1_Props.Pool_1_Props.Grp_1_IsSub_1\", key: { Stat: 1, Props.Pool: 1, Props.Grp: 1, IsSub: 1 } } ] }", "code" : 13 }).

I can create index from Mongo shell.



 Comments   
Comment by Craig Wilson [ 11/Sep/14 ]

Hi Vibhu, sorry for the late response. I simply can't reproduce this.

But I just had a thought you can try. Obviously, you are trying to do something on the "deadline7db_Jobs" database. However, it appears as though your user was created in the "admin" database. If this is true, then you need to use the "admin" database for your credentials, not the "deadline7db_Jobs" database.

If that doesn't work, I'll need you to provide a list of reproducible steps and a Program.cs file I can use to run.

Comment by Vibhu Kasrija [ 11/Sep/14 ]

Hi Craig,

Could you please let me know if there is any update on this as this issue is a road blocker for me and need to get this resolved asap.

Thanks!
Vibhu

Comment by Vibhu Kasrija [ 10/Sep/14 ]

I can see similar issue here for java:

https://jira.mongodb.org/browse/JAVA-1181

Vibhu

Comment by Vibhu Kasrija [ 10/Sep/14 ]

Below is the code I am using to provide credentials to driver.

MongoClientSettings mongoSettings = new MongoClientSettings();
List<MongoCredential> credentials = new List<MongoCredential>();
credentials.Add(MongoCredential.CreateMongoCRCredential(connectionInfo.DatabaseName, user, connectionInfo.Password));
mongoSettings.Credentials = credentials;

MongoClient mongoClient = new MongoClient( mongoSettings );
MongoServer mongoServer = mongoClient.GetServer();

    1. connecting to mongo shell

C:\mongodir\application\bin\mongo.exe -u admin -p <password> --authenticationDatabase admin

Thanks!
Vibhu

Comment by Craig Wilson [ 10/Sep/14 ]

1. Are you providing the driver with the credentials? If so, how? Could you provide an example?

2. Are you providing the shell with credentials? If so, how? Could you provide an example?

Comment by Vibhu Kasrija [ 10/Sep/14 ]

I am using C# driver (1.9.2). I guess root provides all the rights to create index if not then which privilege does it require?

I am running everything on the same machine. Mongod, mongo and application all are on the same machine.

If user doesn't have required rights then how is it working through mongo shell.

Please let me know if you need further info.
Thanks for your reply.

Vibhu

Comment by Craig Wilson [ 09/Sep/14 ]

Hi Vibhu,

  • Are you using the .NET (C#) driver for this? It would appear as though your user simply doesn't have rights to perform this function.
  • Also, where is the shell running where this succeeds? As in, is it running on the same box as the driver, or is running on the same box as the mongod, or...

Thanks.

Generated at Wed Feb 07 21:38:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.