Can't Authenticate via Node SDK


#1

I am using the code below. It connects just fine to our shared dev server, but I am trying to connect to a couchbase instance on my local machine. The local connection does not work, even tho the same username and password works to connect via CBQ.

Error:
Can not open bucket { CouchbaseError: Authentication failed. You may have provided an invalid username/password combination
message: ‘Authentication failed. You may have provided an invalid username/password combination’,
code: 2 }

I have tried multiple things

  • changing the server string to ‘couchbase://localhost’, ‘http://localhost:8091’ and many more variations
  • adding a blank password behind the cluster.openBucket() statement
  • using curl to get the saslPassword and using that in the cluster.openBucket() statement. (i get this error: Error: You must not specify a bucket password when using cluster-level authentication.)

Can u provide some direction please?

Thanks!

CBQ

     ~/Applications/Couchbase\ Server.app/Contents/Resources/couchbase-core/bin/cbq \
 -u ab -p test1234 \
 -q -e http://localhost:8091

Code

// const config = require('../../config/default');
const couchbase = require('couchbase');

const config = {
  db: {
    bucket: 'ab',
    dbServer: 'couchbase://localhost/',
    options: 'detailed_errcodes=1',
    password: 'test1234',
    user: 'ab',
  },
};

const { bucketName, dbServer, options, password, user } = config.db;

console.log(JSON.stringify({ bucketName, dbServer, options, password, user }, null, 4));

const cluster = new couchbase.Cluster(dbServer);

cluster.authenticate(user, password);

const bucket = cluster.openBucket(bucketName);

bucket.on('error', (err) => {
  if (err) {
    console.log('Can not open bucket', err);
    process.exit(70);
  }
  console.log('Successfully opened bucket');
});

#2

Hey @roy.a.rico,
Could you let us know what server version you are using for your application? Our authentication behaviour has changed around the 5.x period, and thus if you are using an earlier version you will need to use bucket authentication, whereas 5.x+ you would use cluster-level authentication.
Cheers, Brett


#3

@brett19 Thanks for the quick reply
Local Machine: Version 5.1.1 (5.1.1-5723)
Dev Server: Enterprise Edition 5.1.0 build 5552


#4

Hey @roy.a.rico,
It looks like you are using a server with cluster-level authentication, but are attempting to use bucket-level authentication from the SDK. You will need to setup a user on your cluster (or use one of the predefined users, such as Administrator) in your cluster.authenticate call. The users are then granted access to individual buckets through the UI and a password is no longer needed on the cluster.openBucket call.
Cheers, Brett


#5

Thanks for the reply, and sorry for my slow delay. I do have a user created for this bucket and still am having issues. I also ran SDK dr on my local machine. Any more ideas?

  $ ./sdk-doctor-macos diagnose couchbase://localhost/ab -u ab -p test1234

|====================================================================|
|          ___ ___  _  __   ___   ___   ___ _____ ___  ___           |
|         / __|   \| |/ /__|   \ / _ \ / __|_   _/ _ \| _ \          |
|         \__ \ |) | ' <___| |) | (_) | (__  | || (_) |   /          |
|         |___/___/|_|\_\  |___/ \___/ \___| |_| \___/|_|_\          |
|                                                                    |
|====================================================================|

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.

13:05:01.540 INFO ▶ Parsing connection string `couchbase://localhost/ab`
13:05:16.734 INFO ▶ Connection string identifies the following CCCP endpoints:
13:05:16.734 INFO ▶   1. localhost:11210
13:05:16.734 INFO ▶ Connection string identifies the following HTTP endpoints:
13:05:16.734 INFO ▶   1. localhost:8091
13:05:16.734 INFO ▶ Connection string specifies bucket `ab`
13:05:16.734 WARN ▶ 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
13:05:16.734 INFO ▶ Performing DNS lookup for host `localhost`
13:05:16.734 WARN ▶ Bootstrap host `localhost` has more than one single DNS entry associated.  While this is not neccessarily an error, it has been known to cause difficult-to-diagnose problems in the future when routing is changed or the cluster layout is updated.
13:05:16.735 INFO ▶ Bootstrap host `localhost` has IPv6 addresses associated. This is only supported in Couchbase Server 5.5 or later, and must be specifically enabled on the cluster.
13:05:16.735 INFO ▶ Attempting to connect to cluster via CCCP
13:05:16.735 INFO ▶ Attempting to fetch config via cccp from `localhost:11210`
13:05:16.737 INFO ▶ Identified the following nodes:
13:05:16.737 INFO ▶   [0] localhost
13:05:16.737 INFO ▶                     moxi: 11211,            indexScan:  9101,     indexStreamMaint:  9105
13:05:16.737 INFO ▶               indexHttps: 19102,                kvSSL: 11207,                 n1ql:  8093
13:05:16.737 INFO ▶                  mgmtSSL: 18091,           indexAdmin:  9100,              capiSSL: 18092
13:05:16.737 INFO ▶                projector:  9999,            indexHttp:  9102,   indexStreamCatchup:  9104
13:05:16.737 INFO ▶                       kv: 11210,              n1qlSSL: 18093,                 capi:  8092
13:05:16.737 INFO ▶                     mgmt:  8091,                  fts:  8094,               ftsSSL: 18094
13:05:16.737 INFO ▶          indexStreamInit:  9103
13:05:16.737 INFO ▶ Fetching config from `localhost:8091`
13:05:16.739 INFO ▶ Failed to retreive cluster information (status code: 401)
13:05:16.740 INFO ▶ Successfully connected to KV service at `localhost:11210`
13:05:16.743 INFO ▶ Successfully connected to MGMT service at `localhost:8091`
13:05:16.765 INFO ▶ Successfully connected to CAPI service at `localhost:8092`
13:05:16.766 INFO ▶ Successfully connected to N1QL service at `localhost:8093`
13:05:16.767 INFO ▶ Successfully connected to FTS service at `localhost:8094`
13:05:16.768 INFO ▶ Memd Nop Pinged `localhost:11210` 10 times, 0 errors, 0ms min, 0ms max, 0ms mean
13:05:16.768 INFO ▶ Diagnostics completed

Summary:
[WARN] 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
[WARN] Bootstrap host `localhost` has more than one single DNS entry associated.  While this is not neccessarily an error, it has been known to cause difficult-to-diagnose problems in the future when routing is changed or the cluster layout is updated.

Found multiple issues, see listing above.