"LCB_AUTH_ERROR: Authentication failed" in Bitbucket Pipelines

Hi,

I’ve been debugging for days, but I can’t seem to find the issue. I’ve a PHP project that runs fine in my local development environment with a Couchbase Docker container, but fails consistently with a “LCB_AUTH_ERROR: Authentication failed” in Bitbucket Pipelines when trying to create a primary index, after the bucket have already been successfully created!

I’m using the official couchbase:community-6.6.0 image and I’m initializing the cluster with:

/opt/couchbase/bin/couchbase-cli cluster-init --cluster-name="ClusterName" --cluster-username="Administrator" --cluster-password="Administrator" --cluster-ramsize=4096 --services=data,index,query,fts

After that I’m creating the bucket via the PHP SDK v2.6.1 (simplified code):

$cluster = new Cluster('couchbase://127.0.0.1:8091');
$cluster->authenticate((new PasswordAuthenticator())->username('Administrator')->password('Administrator'));

$clusterManager = $cluster->manager();
$clusterManager->createBucket('bucketname', ['flushEnabled' => true, 'ramQuotaMB' => 100])

After the bucket is created, I’m waiting for all bucket nodes to become healthy. I even waited an additional 60 seconds, but it always fails at the next step…

In the step that fails I’m creating a primary index via the PHP SDK v2.6.1 (simplified code):

$cluster = new Cluster('couchbase://127.0.0.1:8091');
$cluster->authenticate((new PasswordAuthenticator())->username('Administrator')->password('Administrator'));

$bucket = $cluster->openBucket('bucketname');
$bucket->query(N1qlQuery::fromString('CREATE PRIMARY INDEX `#primary` ON `bucketname`'));

This always results in the following error:

Couchbase\Exception: LCB_AUTH_ERROR: Authentication failed. You may have provided an invalid username/password combination
[cb,EROR] (negotiation L:149 I:1050989077) <127.0.0.1:11210> (CTX=0x5593e805f6d0,sasl,SASLREQ=0x5593e805c8f0) Error: 0x2, SASL AUTH failed (ref: "045b1777-336e-4b2b-c1b4-175716b9024e")
[cb,EROR] (cccp L:165 I:1050989077) <NOHOST:NOPORT> (CTX=(nil),) Could not get configuration: LCB_AUTH_ERROR (0x02)
[cb,EROR] (bootstrap L:170 I:1050989077) Failed to bootstrap client=0x5593e8093440. Error=LCB_AUTH_ERROR (0x02), Message=No more bootstrap providers remain
[cb,EROR] (pcbc/pool L:110) Failed to bootstrap LCB connection: LCB_AUTH_ERROR: Authentication failed. You may have provided an invalid username/password combination. I=0x5593e8093440

And I don’t understand why… This whole setup works already fine for years, but now that I try to set this up in Bitbucket Pipelines, I consistently get this error.

I’ve also used couchbaselabs/sdk-doctor to figure out what the problem was, but it just repeats the same error:

+ ./sdk-doctor-linux diagnose couchbase://127.0.0.1/bucketname -u Administrator -p Administrator
|====================================================================|
|          ___ ___  _  __   ___   ___   ___ _____ ___  ___           |
|         / __|   \| |/ /__|   \ / _ \ / __|_   _/ _ \| _ \          |
|         \__ \ |) | ' <___| |) | (_) | (__  | || (_) |   /          |
|         |___/___/|_|\_\  |___/ \___/ \___| |_| \___/|_|_\          |
|                                                                    |
|====================================================================|
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.
07:10:00.039 INFO ▶ Parsing connection string `couchbase://127.0.0.1/bucketname`
07:10:00.039 INFO ▶ Connection string identifies the following CCCP endpoints:
07:10:00.039 INFO ▶   1. 127.0.0.1:11210
07:10:00.039 INFO ▶ Connection string identifies the following HTTP endpoints:
07:10:00.039 INFO ▶   1. 127.0.0.1:8091
07:10:00.039 INFO ▶ Connection string specifies bucket `bucketname`
07:10:00.039 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
07:10:00.039 INFO ▶ Performing DNS lookup for host `127.0.0.1`
07:10:00.039 INFO ▶ Attempting to connect to cluster via CCCP
07:10:00.039 INFO ▶ Attempting to fetch config via cccp from `127.0.0.1:11210`
07:10:00.039 ERRO ▶ Failed to fetch configuration via cccp from `127.0.0.1:11210` (error: invalid bucket name/password)
07:10:00.039 INFO ▶ Attempting to connect to cluster via HTTP (Terse)
07:10:00.039 INFO ▶ Attempting to fetch terse config via http from `127.0.0.1:8091`
07:10:00.041 INFO ▶ Selected the following network type: default
07:10:00.041 INFO ▶ Identified the following nodes:
07:10:00.041 INFO ▶   [0] 127.0.0.1
07:10:00.041 INFO ▶                projector:  9999,                 mgmt:  8091,                   kv: 11210
07:10:00.041 INFO ▶                     capi:  8092
07:10:00.041 WARN ▶ Your configuration was fetched via a non-optimal path, you should update your connection string and/or cluster configuration to allow CCCP config fetch
07:10:00.041 INFO ▶ Fetching config from `http://127.0.0.1:8091`
07:10:00.042 INFO ▶ Failed to retreive cluster information (status code: 404)
07:10:00.042 ERRO ▶ Failed to connect to Key Value service at `127.0.0.1:11210` (error: invalid bucket name/password)
07:10:00.054 INFO ▶ Successfully connected to Management service at `127.0.0.1:8091`
07:10:00.064 INFO ▶ Successfully connected to Views service at `127.0.0.1:8092`
07:10:00.064 WARN ▶ Could not test Query service on `127.0.0.1` as it was not in the config
07:10:00.064 WARN ▶ Could not test Search service on `127.0.0.1` as it was not in the config
07:10:00.064 WARN ▶ Could not test Analytics service on `127.0.0.1` as it was not in the config
07:10:00.068 WARN ▶ Failed to perform KV connection performance analysis on `127.0.0.1:11210` (error: %!d(string=invalid bucket name/password))
07:10:00.068 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] Your configuration was fetched via a non-optimal path, you should update your connection string and/or cluster configuration to allow CCCP config fetch
[WARN] Could not test Query service on `127.0.0.1` as it was not in the config
[WARN] Could not test Search service on `127.0.0.1` as it was not in the config
[WARN] Could not test Analytics service on `127.0.0.1` as it was not in the config
[WARN] Failed to perform KV connection performance analysis on `127.0.0.1:11210` (error: %!d(string=invalid bucket name/password))
[ERRO] Failed to fetch configuration via cccp from `127.0.0.1:11210` (error: invalid bucket name/password)
[ERRO] Failed to connect to Key Value service at `127.0.0.1:11210` (error: invalid bucket name/password)
Found multiple issues, see listing above.

Any help is appreciated!

Thanks,
Raymond

Is it possible to run a quick test with the latest PHP SDK and latest Server version?

Also, am I correct in reading that you’re re-authenticating to the cluster again before creating the index? Can you attempt to create the index using the same cluster object that you used to create the bucket? And then finally, are you able to perform any other operations (i.e. read/write a document)?

And in the latest PHP SDK there is support for a ping/healthcheck: Documentation

Ok, I’ve narrowed it down to the cluster NOT being initalised at all…

ERROR: Unable to connect to host at http://127.0.0.1:8091: HTTPConnectionPool(host='127.0.0.1', port=8091): Max retries exceeded with url: /pools (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7fe687b4aef0>: Failed to establish a new connection: [Errno 111] Connection refused'))

The weird thing tho is that it is actually creating the buckets “correctly”. If I asked for the list of buckets, the bucket I created is visible.

I’m going to investigate why I can’t initialize the cluster; it is probably due to my “wait for it” script.

Thanks!

There is nothing listening at at that address (127.0.0.1:8091). If you’ve started the couchbase server, check the logs as to why it is no longer running. Keep in mind that localhost (127.0.0.1) will only work when running from the same host and is generally not the address that should be used.

Also - setting the environment variable LCB_LOGLEVEL=5 will give more diagnostic information.

This topic was automatically closed after 90 days. New replies are no longer allowed.