Couchdb: {"error":"unauthorized","reason":"Name or password is incorrect."} even if access is granted to user

Created on 20 Jun 2017  路  10Comments  路  Source: apache/couchdb

I was following the authorization topic mentioned in below link
http://docs.couchdb.org/en/2.0.0/intro/security.html
created an user using endpoints port 5986, then executed APIs as per documentation for e.g.
curl -X PUT http://localhost:5984/eventdb/_security -u admin:* -H "Content-Type: application/json" -d '{"admins": { "names": [], "roles": [] }, "members": { "names": ["fan"], "roles": [] } }'
please note password is hidden for obvious purpose

which returns below result for me

{"ok":true}

Now when I tried to access database using below api

curl -u fan:apple http://localhost:5984/eventdb

it results below response for me
{"error":"unauthorized","reason":"Name or password is incorrect."}

I am pretty much sure about name and password here.

I am novice to couchdb however believe that porting _users to 5986 might have resulted this issue

Please note I am using couchdb 2.0.0

Most helpful comment

Ooooo
thanks for your help. I should have contacted you first. Any way thanks again. Much appreciated.

Regards,
Suhas

All 10 comments

This is not a bug.

You should be doing everything with CouchDB using port 5984. The only thing that should be done via port 5986 is cluster setup tasks as explicitly outlined in our documentation.

Thanks for your response.
However I tried following API on 5984
curl -X PUT http://admin:*@localhost:5984/_users/org.couchdb.user:dan -H "Accept: application/json" -H "Content-Type: application/json" -d '{"name": "dan", "password": "apple", "roles": [], "type": "user"}'

it results in below message
{"error":"not_found","reason":"Database does not exist."}

Same was working on port 5986. Not able to understand what is the issue with port 5984

You need to run all of your commands against port 5984. That error says your database was not created through the clustered interface.

If you are upgrading from couchdb 1.x you can migrate your database with these steps: http://docs.couchdb.org/en/latest/install/upgrading.html

thanks again.
It was a fresh installation of couchdb 2.0.0, so there was no upgrade. I am using MAC, do you think re-installing couchdb will solve this problem.

Regards,
Suhas

No need to reinstall. Just start over with:

curl -X PUT http://localhost:5984/eventdb

to create your database first.

Thank you.

Started over, deleted eventdb and recreated one, however same issue exists. Added _security document to eventdb and assign an user to it and when tried
curl -u fan:apple http://localhost:5984/eventdb

it results in

{"error":"unauthorized","reason":"Name or password is incorrect."}

Can you paste the _entire_ set of things that you try? Is your user:password that you show there a CouchDB admin (listed in [admins] section of local.ini?)

Hi,
Objective : is to create an user which will be in _users collection and then provide eventdb member access to the user.

things I tried out

  1. For adding user

curl -X PUT http://admin:*@localhost:5984/_users/org.couchdb.user:dan -H "Accept: application/json" -H "Content-Type: application/json" -d '{"name": "dan", "password": "apple", "roles": [], "type": "user"}'

which results in below message
{"error":"not_found","reason":"Database does not exist."}

I searched on google for this error and come to know that system collection like _users are moved to port 5986 hence I fired below api

curl -X PUT http://admin:*@localhost:5986/_users/org.couchdb.user:dan -H "Accept: application/json" -H "Content-Type: application/json" -d '{"name": "dan", "password": "apple", "roles": [], "type": "user"}'
I was able to create an user. (please note port number 5986)

  1. Provide eventdb member access to dan

I executed below command to provide an access
curl -X PUT http://localhost:5984/eventdb/_security -u admin:* -H "Content-Type: application/json" -d '{"admins": { "names": [], "roles": [] }, "members": { "names": ["dan"], "roles": [] } }'
which returns below result for me

{"ok":true}

  1. Accessing eventdb using dan's credential

curl -u dan:apple http://localhost:5984/eventdb

it results in
{"error":"unauthorized","reason":"Name or password is incorrect."}

I was following documentation at http://docs.couchdb.org/en/2.0.0/intro/security.html

thanks for your help.

Your step 1 talking to port 5986 to create a user is wrong - you got bad advice.

You need to first create the _users database on port 5984 as outlined in our setup documentation: http://docs.couchdb.org/en/latest/install/setup.html#single-node-setup

Once you have created the _users database through port 5984, repeat your step 1 to create your user on port 5984.

Then everything else should work normally.

Ooooo
thanks for your help. I should have contacted you first. Any way thanks again. Much appreciated.

Regards,
Suhas

Was this page helpful?
0 / 5 - 0 ratings