You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2013/08/21 18:38:01 UTC

[34/50] git commit: updated refs/heads/1781-reorganize-and-improve-docs to 360107b

Update Database Security API reference.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/4bb6d41e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/4bb6d41e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/4bb6d41e

Branch: refs/heads/1781-reorganize-and-improve-docs
Commit: 4bb6d41eb7aa4632fdeeee38158dc2e30a3a1c37
Parents: c6af82e
Author: Alexander Shorin <kx...@apache.org>
Authored: Tue Aug 13 16:13:18 2013 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Wed Aug 21 20:29:40 2013 +0400

----------------------------------------------------------------------
 share/doc/src/api/database/security.rst | 208 ++++++++++++++++++---------
 1 file changed, 137 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/4bb6d41e/share/doc/src/api/database/security.rst
----------------------------------------------------------------------
diff --git a/share/doc/src/api/database/security.rst b/share/doc/src/api/database/security.rst
index ff0fb69..6a9f1c9 100644
--- a/share/doc/src/api/database/security.rst
+++ b/share/doc/src/api/database/security.rst
@@ -12,101 +12,167 @@
 
 
 .. _api/db/security:
-.. _api/db/security.get:
 
-``GET /db/_security``
-=====================
+``/db/_security``
+=================
 
-* **Method**: ``GET /db/_security``
-* **Request**: None
-* **Response**: JSON of the security object
-* **Admin Privileges Required**: no
+.. http:get:: /{db}/_security
 
-Gets the current security object from the specified database. The
-security object consists of two compulsory elements, ``admins`` and
-``readers``, which are used to specify the list of users and/or roles
-that have admin and reader rights to the database respectively. 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.
+  Returns the current security object from the specified database.
 
-To get the existing security object you would send the following
-request:
+  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:
 
-.. code-block:: javascript
+  - ``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" : {
-          "roles" : [],
-          "names" : [
-             "mc",
-             "slp"
-          ]
-       },
-       "readers" : {
-          "roles" : [],
-          "names" : [
-             "tim",
-             "brian"
-          ]
-       }
-    }
+  - ``admins``: they have all the privileges of ``members`` plus the privileges:
+    write (and edit) design documents, add/remove database admins and members,
+    set the :ref:`database revisions limit <api/db/revs_limit>` and execute
+    :ref:`temporary views <api/db/temp_view>` against the database.
+    They can not create a database and neither delete a database.
+
+  Both ``members`` and ``admins`` objects are contains two array-typed fields:
+
+  - ``users``: List of CouchDB user names
+  - ``roles``: List of users roles
+
+  Any other 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.
 
-Security object structure is:
+  If both the names and roles fields of either the admins or members properties
+  are empty arrays, it means the database has no admins or members.
 
-* **admins**: Roles/Users with admin privileges
+  Having no admins, only server admins (with the reserved ``_admin`` role)
+  are able to update design document and make other admin level changes.
 
-  * **roles** [array]: List of roles with parent privilege
-  * **users** [array]: List of users with parent privilege
+  Having no members, any user can write regular documents (any non-design
+  document) and read documents from the database.
 
-* **readers**: Roles/Users with reader privileges
+  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 :http:get:`/{db}` call).
 
-  * **roles** [array]: List of roles with parent privilege
-  * **users** [array]: List of users with parent privilege
+  .. note::
+     If the security object for a database has never been set, then the
+     value returned will be empty.
 
-.. 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
+     speedup authorization checks (avoids traversing a database`s documents
+     B-Tree).
 
-.. _api/db/security.put:
+  :param db: Database name
+  :<header Accept: - :mimetype:`application/json`
+                   - :mimetype:`text/plain`
+  :>header Content-Type: - :mimetype:`application/json`
+                         - :mimetype:`text/plain; charset=utf-8`
+  :>json object admins: Object with two fields as ``names`` and ``roles``.
+    See description above for more info.
+  :>json object members: Object with two fields as ``names`` and ``roles``.
+    See description above for more info.
+  :code 200: Request completed successfully
 
-``PUT /db/_security``
-=====================
+  **Request**:
 
-* **Method**: ``PUT /db/_security``
-* **Request**: JSON specifying the admin and user security for the database
-* **Response**: JSON status message
-* **Admin Privileges Required**: no
+  .. code-block:: http
 
-Sets the security object for the given database.For example, to set the
-security object for the ``recipes`` database:
+    GET /db/_security HTTP/1.1
+    Accept: application/json
+    Host: localhost:5984
 
-.. code-block:: javascript
+  **Response**:
 
-    PUT http://couchdb:5984/recipes/_security
+  .. code-block:: http
+
+    HTTP/1.1 200 OK
+    Cache-Control: must-revalidate
+    Content-Length: 109
     Content-Type: application/json
+    Date: Mon, 12 Aug 2013 19:05:29 GMT
+    Server: CouchDB/1.4.0 (Erlang OTP/R16B)
 
     {
-       "admins" : {
-          "roles" : [],
-          "names" : [
-             "mc",
-             "slp"
-          ]
-       },
-       "readers" : {
-          "roles" : [],
-          "names" : [
-             "tim",
-             "brian"
-          ]
-       }
+        "admins": {
+            "names": [
+                "superuser"
+            ],
+            "roles": [
+                "admins"
+            ]
+        },
+        "members": {
+            "names": [
+                "user1",
+                "user2"
+            ],
+            "roles": [
+                "developers"
+            ]
+        }
     }
 
-If the setting was successful, a JSON status object will be returned:
 
-.. code-block:: javascript
+.. http:put:: /{db}/_security
+
+  Sets the security object for the given database.
+
+  :param db: Database name
+  :<header Accept: - :mimetype:`application/json`
+                   - :mimetype:`text/plain`
+  :>header Content-Type: - :mimetype:`application/json`
+                         - :mimetype:`text/plain; charset=utf-8`
+  :<json object admins: Object with two fields as ``names`` and ``roles``.
+    :ref:`See description above for more info <api/db/security>`.
+  :<json object members: Object with two fields as ``names`` and ``roles``.
+    :ref:`See description above for more info <api/db/security>`.
+  :>json boolean ok: Operation status
+  :code 200: Request completed successfully
+  :code 401: Administrator's privileges required
+
+  **Request**:
+
+  .. code-block:: http
+
+    PUT /db/_security HTTP/1.1
+    Accept: application/json
+    Content-Length: 121
+    Content-Type: application/json
+    Host: localhost:5984
+
+    {
+        "admins": {
+            "names": [
+                "superuser"
+            ],
+            "roles": [
+                "admins"
+            ]
+        },
+        "members": {
+            "names": [
+                "user1",
+                "user2"
+            ],
+            "roles": [
+                "developers"
+            ]
+        }
+    }
+
+  **Response**:
+
+  .. code-block:: http
+
+    HTTP/1.1 200 OK
+    Cache-Control: must-revalidate
+    Content-Length: 12
+    Content-Type: application/json
+    Date: Tue, 13 Aug 2013 11:26:28 GMT
+    Server: CouchDB/1.4.0 (Erlang OTP/R16B)
 
     {
-       "ok" : true
+        "ok": true
     }