Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1052

Connecting to MongoDb via C# Driver with Kerberos Auth and a Keytab

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0
    • Component/s: Security
    • Environment:
      MongoDb service is running on a Red Hat Enterprise Linux box in our internal cloud.

      I am trying to connect to it using kerberos, from a Windows machine.
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hi,

      I am having trouble connecting to MongoDb using kerberos authentication.

      I have created a keytab and added it to the keytabs folder.

      My installation of MongoDb is located at:
      /opt/mongodb/

      I can generate a token from the Kerberos server using kinit and specifying the keytab located at: /opt/mongodb/keytab, this successfully generates a keytab for the FID: ost_linux_mongo/vm-1b98-f53f.nam.nsroot.net

      kinit -k -t ost_linux_mongo.keytab ost_linux_mongo/vm-1b98-f53f.nam.nsroot.net

      Through the shell, I can then login to the database using the following command:-

      ./bin/mongo --authenticationMechanism=GSSAPI --authenticationDatabase=\$external -u ost_linux_mongo/vm-1b98-f53f.nam.nsroot.net@NAMUXDEV.DYN.NSROOT.NET vm-1b98-f53f:32017/admin --ssl

      The login works without issues.

      However the issue is that when I attempt the same via the windows machine using the following config:-

      var credential = MongoCredential.CreateGssapiCredential("ost_linux_mongo/vm-1b98-f53f.nam.nsroot.net@NAMUXDEV.DYN.NSROOT.NET","pass");

      var settings = new MongoClientSettings
      {
      Credentials = new[]

      { credential }

      ,
      Server = new MongoServerAddress("vm-1b98-f53f.nam.nsroot.net", 32017),

      UseSsl = true,
      VerifySslCertificate = false,
      };

      client = new MongoClient(settings);
      server = client.GetServer();
      return server.GetDatabase("admin");

      Initialization method DataStatsTest.MongoDbCrudTest.SetUp threw exception. MongoDB.Driver.MongoConnectionException: MongoDB.Driver.MongoConnectionException: Unable to connect to server vm-1b98-f53f.nam.nsroot.net:32017: Unable to initialize security context. Ensure the username and password are correct.. ---> MongoDB.Driver.Communication.Security.MongoSecurityException: Unable to initialize security context. Ensure the username and password are correct. ---> MongoDB.Driver.Communication.Security.Mechanisms.Sspi.Win32Exception: No authority could be contacted for authentication. The domain name of the authenticating party could be wrong, the domain could be unreachable, or there might have been a trust relationship failure..

            Assignee:
            Unassigned Unassigned
            Reporter:
            schana Sukh Chana
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: