DehMotth
DehMotth

Reputation: 689

CouchDB replication - Unauthorized to access or create database

I am trying to setup a CouchDB database replication but both is not working via Futon and cURL/CLI: It ends up with the following error message in both cases:

{"error":"unauthorized","reason":"unauthorized to access or create database table1"}

curl -X POST http://127.0.0.1:5984/_replicate -d '{"source": "table1",
"user_ctx": {"name": "", "roles": ["admin"]}, "target":   
"http://username:password@server:5984/table1", "create_target": false, 
"continuous": true}' -H "Content-Type: application/json"

The target database is secured via a username and password and for HTTP basic authentication i added the credentials as you can see. The same error appears when i create a replication document via Futon.

Thanks for your help.

Upvotes: 4

Views: 2944

Answers (1)

user6574009
user6574009

Reputation: 59

It is a little bit late but I think you need it.

(CouchDb 1.6.1)

https://wiki.apache.org/couchdb/Replication

POST /_replicate HTTP/1.1

{ 
    "source": {
        "url":"https://example.net:5984/table1",
        "headers":{
            "Authorization":"Basic Ym9iQGV4YW1wbGUuY29tOnBhc3N3b3Jk"
        }
    }, 
    "target":"target1", 
    "create_target": false, 
    "continuous": true
}

where the base64 string following the word "Basic" is the output of:

  • echo -n 'username:password' | base64 (username and password for database table1 in https://example.net:5984.
  • Very important : when you send your request you send it to an url. The target should also be the name of the database where you will replicated "target":"http://server:5984/table1" -->> table1
  • The request header you use to send this replication should contains the Basic token too. (a admin username and password or the superadmin password of the target database)

Resume

curl -X POST http://127.0.0.1:5984/_replicate 
-d '{ 
    "source": {
        "url":"https://example.net:5984/table1",
        "headers":{
            "Authorization":"Basic Ym9iQGV4YW1wbGUuY29tOnBhc3N3b3Jk"
        }
    }, 
    "target":"target1", 
    "create_target": false, 
    "continuous": true
}' -H "Authorization: Basic dXNlcm5hbWUyOnBhc3N3b3JkMg==;Content-Type: application/json"
  • dXNlcm5hbWUyOnBhc3N3b3JkMg== : username2:password2 (base64)
  • Ym9iQGV4YW1wbGUuY29tOnBhc3N3b3Jk : username:password (base64)

  • username2:password2 : admin name and password of the database target1 (on http://server:5984)

  • username:password : admin name and password of the database target1 (on 127.0.0.1:5984)

Upvotes: 5

Related Questions