@@ -260,46 +260,42 @@ with the timeout (in seconds) setting in the :ref:`couch_httpd_auth
260
260
Authentication Database
261
261
=======================
262
262
263
- You may already note, that CouchDB administrators are defined within config file
264
- and you now wondering does regular users are also stored there. No, they don't .
265
- CouchDB has special `authentication database ` -- ``_users `` by default -- that
266
- stores all registered users as JSON documents.
263
+ You may already note that CouchDB administrators are defined within the config
264
+ file and are wondering if regular users are also stored there. No, they are not .
265
+ CouchDB has a special `authentication database `, named ``_users `` by default,
266
+ that stores all registered users as JSON documents.
267
267
268
- CouchDB uses special database (called ``_users `` by default) to store
269
- information about registered users. This is a `system database ` -- this means
270
- that while it shares common :ref: `database API <api/database >`, there are some
271
- special security-related constraints applied and used agreements on documents
272
- structure. So how `authentication database ` is different from others?
268
+ This special database is a `system database `, this means that while it shares
269
+ the common :ref: `database API <api/database >`, there are some
270
+ special security-related constraints applied. Below is listed how the
271
+ `authentication database ` is different from the other databases.
273
272
274
273
- Only administrators may browse list of all documents
275
274
(:get: `GET /_users/_all_docs </{db}/_all_docs> `)
276
- - Only administrators may listen :ref: `changes feed
275
+ - Only administrators may listen to :ref: `changes feed
277
276
<changes>` (:get: `GET /_users/_changes </{db}/_changes> `)
278
277
- Only administrators may execute design functions like :ref: `views <viewfun >`,
279
278
:ref: `shows <showfun >` and :ref: `others <ddocs >`
280
- - Only administrators may :method: `GET `, :method: `PUT ` or :method: `DELETE `
281
- any document (to be honest, that they always can do)
282
- - There is special design document ``_auth `` that cannot be modified
283
- - Every document (of course, except `design documents `) represents registered
279
+ - There is a special design document ``_auth `` that cannot be modified
280
+ - Every document except the `design documents ` represent registered
284
281
CouchDB users and belong to them
285
282
- Users may only access (:get: `GET /_users/org.couchdb.user:Jan
286
283
</{db}/{docid}> `) or modify (:put: `PUT /_users/org.couchdb.user:Jan
287
- </{db}/{docid}> `) documents that they owns
284
+ </{db}/{docid}> `) documents that they own
288
285
289
- These draconian rules are reasonable: CouchDB cares about user's personal
290
- information and doesn't discloses it for everyone . Often, users documents are
291
- contains not only system information like `login `, `password hash ` and `roles `,
292
- but also sensitive personal information like: real name, email, phone, special
293
- internal identifications and more - this is not right information that you
286
+ These draconian rules are necessary since CouchDB cares about its users'
287
+ personal information and takes not to disclose it to just anyone . Often, user
288
+ documents contain system information like `login `, `password hash ` and `roles `,
289
+ apart from sensitive personal information like: real name, email, phone, special
290
+ internal identifications and more. This is not information that you
294
291
want to share with the World.
295
292
296
293
297
294
Users Documents
298
295
===============
299
296
300
- Each CouchDB user is stored in document format. These documents are contains
301
- several *mandatory * fields, that CouchDB handles for correct authentication
302
- process:
297
+ Each CouchDB user is stored in document format. These documents contain
298
+ several *mandatory * fields, that CouchDB needs for authentication:
303
299
304
300
- **_id ** (*string *): Document ID. Contains user's login with special prefix
305
301
:ref: `org.couchdb.user `
@@ -317,37 +313,37 @@ process:
317
313
- **salt ** (*string *): Hash salt. Used for ``simple `` `password_scheme `
318
314
- **type ** (*string *): Document type. Constantly have value ``user ``
319
315
320
- Additionally, you may specify any custom fields that are relates to the target
321
- user. This is good place to store user's private information because only the
316
+ Additionally, you may specify any custom fields that relate to the target
317
+ user. This is a good place to store user's private information because only the
322
318
target user and CouchDB administrators may browse it.
323
319
324
320
.. _org.couchdb.user :
325
321
326
322
Why ``org.couchdb.user: `` prefix?
327
323
---------------------------------
328
324
329
- The reason to have special prefix before user's login name is to have
330
- namespaces which users are belongs to. This prefix is designed to prevent
331
- replication conflicts when you'll try to merge two `_user ` databases or more.
325
+ The reason there is a special prefix before a user's login name is to have
326
+ namespaces that users belong to. This prefix is designed to prevent
327
+ replication conflicts when you try merging two `_user ` databases or more.
332
328
333
- For current CouchDB releases, all users are belongs to the same
334
- ``org.couchdb.user `` namespace and this cannot be changed, but we'd made
335
- such design decision for future releases.
329
+ For current CouchDB releases, all users belong to the same
330
+ ``org.couchdb.user `` namespace and this cannot be changed. This may be changed
331
+ in future releases.
336
332
337
333
338
334
Creating New User
339
335
=================
340
336
341
- Creating new user is a very trivial operation. You need just to send single
342
- :method: `PUT ` request with user's data to CouchDB. Let's create user with login
343
- `jan ` and password `apple `::
337
+ Creating a new user is a very trivial operation. You just need to do a
338
+ :method: `PUT ` request with user's data to CouchDB. Let's create a user with
339
+ login `jan ` and password `apple `::
344
340
345
341
curl -X PUT http://localhost:5984/_users/org.couchdb.user:jan \
346
342
-H "Accept: application/json" \
347
343
-H "Content-Type: application/json" \
348
344
-d '{"name": "jan", "password": "apple", "roles": [], "type": "user"}'
349
345
350
- This `curl ` command will produce next HTTP request:
346
+ This `curl ` command will produce the following HTTP request:
351
347
352
348
.. code-block :: http
353
349
@@ -373,8 +369,8 @@ And CouchDB responds with:
373
369
374
370
{"ok":true,"id":"org.couchdb.user:jan","rev":"1-e0ebfb84005b920488fc7a8cc5470cc0"}
375
371
376
- Document successfully created what also means that user `jan ` have created too!
377
- Let's check is this true::
372
+ The document was successfully created! The user `jan ` should now exist in our
373
+ database. Let's check if this is true::
378
374
379
375
curl -X POST http://localhost:5984/_session -d 'name=jan&password=apple'
380
376
@@ -384,9 +380,9 @@ CouchDB should respond with:
384
380
385
381
{" ok" : true ," name" : " jan" ," roles" : []}
386
382
387
- Which means that username was recognized and password's hash matches with stored
388
- one. If we specify wrong login and/or password, CouchDB will notify us with
389
- the next error message:
383
+ This means that the username was recognized and the password's hash matches
384
+ with the stored one. If we specify an incorrect login and/or password, CouchDB
385
+ will notify us with the following error message:
390
386
391
387
.. code-block :: javascript
392
388
@@ -396,21 +392,16 @@ the next error message:
396
392
Password Changing
397
393
=================
398
394
399
- This is quite common situation: user had forgot their password, it was leaked
400
- somehow (via copy-paste, screenshot, or by typing in wrong chat window) or
401
- something else. Let's change password for our user `jan `.
395
+ Let's define what is password changing from the point of view of CouchDB and
396
+ the authentication database. Since "users" are "documents", this operation is
397
+ just updating the document with a special field ``password `` which contains
398
+ the *plain text password *. Scared? No need to be, the authentication database
399
+ has a special internal hook on document update which looks for this field and
400
+ replaces it with the *secured hash * depending on the chosen ``password_scheme ``.
402
401
403
- First of all, let's define what is the password changing from the point of
404
- CouchDB and the authentication database. Since "users" are "documents", this
405
- operation is nothing, but updating the document with special field ``password ``
406
- which contains the *plain text password *. Scared? No need to: the authentication
407
- database has special internal hook on document update which looks for this
408
- field and replaces it with the *secured hash *, depending on chosen
409
- ``password_scheme ``.
410
-
411
- Summarizing above, we need to get document content, add ``password `` field
412
- with new plain text password value and store JSON result to the authentication
413
- database.
402
+ Summarizing the above process - we need to get the document's content, add
403
+ the ``password `` field with the new password in plain text and then store the
404
+ JSON result to the authentication database.
414
405
415
406
::
416
407
@@ -430,8 +421,8 @@ database.
430
421
" type" : " user"
431
422
}
432
423
433
- Here is our user's document. We may strip hashes from stored document to reduce
434
- amount of posted data::
424
+ Here is our user's document. We may strip hashes from the stored document to reduce
425
+ the amount of posted data::
435
426
436
427
curl -X PUT http://localhost:5984/_users/org.couchdb.user:jan \
437
428
-H "Accept: application/json" \
@@ -443,7 +434,7 @@ amount of posted data::
443
434
444
435
{" ok" : true ," id" : " org.couchdb.user:jan" ," rev" : " 2-ed293d3a0ae09f0c624f10538ef33c6f" }
445
436
446
- Updated! Now let's check that password was really changed::
437
+ Updated! Now let's check that the password was really changed::
447
438
448
439
curl -X POST http://localhost:5984/_session -d 'name=jan&password=apple'
449
440
@@ -465,11 +456,12 @@ CouchDB should respond with:
465
456
466
457
{" ok" : true ," name" : " jan" ," roles" : []}
467
458
468
- Hooray! You may wonder why so complex: need to retrieve user's document, add
469
- special field to it, post it back - where is one big button that changes the
470
- password without worry about document's content? Actually, :ref: `Futon
471
- <intro/futon>` has such at the right bottom corner if you have logged in -
472
- all implementation details are hidden from your sight.
459
+ Hooray! You may wonder why this was so complex - we need to retrieve user's
460
+ document, add a special field to it, post it back - where is that one big
461
+ button that changes the password without worrying about the document's content?
462
+ Actually, :ref: `Futon <intro/futon >` has one such thing at the bottom right
463
+ corner if are logged in. Using that will hide all the implementation details
464
+ described above and keep it real simple for you.
473
465
474
466
.. note ::
475
467
@@ -482,47 +474,45 @@ Users Public Information
482
474
483
475
.. versionadded :: 1.4
484
476
485
- Sometimes users *wants * to share some information with the World . For instance,
477
+ Sometimes users *want * to share some information with the world . For instance,
486
478
their contact email to let other users get in touch with them. To solve this
487
- problem, but still keep sensitive and private information secured there is
488
- special :ref: `configuration <config >` option :config:option: `public_fields
489
- <couch_httpd_auth/public_fields> `. In this options you may define comma
490
- separated list of users document fields that will be publicity available.
479
+ problem, but still keep sensitive and private information secured, there is
480
+ a special :ref: `configuration <config >` option :config:option: `public_fields
481
+ <couch_httpd_auth/public_fields> `. In this option you may define
482
+ a comma- separated lis of users document fields that will be publicly available.
491
483
492
- Normally, if you request any user's document and you're not administrator or
493
- this document owner, CouchDB will respond with :statuscode: `404 `::
484
+ Normally, if you request a user document and you're not an administrator or
485
+ document's owner, CouchDB will respond with :statuscode: `404 `::
494
486
495
487
curl http://localhost:5984/_users/org.couchdb.user:robert
496
488
497
489
.. code-block :: javascript
498
490
499
491
{" error" : " not_found" ," reason" : " missing" }
500
492
501
- This response is constant for both cases when user exists or not exists - by
493
+ This response is constant for both cases when user exists or doesn't exist for
502
494
security reasons.
503
495
504
- Now let's share field ``name ``. First, setup the ``public_fields `` configuration
505
- option. Remember, that this action requires administrator's privileges and
506
- the next command will ask for password for user `admin `, assuming that they are
507
- the server administrator::
496
+ Now let's share the field ``name ``. First, setup the ``public_fields ``
497
+ configuration option. Remember, that this action requires administrator
498
+ privileges. The next command will prompt you for user `admin `'s password:
508
499
509
500
curl -X PUT http://localhost:5984/_config/couch_http_auth/public_fields \
510
501
-H "Content-Type: application/json" \
511
502
-d '"name"' \
512
503
-u admin
513
504
514
- What have changed? Let's check Robert's document once again::
505
+ What has changed? Let's check Robert's document once again::
515
506
516
507
curl http://localhost:5984/_users/org.couchdb.user:robert
517
508
518
509
.. code-block :: javascript
519
510
520
511
{" _id" : " org.couchdb.user:robert" ," _rev" : " 6-869e2d3cbd8b081f9419f190438ecbe7" ," name" : " robert" }
521
512
522
- Good news! Now we may read field ``name `` from *every user's document without
523
- need to be an administrator *. That's important note: don't publish sensitive
524
- information, especially without user's acknowledge - they may not like such
525
- actions from your side.
513
+ Good news! Now, we may read the field ``name `` in *every user document without
514
+ needing to be an administrator *. Keep in mind though not to publish sensitive
515
+ information, especially without user's consent!
526
516
527
517
528
518
==============
0 commit comments