@@ -54,7 +54,15 @@ Let's say you POST the following document into ``_replicator``:
5454 {
5555 " _id" : " my_rep" ,
5656 " source" : " http://myserver.com/foo" ,
57- " target" : " http://user:pass@localhost:5984/bar" ,
57+ " target" : {
58+ " url" : " http://localhost:5984/bar" ,
59+ " auth" : {
60+ " basic" : {
61+ " username" : " user" ,
62+ " password" : " pass"
63+ }
64+ }
65+ },
5866 " create_target" : true ,
5967 " continuous" : true
6068 }
@@ -100,7 +108,7 @@ Replication state of this document can then be queried from
100108 "source" : " http://myserver.com/foo/" ,
101109 "start_time" : " 2017-04-05T19:18:15Z" ,
102110 "state" : " running" ,
103- "target" : " http://adm:*****@ localhost:5984/bar/"
111+ "target" : " http://localhost:5984/bar/"
104112 }
105113
106114 The state is ``running ``. That means replicator has scheduled this
@@ -145,7 +153,7 @@ The replication job will also appear in
145153 "pid" : " <0.1174.0>" ,
146154 "source" : " http://myserver.com/foo/" ,
147155 "start_time" : " 2017-04-05T19:18:15Z" ,
148- "target" : " http://adm:*****@ localhost:5984/bar/" ,
156+ "target" : " http://localhost:5984/bar/" ,
149157 "user" : null
150158 }
151159 ],
@@ -171,7 +179,15 @@ For example, POST-ing this document
171179 {
172180 " _id" : " my_rep_crashing" ,
173181 " source" : " http://myserver.com/missing" ,
174- " target" : " http://user:pass@localhost:5984/bar" ,
182+ " target" : {
183+ " url" : " http://localhost:5984/bar" ,
184+ " auth" : {
185+ " basic" : {
186+ " username" : " user" ,
187+ " password" : " pass"
188+ }
189+ }
190+ },
175191 " create_target" : true ,
176192 " continuous" : true
177193 }
@@ -213,16 +229,16 @@ crashes with an increasingly larger interval. The ``history`` list from
213229 "error_count" : 6 ,
214230 "id" : " cb78391640ed34e9578e638d9bb00e44+create_target" ,
215231 "info" : {
216- "error" : " db_not_found: could not open http://adm:*****@localhost:5984 /missing/"
232+ "error" : " db_not_found: could not open http://myserver.com /missing/"
217233 },
218234 "last_updated" : " 2017-04-05T20:55:10Z" ,
219235 "node" : " node1@127.0.0.1" ,
220236 "source_proxy" : null ,
221237 "target_proxy" : null ,
222- "source" : " http://adm:*****@localhost:5984 /missing/" ,
238+ "source" : " http://myserver.com /missing/" ,
223239 "start_time" : " 2017-04-05T20:38:34Z" ,
224240 "state" : " crashing" ,
225- "target" : " http://adm:*****@ localhost:5984/bar/"
241+ "target" : " http://localhost:5984/bar/"
226242 }
227243
228244 Repeated crashes are described as a ``crashing `` state. ``-ing `` suffix
@@ -277,7 +293,7 @@ exactly why it failed:
277293 "source" : " http://myserver.com/foo/" ,
278294 "start_time" : " 2017-04-05T21:41:51Z" ,
279295 "state" : " failed" ,
280- "target" : " http://adm :***** @localhost:5984/bar/ "
296+ "target" : " http://user :****@localhost:5984/bar" ,
281297 }
282298
283299 Notice the state for this replication is ``failed ``. Unlike
@@ -495,7 +511,15 @@ which represent pull replications from servers A and B:
495511 {
496512 " _id" : " rep_from_A" ,
497513 " source" : " http://aserver.com:5984/foo" ,
498- " target" : " http://user:pass@localhost:5984/foo_a" ,
514+ " target" : {
515+ " url" : " http://localhost:5984/foo_a" ,
516+ " auth" : {
517+ " basic" : {
518+ " username" : " user" ,
519+ " password" : " pass"
520+ }
521+ }
522+ },
499523 " continuous" : true
500524 }
501525
@@ -504,7 +528,15 @@ which represent pull replications from servers A and B:
504528 {
505529 " _id" : " rep_from_B" ,
506530 " source" : " http://bserver.com:5984/foo" ,
507- " target" : " http://user:pass@localhost:5984/foo_b" ,
531+ " target" : {
532+ " url" : " http://localhost:5984/foo_b" ,
533+ " auth" : {
534+ " basic" : {
535+ " username" : " user" ,
536+ " password" : " pass"
537+ }
538+ }
539+ },
508540 " continuous" : true
509541 }
510542
@@ -696,3 +728,76 @@ The syntax for a selector is the same as the
696728Using a selector is significantly more efficient than using a JavaScript
697729filter function, and is the recommended option if filtering on document
698730attributes only.
731+
732+ Specifying Usernames and Passwords
733+ ===================================
734+
735+ There are multiple ways to specify usernames and passwords for replication endpoints:
736+
737+ - In an ``{"auth": {"basic": ...}} `` object:
738+
739+ .. versionadded :: 3.2.0
740+
741+ .. code-block :: javascript
742+
743+ {
744+ " target" : {
745+ " url" : " http://someurl.com/mydb" ,
746+ " auth" : {
747+ " basic" : {
748+ " username" : " $username" ,
749+ " password" : " $password"
750+ }
751+ }
752+ },
753+ ...
754+ }
755+
756+ This is the prefererred format as it allows including characters like ``@ ``, ``: ``
757+ and others in the username and password fields.
758+
759+ - In the userinfo part of the endpoint URL. This allows for a more compact
760+ endpoint represention however, it prevents using characters like ``@ `` and ``: ``
761+ in usernames or passwords:
762+
763+ .. code-block :: javascript
764+
765+ {
766+ " target" : " http://user:pass@localhost:5984/bar"
767+ ...
768+ }
769+
770+ Specifying credentials in the userinfo part of the URL is deprecated as per
771+ `RFC3986 <https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1 >`_.
772+ CouchDB still supports this way of specifying credentials and doesn't yet
773+ have a target release when support will be removed.
774+
775+ - In an ``"Authorization: Basic $b64encoded_username_and_password" `` header:
776+
777+ .. code-block :: javascript
778+
779+ {
780+ " target" : {
781+ " url" : " http://someurl.com/mydb" ,
782+ " headers" : {
783+ " Authorization" : " Basic dXNlcjpwYXNz"
784+ }
785+ },
786+ ...
787+ }
788+
789+ This method has the downside of the going through the extra step of base64
790+ encoding. In addition, it could give the impression that it encrypts or
791+ hides the credentials so it could encourage invadvertent sharing and
792+ leaking credentials.
793+
794+ When credentials are provided in multiple forms, they are selected in the following order:
795+
796+ - ``"auth": {"basic": {...}} `` object
797+ - URL userinfo
798+ - ``"Authorization: Basic ..." `` header.
799+
800+ First, the ``auth `` object is checked, and if credentials are defined there,
801+ they are used. If they are not, then URL userinfo is checked. If credentials
802+ are found there, then those credentials are used, otherwise basic auth header
803+ is used.
0 commit comments