【问题标题】:CouchDB replication - Unauthorized to access or create databaseCouchDB 复制 - 未经授权访问或创建数据库
【发布时间】:2015-10-26 14:49:14
【问题描述】:

我正在尝试设置 CouchDB 数据库复制,但两者都无法通过 Futon 和 cURL/CLI 工作:在这两种情况下都会出现以下错误消息:

{"error":"unauthorized","re​​ason":"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"

目标数据库通过用户名和密码进行保护,对于 HTTP 基本身份验证,我添加了凭据,如您所见。当我通过 Futon 创建复制文档时出现同样的错误。

感谢您的帮助。

【问题讨论】:

  • 谁能帮忙解决这个问题?

标签: authentication couchdb replication


【解决方案1】:

有点晚了,但我认为你需要它。

(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
}

“Basic”后面的 base64 字符串是以下内容的输出:

  • echo -n '用户名:密码' | base64(https://example.net:5984 中数据库 table1 的用户名和密码。
  • 非常重要:当您发送请求时,您会将其发送到一个 url。目标也应该是您将复制的数据库的名称 "target":"http://server:5984/table1" -->> table1
  • 用于发送此复制的请求标头也应包含基本令牌。 (目标数据库的管理员用户名和密码或超级管理员密码)

简历

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:用户名:密码(base64)

  • username2:password2 : 数据库 target1 的管理员名称和密码(http://server:5984)

  • username:password : 数据库 target1 的管理员名称和密码(127.0.0.1:5984)

【讨论】:

  • 这个答案解决了我多年来 POST 到 _replicator 的问题,我没有意识到我收到了“未经授权”的回复。在使用 "headers":{"Authorisation":"Basic dfdfg..."} 沙发时正确执行复制。 Couch 不接受普通用户名:密码。干得好。
猜你喜欢
  • 1970-01-01
  • 2012-01-14
  • 2015-03-05
  • 1970-01-01
  • 2020-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多