10
votes

I'm following the couchdb security documentation (http://docs.couchdb.org/en/1.6.1/intro/security.html) to try to create a server-admin using cURL: curl -X PUT $HOST/_config/admins/anna -d '"secret"'

When I do this, I get an error: {"error":"not_found","reason":"Database does not exist."}

I'm on v2.0 so I don't known if something has changed since the 1.6 version of the documentation. I can create server-admins just fine using fauxton. Any ideas?

3

3 Answers

18
votes

To anybody else running into this issue, it's an easy answer: in couchdb 2.0 some of the APIs moved to using port 5986 ... I had been using port 5984 (which is still used a lot in v2.0, but apparently not for the _config endpoint).

The following works:

curl -X PUT http://localhost:5986/_config/admins/admin1 -d '"password"'
5
votes

The Couchdb2 way of adding a user is

curl -X PUT http://localhost:5984/_node/nodename/_config/admins/admin1 -d '"password"'
1
votes

In the GUI, you can find out that you need to set up a single node cluster, and when you do that you specify the admin username and password.

And you can do the same thing using an API endpoint that you can POST to:
http://docs.couchdb.org/en/2.1.0/api/server/common.html#post--_cluster_setup

With 2.0 using enable_single_node returned {"error":"bad_request","reason":"Invalid Action'"} so I reverted to doing:

j=$(cat <<EOF
{
  "action": "enable_cluster",
  "bind_address": "0.0.0.0",
  "username": "admin",
  "password": "$PASS",
  "port": "5984",
  "node_count":"1"
} 
EOF
)

curl  -s -X POST -H "Content-Type: application/json" http://$IP/_cluster_setup -d "$j"
curl  -s -X POST -H "Content-Type: application/json" $URI/_cluster_setup -d '{"action": "finish_cluster"}'