J Chadwick
J Chadwick

Reputation: 15

"Name or password is incorrect" for couch_peruser on Cloud but localhost works

I have Couchdb installed locally on Windows, localhost:5984 and on Google Cloud, 104.197.185.97:5984. I reviewed the local.ini and also settings via Fauxton. I run code to create a user with one database per user, the setting is [couch_peruser] enable = true.

I create the Couchdb user (and the database is automatically created, for example userdb-70706333) in Laravel/php (see below) and using my Windows curl here as a test, I can connect to the specific user's database as an admin:

curl -X GET http://adminUserName:adminPassword@localhost:5984/userdb-70706333
curl -X GET http://adminUserName:[email protected]:5984/userdb-70706333

Yet I get an error "unathorized" reason: "Name or password is incorrect" for Google cloud server - why? (First line works, second line gives this error)

curl -X GET http://userName:userPassword@localhost:5984/userdb-70706333
curl -X GET http://userName:[email protected]:5984/userdb-70706333

The local.ini files are almost identical: Both have:

[couch_peruser]
delete_dbs = true
enable = true
[chttpd]
port=5984
bind_address=0.0.0.0
require_valid_user=true
authentication_handlers = 
WWW-Authenticate=Basic realm="Administrator"
enable_cors = true
authentication_handlers = {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, proxy_authentication_handler}, {couch_httpd_auth, default_authentication_handler}
[couch_httpd_auth]
require_valid_user=true
allow_persistent_cookies = true
proxy_use_secret = 
timeout = 6000
[ssl]
port=6984
[cors]
origins = *
credentials = true
methods = GET, PUT, POST, HEAD, DELETE
headers = accept, authorization, content-type, origin, referer

Differences: Google cloud server:

[couchdb]
database_dir=/opt/bitnami/couchdb/var/lib/couchdb
view_index_dir=/opt/bitnami/couchdb/var/lib/couchdb
plugin_dir=/opt/bitnami/couchdb/lib/couchdb/plugins

Local:

[couchdb]
database_dir=./data
view_index_dir=./data

My Laravel/php code to create the couchdb/user:

curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
    $data_array = array(
        "name" => (string)($user_name),
        "password" => (string)($user_password),
        "roles" => ["users"],
        "type" => (string)("user")
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$url = 'http://' . $admin_user_name . ':' . $admin_user_password . '@'.$remoteDbIP.'/_users/org.couchdb.user:' . $user_name;
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'Accept: application/json',
        'Content-Type: application/json',
    ));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_exec($curl);

So I call this from javascript:

var completeRemoteDbUrl = 'http://' + userName + ':' + userPassword + '@' + remoteDbUrl;
console.log("completeRemoteDbUrl:" + completeRemoteDbUrl);
var theRemoteDb = new PouchDB(completeRemoteDbUrl, {revs_limit: 1});

completeRemoteDbUrl value is For local:

http://ppc1:jqW1iR370706331@localhost:5984/userdb-70706331

For remote:

http://ppc1:[email protected]:5984/userdb-70706331

So I tried both from curl and tried uploading the code to my cloudways server and both give me the same result "Name or password is incorrect". Got a feeling it is something simple. Thanks.

Upvotes: 0

Views: 1281

Answers (1)

J Chadwick
J Chadwick

Reputation: 15

The answer is to open up a tunnel on the source server, which is the server you are calling the couchDB from. On my server that hosts couchDB, the key file is already created and you download that one (note *.pem is the linux one, *.ppk is the Windows one). Upload the key file to the source server, not the keyfile location and to open the tunnel run: ssh -N -L SOURCE-PORT:127.0.0.1:DESTINATION-PORT -i KEYFILE-LOCATION DESTINATION-USERNAME@DESTINATION-SERVER-IP Ctl-z out and run: Then check it works with wget http://127.0.0.1:SOURCE-PORT/ Now I am figuring out how to keep the process running after I sign off my SSH connection to my source server. fuser looks good.

Upvotes: 0

Related Questions