3.6. 认证和授权¶
3.6.1. 服务器管理员¶
-
[admins]
¶
在 3.0.0 版更改: CouchDB需要一个管理帐户才能启动。如果尚未创建管理员帐户,CouchDB将打印一条错误消息并终止。
CouchDB服务器管理员和密码不存储在 _users
数据库,但在最后一个 [admins]
在加载其ini文件时CouchDB找到的部分。有关配置文件顺序和行为的详细信息,请参阅:配置:简介。此文件(可能类似于 /opt/couchdb/etc/local.ini
或 /opt/couchdb/etc/local.d/10-admins.ini
当CouchDB从软件包安装时)应该得到适当的保护,并且只有系统管理员才能读取:
[admins]
;admin = mysecretpassword
admin = -hashed-6d3c30241ba0aaa4e16c6ea99224f915687ed8cd,7f4a3e05e0cbc6f48a0035e3508eef90
architect = -pbkdf2-43ecbd256a70a3a2f7de40d2374b6c3002918834,921a12f74df0c1052b3e562a23cd227f,10000
管理员可以直接添加到 [admins]
当CouchDB重新启动时,密码将被保存并加密。您还可以使用HTTP接口来创建管理员帐户;这样,您就不需要重新启动CouchDB,也不需要临时以明文形式存储或传输密码。HTTP协议 /_node/{{node-name}}/_config/admins
终结点支持查询、删除或创建新的管理帐户:
GET /_node/nonode@nohost/_config/admins HTTP/1.1
Accept: application/json
Host: localhost:5984
HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 196
Content-Type: application/json
Date: Fri, 30 Nov 2012 11:37:18 GMT
Server: CouchDB (Erlang/OTP)
{
"admin": "-hashed-6d3c30241ba0aaa4e16c6ea99224f915687ed8cd,7f4a3e05e0cbc6f48a0035e3508eef90",
"architect": "-pbkdf2-43ecbd256a70a3a2f7de40d2374b6c3002918834,921a12f74df0c1052b3e562a23cd227f,10000"
}
如果已经有一个salt加密的密码字符串(例如,来自一个旧的ini文件,或者来自另一个CouchDB服务器),那么您可以存储“原始”加密字符串,而不需要CouchDB对其进行双重加密。
PUT /_node/nonode@nohost/_config/admins/architect?raw=true HTTP/1.1
Accept: application/json
Content-Type: application/json
Content-Length: 89
Host: localhost:5984
"-pbkdf2-43ecbd256a70a3a2f7de40d2374b6c3002918834,921a12f74df0c1052b3e562a23cd227f,10000"
HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 89
Content-Type: application/json
Date: Fri, 30 Nov 2012 11:39:18 GMT
Server: CouchDB (Erlang/OTP)
"-pbkdf2-43ecbd256a70a3a2f7de40d2374b6c3002918834,921a12f74df0c1052b3e562a23cd227f,10000"
有关详细信息,请参阅 security, including configuring the work factor for PBKDF2
, and the algorithm itself at PBKDF2 (RFC-2898) .
在 1.4 版更改: PBKDF2 添加了服务器端散列salt密码支持,现在作为 _config/admins
应用程序编程接口。
3.6.2. 身份验证配置¶
-
[chttpd]
¶ -
require_valid_user
¶ 当此选项设置为
true
,不允许来自匿名用户的请求。每个人都必须经过认证。:[chttpd] require_valid_user = false
-
require_valid_user_except_for_up
¶ 当此选项设置为
true
,不允许来自匿名用户的请求, 除了 对于/_up
终结点。其他人都必须经过身份验证。:[chttpd] require_valid_user_except_for_up = false
-
-
[chttpd_auth]
¶ 在 3.2 版更改: 这些选项已移动到 [chttpd_auth] 部分: authentication_redirect , require_valid_user , timeout , auth_cache_size , allow_persistent_cookies , iterations , min_iterations , max_iterations , secret , users_db_public , x_auth_roles , x_auth_token , x_auth_username , cookie_domain , same_site 。
在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
当设置为
true
,CouchDB将设置cookie的Max Age和Expires属性,这将导致用户代理(如浏览器)在重新启动时保留cookie。:[chttpd_auth] allow_persistent_cookies = true
2.1.1 新版功能.
在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
配置
domain
的属性AuthSession
饼干。默认情况下domain
属性为空,导致在CouchDB的域上设置cookie。:[chttpd_auth] cookie_domain = example.com
-
same_site
¶ 3.0.0 新版功能.
在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
如果此选项设置为非空值,则
SameSite
属性添加到AuthSession
饼干。有效值为none
,lax
或strict
::[chttpd_auth] same_site = strict
-
auth_cache_size
¶ 在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
数量 用户上下文对象 在内存中缓存,减少磁盘查找。:
[chttpd_auth] auth_cache_size = 50
-
authentication_redirect
¶ 在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
指定成功身份验证时重定向的位置,如果
text/html
客户机接受响应(通过Accept
收割台)。:[chttpd_auth] authentication_redirect = /_utils/session.html
-
iterations
¶ 1.3 新版功能.
在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
PBKDF2算法进行密码哈希的迭代次数。数字越大,散列的持久性越好,但对于需要身份验证的每个请求,都会降低性能。:
[chttpd_auth] iterations = 10000
-
min_iterations
¶ 1.6 新版功能.
在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
由PBKDF2算法散列的密码允许的最小迭代次数。禁止任何迭代次数较少的用户。:
[chttpd_auth] min_iterations = 100
-
max_iterations
¶ 1.6 新版功能.
在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
由PBKDF2算法散列的密码允许的最大迭代次数。禁止任何具有更大迭代次数的用户。:
[chttpd_auth] max_iterations = 100000
-
password_regexp
¶ 3.2 新版功能.
一份名单 Regular Expressions 要检查新密码/更改的密码,请执行以下操作。设置时,新用户密码必须 匹配 此列表中的所有RegExp。
RegExp可以与 原因文本 :
[{{"RegExp", "reason text"}}, ...]
. If a RegExp doesn't match, its reason text will be appended to the default reason ofPassword does not conform to requirements.
::[couch_httpd_auth] ; Password must be 10 chars long and have one or more uppercase and ; lowercase char and one or more numbers. password_regexp = [{".{10,}", "Min length is 10 chars."}, "[A-Z]+", "[a-z]+", "\\d+"]
-
proxy_use_secret
¶ 在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
当此选项设置为
true
,即chttpd_auth/secret
选项为必填项 代理身份验证 。::[chttpd_auth] proxy_use_secret = false
-
public_fields
¶ 1.4 新版功能.
在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
用户文档中以逗号分隔的字段名列表(在
couchdb/users_db_suffix
)任何用户都可以阅读。如果未设置或未指定,则经过身份验证的用户只能检索自己的文档。:[chttpd_auth] public_fields = first_name, last_name, contacts, url
注解
使用
public_fields
用户文档属性的允许列表需要设置chttpd_auth/users_db_public
选项以执行以下操作true
(后一项选择并无其他用途):[chttpd_auth] users_db_public = true
-
require_valid_user
¶ 在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
当此选项设置为
true
,不允许来自匿名用户的请求。每个人都必须经过认证。:[chttpd_auth] require_valid_user = false
-
secret
¶ 在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
秘密令牌用于 代理身份验证 为了 Cookie身份验证 . ::
[chttpd_auth] secret = 92de07df7e7a3fe14808cef90a7cc0d91
-
timeout
¶ 在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
在会话将过期之前,自上一个请求以来的秒数。:
[chttpd_auth] timeout = 600
-
users_db_public
¶ 1.4 新版功能.
在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
允许所有用户查看用户文档。默认情况下,只有管理员可以浏览所有用户的文档,而用户只能浏览自己的文档。:
[chttpd_auth] users_db_public = false
-
x_auth_roles
¶ 在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
HTTP标头名称 (
X-Auth-CouchDB-Roles
默认情况下)包含用户角色列表,用逗号分隔。用于 代理身份验证 . ::[chttpd_auth] x_auth_roles = X-Auth-CouchDB-Roles
-
x_auth_token
¶ 在 3.2 版更改: 从 [couch_httpd_auth] 至 [chttpd_auth] 部分
HTTP标头名称 (
X-Auth-CouchDB-Token
默认情况下)包含用于验证授权的令牌。此令牌是一个 HMAC-SHA1 从chttpd_auth/secret
和chttpd_auth/x_auth_username
。客户端和CouchDB节点上的密钥应该相同。此内标识是可选的,如果chttpd_auth/proxy_use_secret
选项不是true
。用于 代理身份验证 。::[chttpd_auth] x_auth_token = X-Auth-CouchDB-Token