Cant Authenticate Localhost with .NET SDK in .NET Core 3.1

I’m running couchbase locally on docker. I can connect to web ui fine on http://localhost:8091/. I cannot connect from the SDK. My project is .NET core 3.1 Couchbasenetclient 2.7.16. I also tried downgrading the nuget package as low as 2.5.

I have tried every combination of http://localhost:8091 as well as 127.0.0.1:8091 and /pools. It will not connect. Originally i was trying .openBucket with the SASLPASSWORD. But now i am just using the following code to try and connect to the cluster. The user i created when i set up the cluster is “administrator” but i also created an “admin” user from the security tab and have tried connecting with both credentials.

    var cluster = new Cluster(new ClientConfiguration
            {
                Servers = new List<Uri> { new Uri(" http://localhost:8091") }
            });
            cluster.Authenticate("administrator", "administrator");

            var manager = cluster.CreateManager();
            var userResult = manager.GetUser(AuthenticationDomain.Local, "admin");
            var user = userResult.Value;

            Console.WriteLine(user.Name);
            Console.WriteLine(user.Domain);
            Console.WriteLine(user.Roles);

            cluster.Dispose();

The error seems actually related to javascript parsing??

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ‘Couchbase.Configuration.Server.Serialization.Settings’ because the type requires a JSON object (e.g. {“name”:“value”}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {“name”:“value”}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path ‘settings’, line 1, position 102.

Callstack:
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.DownLoadConfig[T](Uri uri)
at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.DownloadConfigs(Uri server)
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate)
at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.Initialize()
at Couchbase.Cluster.CreateManager(String username, String password)
at Couchbase.Cluster.CreateManager()
at CouchTest.Program.Main(String args) in D:\projects\CouchTest\CouchTest\Program.cs:line 21

I get this same error regardless of how i modify the code to try and connect. Any help appreciated

@jasongerstorff

I run locally on Docker all the time. What ports are you mapping to localhost? It requires more than just 8091, Couchbase Server uses different ports for different services. For a basic app (no SSL, etc) I map 8091-8096 and 11210.

I didn’t map any ports manually i just took the defaults. Hostname is “172.17.0.2:8091” and the other ports showing are

ports: {

  • direct: 11210,
  • httpsCAPI: 18092,
  • httpsMgmt: 18091,
  • distTCP: 21100,
  • distTLS: 21150
    }

All of the examples i’ve seen show connecting the sdk to 8091 including

https://hub.docker.com/_/couchbase

https://docs.couchbase.com/dotnet-sdk/2.7/start-using-sdk.html

For there record, I can connect to our actual hosted couchbase instances from the sdk, i just can’t connect to my local instance from the sdk. The local web ui works for me.

Perhaps there is a firewall blocking ports somewhere?

Any time you’re having connectivity issues, it’d be good to diagnostically check for lower level details with SDK doctor. It may not find anything, but it will validate that common connectivity problems aren’t there.

You’ll find pre-built binaries on the release page.

Usually the summary at the end is pretty easy to interpret. If you need help with interpretation, please feel free to post it or a link to it here.

@jasongerstorff I think your issue is that you need connectivity from the SDK to the Couchbase Server on more than just port 8091. That port is used for initial bootstrapping and the management API, but after that the SDK connects to other ports (including for authentication).

Try launching your Docker image like this:

docker run -p 8091-8096:8091-8096 -p 11210:11210 couchbase/server:enterprise-6.5.0

As mentioned before, there are more ports you could map for some other features, but this baseline gets you what most people normally need. Also, you can easily change the version tag on the image, of course, I just wrote this example using the latest enterprise release.

And, as mentioned by Matt, if this doesn’t work I’d try running the SDK doctor. However, make sure you don’t run it using Docker. To properly verify behaviors, it needs to be running from the same environment you’re trying to connect from. So I’d run it directly in your OS environment.

That is the docker command I ran, i tried connecting to different 809* ports, it didn’t work. If i use 11210 the CreateManager() method won’t fail like it does with the 809* ports…it seems it authenticated, but then it won’t pull back any users. And I still can’t open a bucket after that with or without the sasl pass as a parameter. I’ve tried using the top level administrator account to authenticate, as well as a couple of users i set up.

I’ll try the SDK doctor and post back.

It says invalid bucket name/password. But that is 100% the correct bucket name. I tried using the credentials as well.

>sdk-doctor diagnose couchbase://127.0.0.1/tms_messaging

Note: Diagnostics can only provide accurate results when your cluster
is in a stable state. Active rebalancing and other cluster configuration
changes can cause the output of the doctor to be inconsistent or in the
worst cases, completely incorrect.

10:41:43.879 INFO :arrow_forward: Parsing connection string couchbase://127.0.0.1/tms_messaging
10:41:43.882 INFO :arrow_forward: Connection string identifies the following CCCP endpoints:
10:41:43.882 INFO :arrow_forward: 1. 127.0.0.1:11210
10:41:43.883 INFO :arrow_forward: Connection string identifies the following HTTP endpoints:
10:41:43.883 INFO :arrow_forward: 1. 127.0.0.1:8091
10:41:43.884 INFO :arrow_forward: Connection string specifies bucket tms_messaging
10:41:43.885 WARN :arrow_forward: Your connection string specifies only a single host. You should consider adding additional static nodes from your cluster to this list to improve your applications fault-tolerance
10:41:43.885 INFO :arrow_forward: Performing DNS lookup for host 127.0.0.1
10:41:43.886 INFO :arrow_forward: Attempting to connect to cluster via CCCP
10:41:43.887 INFO :arrow_forward: Attempting to fetch config via cccp from 127.0.0.1:11210
10:41:43.895 ERRO :arrow_forward: Failed to fetch configuration via cccp from 127.0.0.1:11210 (error: invalid bucket name/password)
10:41:43.895 INFO :arrow_forward: Attempting to connect to cluster via HTTP (Terse)
10:41:43.895 INFO :arrow_forward: Attempting to fetch terse config via http from 127.0.0.1:8091
10:41:43.900 ERRO :arrow_forward: Failed to fetch terse configuration via http from 127.0.0.1:8091 (error: http error (status code: 404))
10:41:43.900 INFO :arrow_forward: Attempting to connect to cluster via HTTP (Full)
10:41:43.901 INFO :arrow_forward: Failed to connect via HTTP (Full), as it is not yet supported by the doctor
10:41:43.902 INFO :arrow_forward: Selected the following network type:
10:41:43.903 ERRO :arrow_forward: All endpoints specified by your connection string were unreachable, further cluster diagnostics are not possible
10:41:43.903 INFO :arrow_forward: Diagnostics completed

Summary:
e[33m[WARN]e[0m Your connection string specifies only a single host. You should consider adding additional static nodes from your cluster to this list to improve your applications fault-tolerance
e[31m[ERRO]e[0m Failed to fetch configuration via cccp from 127.0.0.1:11210 (error: invalid bucket name/password)
e[31m[ERRO]e[0m Failed to fetch terse configuration via http from 127.0.0.1:8091 (error: http error (status code: 404))
e[31m[ERRO]e[0m All endpoints specified by your connection string were unreachable, further cluster diagnostics are not possible

Found multiple issues, see listing above.

Hello jasongerstorff,

  1. Do you use 1-node or 3-node docker image variant?
  2. The probliem is reproduced with quick-install example? (https://docs.couchbase.com/server/6.5/getting-started/do-a-quick-install.html)

I actually used the command on docker hub, its the same port mapping, it does use a -d option not the -t i don’t know if that matters.

I’m not entirely sure what image variant I’m using, the image is 5008c. There is only one node running under servers. Again, i can access the web console just fine when the container is running, i just cannot connect from the sdk.

I tried multiple versions of the .NET sdk including the 3.0 beta.

I’m pretty sure if you see this, there would be more information in the memcached.log on the cluster side.

This one doesn’t make much sense (unless it’s a bug in sdk-doctor?). If you’re getting the UI at that same ip/host, then the terse URL must be there. Maybe you can try a quick curl to that URI and see if the headers indicate it’s Couchbase Server. For example with my server:

$ curl -i -u ingenthr http://ingenthr@centos7-2:8091/poo
ls/default
Enter host password for user 'ingenthr':
HTTP/1.1 200 OK
X-XSS-Protection: 1; mode=block
X-Permitted-Cross-Domain-Policies: none
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Server: Couchbase Server
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Date: Fri, 03 Apr 2020 03:08:36 GMT
Content-Type: application/json
Content-Length: 4538
Cache-Control: no-cache,no-store,must-revalidate

{"name":"default","nodes":[{"systemStats":{"cpu_utilization_rate":6.068601583113456,"cpu_stolen_rate":0,"swap_total":1073737728,"swap_used":0,"mem_total":6089273344,"mem_free":3358773248,"mem_limit":6089273344,"cpu_cores_available":4},"interestingStats":{"cmd_get":0,"couch_docs_actual_disk_size":43115365,"couch_docs_data_size":34767917,"couch_spatial_data_size":0,"couch_spatial_disk_size":0,"couch_views_actual_disk_size":0,"couch_views_data_size":0,"curr_items":31592,"curr_items_tot":31592,"ep_bg_fetched":0,"get_hits":0,"mem_used":81419536,"ops":0,"vb_active_num_non_resident":0,"vb_replica_curr_items":0},"uptime":"774953","memoryTotal":6089273344,"memoryFree":3358773248,"mcdMemoryReserved":4645,"mcdMemoryAllocated":4645,"couchApiBase":"http://192.168.1.211:8092/","couchApiBaseHTTPS":"https://192.168.1.211:18092/","clusterMembership":"active","recoveryType":"none","status":"healthy","otpNode":"ns_1@127.0.0.1","thisNode":true,"hostname":"192.168.1.211:8091","nodeUUID":"6a3f6b6362665ed0a00308241976580d","clusterCompatibility":393221,"version":"6.5.0-4960-enterprise","os":"x86_64-unknown-linux-gnu","cpuCount":4,"ports":{"direct":11210,"httpsCAPI":18092,"httpsMgmt":18091,"distTCP":21100,"distTLS":21150},"services":["cbas","eventing","fts","index","kv","n1ql"],"nodeEncryption":false,"configuredHostname":"127.0.0.1:8091","addressFamily":"inet","externalListeners":[{"afamily":"inet","nodeEncryption":false},{"afamily":"inet6","nodeEncryption":false}]}],"buckets":{"uri":"/pools/default/buckets?v=60658837&uuid=cd92231250634c514557f0cd25970c2f","terseBucketsBase":"/pools/default/b/","terseStreamingBucketsBase":"/pools/default/bs/"},"remoteClusters":{"uri":"/pools/default/remoteClusters?uuid=cd92231250634c514557f0cd25970c2f","validateURI":"/pools/default/remoteClusters?just_validate=1"},"alerts":[],"alertsSilenceURL":"/controller/resetAlerts?uuid=cd92231250634c514557f0cd25970c2f&token=0","controllers":{"addNode":{"uri":"/controller/addNodeV2?uuid=cd92231250634c514557f0cd25970c2f"},"rebalance":{"uri":"/controller/rebalance?uuid=cd92231250634c514557f0cd25970c2f"},"failOver":{"uri":"/controller/failOver?uuid=cd92231250634c514557f0cd25970c2f"},"startGracefulFailover":{"uri":"/controller/startGracefulFailover?uuid=cd92231250634c514557f0cd25970c2f"},"reAddNode":{"uri":"/controller/reAddNode?uuid=cd92231250634c514557f0cd25970c2f"},"reFailOver":{"uri":"/controller/reFailOver?uuid=cd92231250634c514557f0cd25970c2f"},"ejectNode":{"uri":"/controller/ejectNode?uuid=cd92231250634c514557f0cd25970c2f"},"setRecoveryType":{"uri":"/controller/setRecoveryType?uuid=cd92231250634c514557f0cd25970c2f"},"setAutoCompaction":{"uri":"/controller/setAutoCompaction?uuid=cd92231250634c514557f0cd25970c2f","validateURI":"/controller/setAutoCompaction?just_validate=1"},"clusterLogsCollection":{"startURI":"/controller/startLogsCollection?uuid=cd92231250634c514557f0cd25970c2f","cancelURI":"/controller/cancelLogsCollection?uuid=cd92231250634c514557f0cd25970c2f"},"replication":{"createURI":"/controller/createReplication?uuid=cd92231250634c514557f0cd25970c2f","validateURI":"/controller/createReplication?just_validate=1"}},"rebalanceStatus":"none","rebalanceProgressUri":"/pools/default/rebalanceProgress","stopRebalanceUri":"/controller/stopRebalance?uuid=cd92231250634c514557f0cd25970c2f","nodeStatusesUri":"/nodeStatuses","maxBucketCount":30,"autoCompactionSettings":{"parallelDBAndViewCompaction":false,"databaseFragmentationThreshold":{"percentage":30,"size":"undefined"},"viewFragmentationThreshold":{"percentage":30,"size":"undefined"},"indexCompactionMode":"circular","indexCircularCompaction":{"daysOfWeek":"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday","interval":{"fromHour":0,"toHour":0,"fromMinute":0,"toMinute":0,"abortOutside":false}},"indexFragmentationThreshold":{"percentage":30}},"tasks":{"uri":"/pools/default/tasks?v=125884245"},"counters":{},"indexStatusURI":"/indexStatus?v=95157281","checkPermissionsURI":"/pools/default/checkPermissions?v=wjLpN8A%2BlsYmFY2MNJ8sKpQw2kg%3D","serverGroupsUri":"/pools/default/serverGroups?v=52184775","clusterName":"ingenthr-centos7-2","balanced":true,"memoryQuota":2138,"indexMemoryQuota":512,"ftsMemoryQuota":512,"cbasMemoryQuota":1365,"eventingMemoryQuota":256,"storageTotals":{"ram":{"total":6089273344,"quotaTotal":2241855488,"quotaUsed":373293056,"used":4830691328,"usedByData":81419536,"quotaUsedPerNode":373293056,"quotaTotalPerNode":2241855488},"hdd":{"total":10433642496,"quotaTotal":10433642496,"used":521682124,"usedByData":43115365,"free":9911960372}}}