1.3.17. /db/_security
Returns the current security object from the specified database.
The security object consists of two compulsory elements, admins
and members
, which are used to specify the list of users and/or roles that have admin and members rights to the database respectively:
members
: they can read all types of documents from the DB, and they can write (and edit) documents to the DB except for design documents.admins
: they have all the privileges of plus the privileges: write (and edit) design documents, add/remove database admins and members and set the database revisions limit. They can not create a database nor delete a database.
Both members
and admins
objects contain two array-typed fields:
names
: List of CouchDB user namesroles
: List of users roles
Any additional fields in the security object are optional. The entire security object is made available to validation and other internal functions so that the database can control and limit functionality.
If both the names and roles fields of either the admins or members properties are empty arrays, or are not existent, it means the database has no admins or members.
Having no admins, only server admins (with the reserved _admin
role) are able to update design documents and make other admin level changes.
Having no members or roles, any user can write regular documents (any non-design document) and read documents from the database.
Since CouchDB 3.x newly created databases have by default the _admin role to prevent unintentional access.
If there are any member names or roles defined for a database, then only authenticated users having a matching name or role are allowed to read documents from the database (or do a call).
Note
If the security object for a database has never been set, then the value returned will be empty.
Also note, that security objects are not regular versioned documents (that is, they are not under MVCC rules). This is a design choice to speed up authorization checks (avoids traversing a database’s documents B-Tree).
-
- db – Database name
Request Headers
Accept –
application/json
text/plain
Response Headers
Response JSON Object
admins (object) – Object with two fields as
names
androles
. See description above for more info.members (object) – Object with two fields as and
roles
. See description above for more info.
Status Codes
- – Request completed successfully
Request:
Response:
PUT
/{db}/_security
Sets the security object for the given database.
-
- db – Database name
Request Headers
Accept –
application/json
– application/json
Request JSON Object
admins (object) – Object with two fields as
names
androles
. See description above for more info.members (object) – Object with two fields as
names
androles
. .
Response Headers
-
application/json
text/plain; charset=utf-8
Response JSON Object
- ok (boolean) – Operation status
Status Codes
– Request completed successfully
401 Unauthorized – CouchDB Server Administrator privileges required
Response: