0

I'm facing a very odd problem that I can't use any user inside (_users) database to create a session through the route (/_session). It's always giving me error (bad credentials). It used to work fine in couchdb 1.6.1

For normal couchdb adminstrators, it works fine :

$ curl -X POST http://localhost:5984/_session -d 'name=my_main_admin&password=******'
{"ok":true,"name":"my_main_admin","roles":["_admin"]}

However for couchdb users (stored in _users), it doesn't work. I don't think it's about the roles.

So I first create the user :

$ curl -s -H "Content-Type: application/json" -X PUT "http://my_main_admin:*****@127.0.0.1:5984/_node/_local/_users/org.couchdb.user:my_new_user" --data '{"name": "my_new_user", "password": "my_new_user", "roles": [], "type": "user"}'
{"ok":true,"id":"org.couchdb.user:my_new_user","rev":"1-f1fa0870666d17d7324e54128dfbcacb"}

Then if I try to use this user to create a session, it never works :

$ curl -X POST http://localhost:5984/_session -d 'name=my_new_user&password=my_new_user' {"error":"unauthorized","reason":"Name or password is incorrect."}

My CouchDB config looks fine :

"couch_httpd_auth": {
"allow_persistent_cookies": "true",
"auth_cache_size": "50",
"authentication_db": "_users",
"authentication_redirect": "/_utils/session.html",
"iterations": "10",
"require_valid_user": "false"

I used to create sessions with normal users on couchdb 1.6.1 , but it has never worked since I installed couchdb 3.1.1 . I can't find any relevant info in the documentation. Am I missing something?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Aproram
  • 348
  • 1
  • 3
  • 16

1 Answers1

2

The problem is that you are creating the user through the _node/_local interface. The user should be created via the clustered API on the _users clustered database.

    $ curl -s -H "Content-Type: application/json" -X PUT \
  "http://my_main_admin:*****@127.0.0.1:5984/_users/org.couchdb.user:my_new_user" \
 --data '{"name": "my_new_user", "password": "my_new_user", "roles": [], "type": "user"}' \
    /

Now you should be able to log in with the new user using the _session endpoint.

Juanjo Rodriguez
  • 2,103
  • 8
  • 19
  • Perfect! that is the key answer here! Calling the right interface fixed the whole thing, thanks a lot! – Aproram May 22 '21 at 11:44