Authentication exception when opening memcached bucket with password from ClientConfiguration

Description

If you try to open a password protected memcached bucket with a configuration containing the password (but only when you call OpenBucket(name) and not OpenBucket(name, password), the client will throw an exception as follows:

System.AggregateException : Could not bootstrap - check inner exceptions for details.

----> Couchbase.Configuration.ConfigException : is this a Memcached bucket?

If you look at the logs you'll find it's really a WebException with a response of unauthorized:

2015-02-17 10:17:12,583 [Runner thread] ERROR Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig - Bootstrapping failed from http://192.168.27.102:8091/pools: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.DownLoadConfig[T](Uri uri) in c:\jenkins\workspace-net2\couchbase-net-client\Src\Couchbase\Configuration\Server\Providers\Streaming\HttpServerConfig.cs:line 115
at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.DownloadConfigs(Uri server) in c:\jenkins\workspace-net2\couchbase-net-client\Src\Couchbase\Configuration\Server\Providers\Streaming\HttpServerConfig.cs:line 62

Environment

None

Gerrit Reviews

None

Release Notes Description

None

Activity

Show:

Simon Baslé February 20, 2015 at 11:29 AM

is similar, but in ClusterHelper

Jeffry Morris February 17, 2015 at 6:38 PM

A work around is to explicitly provide the password when opening the bucket:

var config = new ClientConfiguration
{
Servers = new List<Uri>
{
new Uri("http://192.168.27.101:8091/pools"),
new Uri("http://192.168.27.102:8091/pools"),
new Uri("http://192.168.27.103:8091/pools")
},
BucketConfigs = new Dictionary<string, BucketConfiguration>
{
{
"default",
new BucketConfiguration
{
BucketName = "distributed_cache",
Password = "secret"
}
}
}
};

var cluster = new Cluster(config);
var bucketName = config.BucketConfigs.Single().Value.BucketName;
var bucket = cluster.OpenBucket(bucketName);
var result = bucket.Get<string>("some_key", "secret");

Jeffry Morris February 17, 2015 at 6:38 PM

Will not work:

var config = new ClientConfiguration
{
Servers = new List<Uri>
{
new Uri("http://192.168.27.101:8091/pools"),
new Uri("http://192.168.27.102:8091/pools"),
new Uri("http://192.168.27.103:8091/pools")
},
BucketConfigs = new Dictionary<string, BucketConfiguration>
{
{
"default",
new BucketConfiguration
{
BucketName = "distributed_cache",
Password = "secret"
}
}
}
};

var cluster = new Cluster(config);
var bucketName = config.BucketConfigs.Single().Value.BucketName;
var bucket = cluster.OpenBucket(bucketName);
var result = bucket.Get<string>("some_key");

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created February 17, 2015 at 6:36 PM
Updated March 4, 2015 at 1:21 AM
Resolved February 25, 2015 at 11:42 AM
Instabug