http://<SERVER_ADDRESS>/<DB_NAME>/_security
{
“admins”: {
“names”: [USER_NAME],
“roles”: [ROLE_NAME]
},
“members”: {
“names”: [USER_NAME],
“roles”: [ROLE_NAME]
},
}
{
"admins": ACCESS_GROUP,
"writers": ACCESS_GROUP,
"readers": ACCESS_GROUP,
"level": LEVEL
}
ACCESS_GROUP: {
"users": [USER_NAME],
"roles": [ROLE_NAME]
};
Традиционно, в Енисее имена всех служебных атрибутов начинаются с символа подчеркивания.
{
"writers": ACCESS_GROUP,
"readers": ACCESS_GROUP,
"level": LEVEL
}
Примечания:
- При создании объекта безопасности БД во всех списках пользователей указана только роль Server.admins (“_admin”). Уровень допуска устанавливается равным 0.
- Роли, которые указаны в скобках являются дополнительными и действуют, если не определены основные роли, указанные перед скобками. Например, Doc.readers (DB.readers) означает, что операция доступна пользователям из атрибута “readers” объекта безопасности документа, а если этот объект безопасности отсутствует, то пользователям “readers” из объекта безопасности БД.
$ curl -u "admin:admin" -X PUT http://127.0.0.1:5984/db1
{"ok":true}
$ curl -u "admin:admin" -X GET http://127.0.0.1:5984/db1/_security | jq
{
"admins": {
"names": [],
"roles": ["_admin"]
},
"readers": {
"names": [],
"roles": [“_admin"]
},
"writers": {
"names": [],
"roles": ["_admin"]
},
"level": 0
}
curl -u "user1:user1" -i -X GET http://127.0.0.1:5984/db1/_all_docs
HTTP/1.1 403 Forbidden
Cache-Control: must-revalidate
Content-Length: 72
Content-Type: application/json
Date: Sun, 14 Jan 2024 11:01:03 GMT
Server: Yenisei/2.1.0-1328 (Erlang OTP/24)
X-Couch-Request-ID: b2ac7a74d0
X-CouchDB-Body-Time: 0
{"error":"forbidden","reason":"you are not allowed to access this db"}
curl -u "admin:admin" -X PUT http://127.0.0.1:5984/db1/_security
-H "Content-Type: application/json"
-d '{"admins": {"names": [], "roles": ["manager"]},
"writers": {"names": [], "roles": ["editor"]},
"readers": {"names": [], "roles": ["client", "editor"]},
"level": 0}'
HTTP/1.1 200 OK
{"ok":true}
curl -u "user1:user1" -i -X GET http://127.0.0.1:5984/db1/_all_docs
HTTP/1.1 200 OK
{"total_rows":0,"offset":0,"rows":[
]}
curl -u "user1:user1" -i -X POST http://127.0.0.1:5984/db1 -H "Content-Type: application/json" -d '{"_id": "doc1"}'
HTTP/1.1 201 Created
{"ok":true,"id":"doc1","rev":"1-967a00dff5e02add41819138abb3284d"}
curl -u "user1:user1" -i -X POST http://127.0.0.1:5984/db1 -H "Content-Type: application/json" -d '{"_id": "doc2"}'
HTTP/1.1 201 Created
{"ok":true,"id":"doc1","rev":"1-967a00dff5e02add41819138abb3284d"}
curl -u "user2:user2" -i -X POST http://127.0.0.1:5984/db1 -H "Content-Type: application/json" -d '{"_id": "doc3"}'
HTTP/1.1 403 Forbidden
{"error":"forbidden","reason":"you are not authorized for this operation"}
curl -u "user2:user2" -i -X GET http://127.0.0.1:5984/db1/doc1
HTTP/1.1 200 OK
{"_id":"doc1","_rev":"1-967a00dff5e02add41819138abb3284d"}
curl -u "user3:user3" -i -X POST http://127.0.0.1:5984/db1
-H "Content-Type: application/json"
-d '{"_id":"doc2",
"_rev":"1-967a00dff5e02add41819138abb3284d",
"_access": {"readers": {"names": [], "roles": ["client", "editor"]},
"writers": {"names":[], "roles": ["editor"]},
"level": 2}}'
HTTP/1.1 201 Created
{"ok":true,"id":"doc2","rev":"2-c57ab28650ccc9789d299d9bd79a0c40"}
curl -u "user1:user1" -i -X GET http://127.0.0.1:5984/db1/doc2
HTTP/1.1 403 Forbidden
{"error":"forbidden","reason":"you are not authorized for this operation"}
curl -u "user4:user4" -i -X GET http://127.0.0.1:5984/db1/doc2
HTTP/1.1 200 OK
{"_id":"doc2","_rev":"2-c57ab28650ccc9789d299d9bd79a0c40","_access":{"readers":{"names":[],"roles":["client","editor"]},"writers":{"names":[],"roles":["editor"]},"level":2}}
Юрий Пипченко
Архитектор СУБД Енисей
ООО “Эквирон”