Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-1039

Force QueryClient to use HTTP Auth for N1QL queries

    XMLWordPrintable

Details

    • Task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.2.2
    • 2.2.4
    • library
    • None

    Description

      Temp fix for: MB-16964

      Note that QueryRequest.AddCredentials will not work until MB-16964 is resolved. This fix will use the credentials passed into Cluster.OpenBucket(user, pass) as the N1QL query credentials, adding them to the HTTP header, and sent the server.

      • If the bucket name in the query does not match the the bucket that was opened and auth'd, then the query will failed with "Authorization Failed"
      • If you try to use QueryRequest.AddCredentials, you will receive "creds has to be of type array of { user, pass }

        "

      Once MB-16964 is released as a server fix, AddCredentials will work for all versions of the server in which the fix applies-for server versions 4.0.0, etc this work around will apply.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          jmorris Jeff Morris added a comment -

          This patch is 2.2.2.0 with http://review.couchbase.org/#/c/57474/ note is does not include NCBC-1031.

          jmorris Jeff Morris added a comment - This patch is 2.2.2.0 with http://review.couchbase.org/#/c/57474/ note is does not include NCBC-1031 .

          I'm still getting an error with the supplied update with a password-protected bucket. In the Error collection for result, I see:

          "Authorization Failed Keyspace testbucket"

          Code is as follows. I am unable to use the AddCredentials line without the previous mentioned array error.

          using (var bucket = _cluster.OpenBucket("testbucket", "mypassword"))
          {
          var queryRequest = new QueryRequest("SELECT click from testbucket as c");
          //queryRequest.AddCredentials( "Administrator", "password", true);

          var result = bucket.Query<dynamic>(queryRequest);
          foreach (var row in result.Rows)

          { Console.WriteLine(row); }

          }

          jdillon Jeff Dillon (Inactive) added a comment - I'm still getting an error with the supplied update with a password-protected bucket. In the Error collection for result, I see: "Authorization Failed Keyspace testbucket" Code is as follows. I am unable to use the AddCredentials line without the previous mentioned array error. using (var bucket = _cluster.OpenBucket("testbucket", "mypassword")) { var queryRequest = new QueryRequest("SELECT click from testbucket as c"); //queryRequest.AddCredentials( "Administrator", "password", true); var result = bucket.Query<dynamic>(queryRequest); foreach (var row in result.Rows) { Console.WriteLine(row); } }
          jmorris Jeff Morris added a comment -

          Jeff Dillon -

          Which server version are you testing against?

          Note that this won't work:

           using (var bucket = _cluster.OpenBucket("default"))
                      {
                          //NOTE: travel-sample is password protected
                          const string query = "SELECT * FROM `travel-sample` LIMIT 10";
           
                          var queryRequest = new QueryRequest(query);
                          var result = await bucket.QueryAsync<dynamic>(queryRequest);
                          Assert.IsTrue(result.Success);
                          Assert.AreEqual(10, result.Rows.Count);
                      }
          

          However, this will work:

           using (var bucket = _cluster.OpenBucket("travel-sample", "secret"))
                      {
                          //NOTE: travel-sample is password protected
                          const string query = "SELECT * FROM `travel-sample` LIMIT 10";
           
                          var queryRequest = new QueryRequest(query);
                          var result = await bucket.QueryAsync<dynamic>(queryRequest);
                          Assert.IsTrue(result.Success);
                          Assert.AreEqual(10, result.Rows.Count);
                      }
          

          Note, it might make sense to change the implementation of AddCredentials temporarily so that it only accepts one user/pass combo and pushes them onto the HTTP header, overwriting the bucket user/pass that the SDK is currently using.

          jmorris Jeff Morris added a comment - Jeff Dillon - Which server version are you testing against? Note that this won't work: using (var bucket = _cluster.OpenBucket("default")) { //NOTE: travel-sample is password protected const string query = "SELECT * FROM `travel-sample` LIMIT 10";   var queryRequest = new QueryRequest(query); var result = await bucket.QueryAsync<dynamic>(queryRequest); Assert.IsTrue(result.Success); Assert.AreEqual(10, result.Rows.Count); } However, this will work: using (var bucket = _cluster.OpenBucket("travel-sample", "secret")) { //NOTE: travel-sample is password protected const string query = "SELECT * FROM `travel-sample` LIMIT 10";   var queryRequest = new QueryRequest(query); var result = await bucket.QueryAsync<dynamic>(queryRequest); Assert.IsTrue(result.Success); Assert.AreEqual(10, result.Rows.Count); } Note, it might make sense to change the implementation of AddCredentials temporarily so that it only accepts one user/pass combo and pushes them onto the HTTP header, overwriting the bucket user/pass that the SDK is currently using.
          jdillon Jeff Dillon (Inactive) added a comment - - edited

          The code I provided (using 2.2.2.2) is giving the error as mentioned. I'm not using AddCredentials (it's commented out, as shown). This is against 4.0.0. Would QueryAsync work any differently compared to Query? The customer is using the Query (sync) version. I will also test with QueryAsync.

          jdillon Jeff Dillon (Inactive) added a comment - - edited The code I provided (using 2.2.2.2) is giving the error as mentioned. I'm not using AddCredentials (it's commented out, as shown). This is against 4.0.0. Would QueryAsync work any differently compared to Query? The customer is using the Query (sync) version. I will also test with QueryAsync.
          jmorris Jeff Morris added a comment -

          Jeff Dillon -

          >>Would QueryAsync work any differently compared to Query?

          Just validated that this is the case, will post a patch ASAP. In meantime, the async version works as expected and the customer could use that version.

          -Jeff

          jmorris Jeff Morris added a comment - Jeff Dillon - >>Would QueryAsync work any differently compared to Query? Just validated that this is the case, will post a patch ASAP. In meantime, the async version works as expected and the customer could use that version. -Jeff
          jmorris Jeff Morris added a comment - - edited

          See attached VF for both async and sync query requests using authenticated buckets.

          jmorris Jeff Morris added a comment - - edited See attached VF for both async and sync query requests using authenticated buckets.

          I have confirmed that the 2.2.2.5 VF works as expected for both sync and async query requests on a password protected bucket.

          jdillon Jeff Dillon (Inactive) added a comment - I have confirmed that the 2.2.2.5 VF works as expected for both sync and async query requests on a password protected bucket.

          People

            jdillon Jeff Dillon (Inactive)
            jmorris Jeff Morris
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty