~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/developers/authentication-ring.txt

  • Committer: Martin Pool
  • Date: 2005-11-04 01:46:31 UTC
  • mto: (1185.33.49 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 1512.
  • Revision ID: mbp@sourcefrog.net-20051104014631-750e0ad4172c952c
Make biobench directly executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Authentication ring
2
 
===================
3
 
 
4
 
When accessing a remote branch (specified as an URL), it may occur that the
5
 
server requests an authentication.
6
 
 
7
 
This authentication can be provided in different ways:
8
 
 
9
 
1. Embedding the user and password
10
 
in the URL::
11
 
 
12
 
  bzr branch <scheme>://<user>:<password>@host:port/path
13
 
 
14
 
* ``scheme``: Any transport protocol requiring authentication.
15
 
* ``user``: The login used to authenticate.
16
 
* ``password``: The associated password.
17
 
* ``host``: The address of the server.
18
 
* ``port``: The port the server is listening to.
19
 
* ``path``: The path on the server.
20
 
 
21
 
2. Embedding the user in the URL and let bzr find the right password or prompt
22
 
for one::
23
 
 
24
 
  bzr branch <scheme>://<user>@host/path
25
 
 
26
 
3. Embedding nothing in the URL and let bzr find user and password or prompt
27
 
for user and/or password::
28
 
 
29
 
  bzr branch <scheme>://host/path
30
 
 
31
 
This specification proposes a mechanism that will allow users to
32
 
just use ``bzr branch <scheme>://host/path`` or ``bzr branch
33
 
<scheme>://<user>@host/path`` and leaves bzr find the ``user``
34
 
and ``password`` in its configuration files.
35
 
 
36
 
When no user is specified for ``FTP``, ``SFTP`` or ``SSH``, the actual behavior
37
 
of ``bzr`` is to default to ``getpass.get_user()``.
38
 
 
39
 
Any implementation of this specification should respect that behaviour.
40
 
 
41
 
This specification also proposes a way to describe credentials so that several
42
 
remote branches can use the same definition. This is particularily important
43
 
for users handling a lot of passwords who need to update them on a regular
44
 
basis.
45
 
 
46
 
Rationale
47
 
---------
48
 
 
49
 
Embedding user and passwords in the command line is a security
50
 
hazard (see `bug #34685
51
 
<https://launchpad.net/products/bzr/+bug/34685>`_).
52
 
 
53
 
Storing passwords in ``~/.bazaar/bazaar.conf`` or ``~/.bazaar/locations.conf``
54
 
is also a security risk.
55
 
 
56
 
Typing user and passwords is error-prone and boring.
57
 
 
58
 
Yet, a safe way to store passwords, while allowing bzr to retrieve them, when
59
 
needed, could improve the bzr user experience.
60
 
 
61
 
This specification describes a way to provide user and passwords to bzr while
62
 
storing them in a relatively safe way.
63
 
 
64
 
Note that ssh servers can be configured to use keys instead of (``user``,
65
 
``password``) and, when used with appropriate agents, provide the same kind of
66
 
comfort this specification aims to provide for all other schemes. These
67
 
specification do not try to cover these configurations by providing
68
 
pass-phrases, but the mechanisms presented *can* be used to provide users.
69
 
 
70
 
Authentication definitions
71
 
--------------------------
72
 
 
73
 
There are two kinds of authentication used by the various schemes supported by
74
 
bzr:
75
 
 
76
 
1. user and password
77
 
 
78
 
``FTP`` and ``SFTP`` needs a (``user``, ``password``) to authenticate against a
79
 
``host`` (SFTP can use ssh keys too, but we don't talk about that in this
80
 
specification as ssh agents provide a better solution).
81
 
 
82
 
2. user, realm and password
83
 
 
84
 
``HTTP`` and ``HTTPS`` needs a (``user, realm, password``) to authenticate
85
 
against a host. But, by using ``.htaccess`` files, for example, it is possible
86
 
to define several (``user, realm, password``) for a given ``host``. So what is
87
 
really needed is (``user``, ``password``, ``host``, ``path``). The ``realm``
88
 
can be ignored [#ignored_realm]_ as long as it is still presented to the user
89
 
when prompting for the password (unless someone found a way to declare two
90
 
different realms for the same path). 
91
 
 
92
 
``HTTP proxy`` can be handled as ``HTTP`` (or ``HTTPS``) by explicitely
93
 
specifying the appropriate port.
94
 
 
95
 
.. [#ignored_realm] The true purpose of realms is to allow the same credentials
96
 
   to be reused for disjoint hierarchies. Ignoring them in this specification
97
 
   aims to simplify the user experience while still allowing to share the same
98
 
   credentials for a whole hierarchy.
99
 
 
100
 
To take all schemes into account, the password will be deduced from a set of
101
 
authentication definitions (``scheme``, ``host``, ``port``, ``path``, ``user``,
102
 
``password``).
103
 
 
104
 
  * ``scheme``: can be empty (meaning the rest of the definition can be used
105
 
    for any scheme), ``SFTP`` and ``bzr+ssh`` should not be used here, ``ssh``
106
 
    should be used instead since this is the real scheme regarding
107
 
    authentication,
108
 
 
109
 
  * ``host``: can be empty (to act as a default for any host),
110
 
 
111
 
  * ``port`` can be empty (useful when an host provides several servers for the
112
 
    same scheme), only numerical values are allowed, this should be used only
113
 
    when the server uses a port different than the scheme standard port,
114
 
 
115
 
  * ``path``: can be empty (FTP or SFTP will never user it),
116
 
 
117
 
  * ``user``: can be empty (``bzr`` will defaults to python's
118
 
    ``getpass.get_user()`` and attempt another matching(see below)),
119
 
 
120
 
  * ``password``: can be empty (for security reasons, a user may use the
121
 
    definitions without storing the passwords but want to be prompted ; or the
122
 
    password will be provided by an external plugin via the
123
 
    ``password_encoding`` mechanism decribed below).
124
 
 
125
 
  * ``password_encoding``: can be empty (default is ``plaintext``).
126
 
 
127
 
Also note that an optional ``verify_certificates=no`` field will allow the
128
 
connection to ``HTTPS`` hosts that provides a self certified certificate (the
129
 
default should be to refuse the connection and inform the user).
130
 
 
131
 
Multiple definitions can be provided and, for a given URL, bzr will select a
132
 
(``user`` [, ``password``]) based on the following rules :
133
 
 
134
 
 1. the first match wins,
135
 
 
136
 
 2. empty fields match everything,
137
 
 
138
 
 3. ``scheme`` matches even if decorators are used in the requested URL,
139
 
 
140
 
 4. ``host`` matches exactly or act as a domain if it starts with '.'
141
 
    (``project.bzr.sf.net`` will match ``.bzr.sf.net`` but ``projectbzr.sf.net``
142
 
    will not match ``bzr.sf.net``).
143
 
 
144
 
 5. ``port`` matches if included in the requested URL (exact matches only)
145
 
 
146
 
 6. ``path`` matches if included in the requested URL (and by rule #2 above,
147
 
    empty paths will match any provided path).
148
 
 
149
 
An optional ``password_encoding`` field may specify how the password is encoded
150
 
but has no impact on the definition selection.
151
 
 
152
 
Possible values are ``plaintext`` (no encoding at all) and ``base64``. When the
153
 
field is absent, ``plaintext`` is assumed. Additional encodings may be added in
154
 
future versions.
155
 
 
156
 
Encoding passwords in ``base64``, while weak, provides protection against
157
 
accidental reading (if an administrator have to look into the file, he will not
158
 
see the passwords in clear).
159
 
 
160
 
This specification intend to ease the authentication providing, not to secure
161
 
it in the best possible way.
162
 
 
163
 
Future versions of this specification may provide additional
164
 
encodings [#password_encoding]_.
165
 
 
166
 
.. [#password_encoding] Additional password encoding methods may be defined
167
 
   that will rely on external means to store the password which, in these
168
 
   cases, will not appear anymore in the definition. It is assumed that
169
 
   additional password encodings will provide a storage outside of the file
170
 
   described here. An encoding named ``netrc`` for example will provide
171
 
   passwords by retrieving them in the ``.netrc`` file.
172
 
 
173
 
File format
174
 
-----------
175
 
 
176
 
Even if ``~/.bazaar/bazaar.conf`` and ``~/.bazaar/locations.conf`` seems to
177
 
provide most of the needed infrastructure, we choose to use a dedicated file
178
 
for the authentication info ``~/.bazaar/authentication.conf`` for the following
179
 
reasons:
180
 
 
181
 
  * allow the user to protect the content of one file only, relaxing security
182
 
    constraints on the others,
183
 
 
184
 
  * while ``locations.conf`` is organized around *local* branches,
185
 
    ``authentication.conf`` is organized around *remote* branches or more
186
 
    generally servers. The same authentification definition can even be used
187
 
    for several schemes for servers providing those schemes.
188
 
 
189
 
``~/.bazaar/authentication.conf`` will use the same file format than
190
 
``~/.bazaar/bazaar.conf``.
191
 
 
192
 
Each section describes an authentication definition.
193
 
 
194
 
The section name is an arbitrary string, only the ``DEFAULT`` value is reserved
195
 
and should appear as the *last* section.
196
 
 
197
 
Each section should define:
198
 
 
199
 
  * ``user``: the login to be used,
200
 
 
201
 
Each section could define:
202
 
 
203
 
  * ``host``: the remote server,
204
 
 
205
 
  * ``port``: the port the server is listening,
206
 
 
207
 
  * ``verify_certificates``: to control certificate verification (useful
208
 
    for self certified hosts). This applies to HTTP[S] only. Accepted values
209
 
    are yes and no, default to yes.
210
 
 
211
 
  * ``path``: the branch location,
212
 
 
213
 
  * ``password``: the password,
214
 
 
215
 
  * ``password_encoding``: the method used to encode the password if any,
216
 
 
217
 
The default content of the file will be::
218
 
 
219
 
    [DEFAULT]
220
 
 
221
 
This section could define:
222
 
 
223
 
  * ``user``: default user to be used (if not defined the usual
224
 
    bzr way applies, see below).
225
 
 
226
 
  * ``password_encoding``: default password encoding.
227
 
 
228
 
Use Cases
229
 
---------
230
 
 
231
 
The use cases described below use the file format defined above.
232
 
 
233
 
  * all FTP connections to the foo.net domain are done with the same (``user``,
234
 
    ``password``)::
235
 
 
236
 
        # Identity on foo.net
237
 
        [foo.net]
238
 
        scheme=ftp
239
 
        host=foo.net
240
 
        user=joe
241
 
        password=secret-pass
242
 
 
243
 
    will provide ('joe', 'secret-pass') for::
244
 
 
245
 
        bzr branch ftp://foo.net/bzr/branch
246
 
        bzr pull ftp://bzr.foo.net/bzr/product/branch/trunk
247
 
 
248
 
  * all connections are done with the same ``user`` (the remote one for which
249
 
    the default bzr one is not appropriate) and the password is always prompted
250
 
    with some exceptions::
251
 
 
252
 
        # Pet projects on hobby.net
253
 
        [hobby]
254
 
        host=r.hobby.net
255
 
        user=jim
256
 
        password=obvious1234
257
 
        
258
 
        # Home server
259
 
        [home]
260
 
        scheme=https
261
 
        host=home.net
262
 
        user=joe
263
 
        password='c2VjcmV0LXBhc3M='
264
 
        password_encoding=base64
265
 
        verify_certificates=no # Still searching a free certificate provider
266
 
        
267
 
        [DEFAULT]
268
 
        # Our local user is barbaz, on all remote sites we're known as foobar
269
 
        user=foobar
270
 
        
271
 
  * an HTTP server and a proxy::
272
 
 
273
 
        # development branches on dev server
274
 
        [dev]
275
 
        scheme=https
276
 
        host=dev.company.com
277
 
        path=/dev
278
 
        user=user1
279
 
        password=pass1
280
 
        
281
 
        # toy branches
282
 
        [localhost]
283
 
        scheme=http
284
 
        host=dev.company.com
285
 
        path=/
286
 
        user=user2
287
 
        password=pass2
288
 
        
289
 
        # proxy
290
 
        [proxy]
291
 
        scheme=http
292
 
        host=proxy.company.com
293
 
        port=3128
294
 
        user=proxyuser1
295
 
        password=proxypass1
296
 
 
297
 
  * source hosting provider declaring sub-domains for each project::
298
 
 
299
 
        [sfnet domain]
300
 
        # we use sftp, but ssh is the scheme used for authentication
301
 
        scheme=ssh
302
 
        # The leading '.' ensures that 'sf.net' alone doesn't match
303
 
        host=.sf.net
304
 
        user=georges
305
 
        password=ben...son
306
 
 
307
 
 
308
 
UI Changes
309
 
----------
310
 
 
311
 
Depending on the info provided in the URL, bzr will interact with the user in
312
 
different ways:
313
 
 
314
 
1. ``user`` and ``password`` given in the URL.
315
 
 
316
 
  Nothing to do.
317
 
 
318
 
2. ``user`` given in the URL.
319
 
 
320
 
  Get a password from ``~/.bazaar/authentication.conf`` or prompt
321
 
  for one if none is found.
322
 
 
323
 
3. No ``user`` given in the URL (and no ``password``).
324
 
 
325
 
  Get a user from ``~/.bazaar/authentication.conf`` or prompt for one if none is
326
 
  found. Continue as 2.
327
 
 
328
 
Note: A user will be queried only if the server requires it for ``HTTP`` or
329
 
``HTTPS``, other protocols always require a user.
330
 
 
331
 
In any case, if the server refuses the authentication, bzr reports to the user
332
 
and terminates.
333
 
 
334
 
Implementation constraints
335
 
--------------------------
336
 
 
337
 
* bzr should be able to prompt for a ``user`` for a given (``scheme``, ``host``
338
 
  [, ``realm``]). Note that ``realm`` is available only after a first
339
 
  connection attempt to the server.
340
 
 
341
 
* No assumptions should be made about the clients of this service
342
 
  (i.e. Transport is the primary target but plugins must be able to use it as
343
 
  well, the definitions used: (``scheme, host, [port,] path``) are general
344
 
  enough to described credentials for ``svn`` servers or LaunchPad xmlrpc
345
 
  calls).
346
 
 
347
 
* Policies regarding default users may be taken into account by the
348
 
  implementations, there is no good way to represent that in this specification
349
 
  and stays flexible enough to accommodate various needs (default user policies
350
 
  may differ for different schemes and that may be easier to handle in the code
351
 
  than in the authentication file itself).
352
 
 
353
 
* If no user can be found by the mechanism described above, bzr should still
354
 
  default to ``getpass.get_user()`` and may attempt a second matching to obtain
355
 
  a password.
356
 
 
357
 
* As this specification proposes a matching between some credentials
358
 
  definitions and real urls, the implementation should provide an optional UI
359
 
  feedback about which credential definition is used. That will allow the user
360
 
  to validate his definitions.
361
 
 
362
 
Questions and Answers
363
 
---------------------
364
 
 
365
 
  * What if a ``.authinfo`` file exists ?
366
 
 
367
 
    * It will be ignored,
368
 
 
369
 
    * Automatic (one-time) conversions may be proposed if sufficient demand
370
 
      exists,
371
 
 
372
 
  * What if a ``.netrc`` file exists ?
373
 
 
374
 
    * It will be honored if the definition specifies
375
 
      ``password_encoding=netrc`` once the appropriate plugin have been
376
 
      written.
377
 
 
378
 
  * What mode should the authentication file use ?
379
 
 
380
 
    * 600 read/write for owner only by default, if another mode (more
381
 
      permissive) is used, a warning will be issued to inform the users of the
382
 
      potential risks.
383
 
 
384
 
  * What about using ``seahorse`` on Ubuntu or ``KeyChain Access`` on Mac OS X ?
385
 
 
386
 
    * plugins can be written and registered to handle the associated
387
 
      ``password_encoding``.
388
 
 
389
 
  * Could it be possible to encode the whole authentication file with a ssh key
390
 
    ?
391
 
 
392
 
    * yes and if the user configure a ssh-agent it will not be queried for
393
 
      pass-phrase every time we want to query the file for a password. But that
394
 
      seems a bit extreme for a first version.
395
 
 
396
 
  * Why can't bzr update the authentication file when it queried the user for a
397
 
    password ?
398
 
 
399
 
    * a future version may address that but:
400
 
 
401
 
      1. The user may want to decide which passwords are stored in the file and
402
 
      which aren't.
403
 
 
404
 
      2. The user should decide if the passwords are encoded (and how) or not
405
 
      (but we may default to base64).
406
 
 
407
 
      3. The right definition may be hard to get right, but reducing it to
408
 
      (``scheme, host, [port,] user, password``) may be a good start. I.e. no
409
 
      path so that all paths on the host will match. The user will have to
410
 
      modify it for more complex configurations anyway.
411