4
When accessing a remote branch (specified as an URL), it may occur that the
5
server requests an authentication.
7
This authentication can be provided in different ways:
9
1. Embedding the user and password
12
bzr branch <scheme>://<user>:<password>@host:port/path
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.
21
2. Embedding the user in the URL and let bzr find the right password or prompt
24
bzr branch <scheme>://<user>@host/path
26
3. Embedding nothing in the URL and let bzr find user and password or prompt
27
for user and/or password::
29
bzr branch <scheme>://host/path
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.
36
When no user is specified for ``FTP``, ``SFTP`` or ``SSH``, the actual behavior
37
of ``bzr`` is to default to ``getpass.get_user()``.
39
Any implementation of this specification should respect that behaviour.
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
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>`_).
53
Storing passwords in ``~/.bazaar/bazaar.conf`` or ``~/.bazaar/locations.conf``
54
is also a security risk.
56
Typing user and passwords is error-prone and boring.
58
Yet, a safe way to store passwords, while allowing bzr to retrieve them, when
59
needed, could improve the bzr user experience.
61
This specification describes a way to provide user and passwords to bzr while
62
storing them in a relatively safe way.
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.
70
Authentication definitions
71
--------------------------
73
There are two kinds of authentication used by the various schemes:
77
``FTP`` and ``SFTP`` needs a (``user``, ``password``) to authenticate against a
78
``host`` (SFTP can use ssh keys too, but we don't talk about that in this
79
specification as ssh agents provide a better solution).
81
2. user, realm and password
83
``HTTP`` and ``HTTPS`` needs a (``user, realm, password``) to authenticate
84
against a host. But, by using ``.htaccess`` files, for example, it is possible
85
to define several (``user, realm, password``) for a given ``host``. So what is
86
really needed is (``user``, ``password``, ``host``, ``path``). The ``realm``
87
can be ignored [#ignored_realm]_ as long as it is still presented to the user
88
when prompting for the password (unless someone found a way to declare two
89
different realms for the same path).
91
``HTTP proxy`` can be handled as ``HTTP`` (or ``HTTPS``) by explicitely
92
specifying the appropriate port.
94
.. [#ignored_realm] The true purpose of realms is to allow the same credentials
95
to be reused for disjoint hierarchies. Ignoring them in this specification
96
aims to simplify the user experience while still allowing to share the same
97
credentials for a whole hierarchy.
99
To take all schemes into account, the password will be deduced from a set of
100
authentication definitions (``scheme``, ``host``, ``port``, ``path``, ``user``,
103
* ``scheme``: can be empty (meaning the rest of the definition can be used
106
* ``host``: can be empty (to act as a default for any host),
108
* ``port`` can be empty (useful when an host provides several servers for the
109
same scheme), only numerical values are allowed,
111
* ``path``: can be empty (FTP or SFTP will never user it),
113
* ``user``: can be empty (and will use the same default as ``bzr``, python's
114
``getpass.get_user()``),
116
* ``password``: can be empty (for security reasons, a user may use the
117
definitions without storing the passwords but want to be prompted).
119
* ``password_encoding``: can be empty (default is ``plaintext``).
121
Also note that an optional ``verify_certificates=no`` field will allow the
122
connection to ``HTTPS`` hosts that provides a self certified certificate (the
123
default should be to refuse the connection and inform the user).
125
Multiple definitions can be provided and, for a given URL, bzr will select a
126
(``user`` [, ``password``]) based on the following rules :
128
1. the first match wins,
130
2. empty fields match everything,
132
3. ``scheme`` matches even if decorators are used in the requested URL,
134
4. ``host`` matches if included in the requested URL. ``foo.net`` will match a
135
requested ``bzr.foo.net``.
137
5. ``port`` matches if included in the requested URL (exact matches only)
139
6. ``path`` matches if included in the requested URL (and by rule #2 above,
140
empty paths will match any provided path).
142
An optional ``password_encoding`` field may specify how the password is encoded
143
but has no impact on the definition selection.
145
Possible values are ``plaintext`` (no encoding at all) and ``base64``. When the
146
field is absent, ``plaintext`` is assumed. Additional encodings may be added in
149
Encoding passwords in ``base64``, while weak, provides protection against
150
accidental reading (if an administrator have to look into the file, he will not
151
see the passwords in clear).
153
This specification intend to ease the authentication providing, not to secure
154
it in the best possible way.
156
Future versions of this specification may provide additional
157
encodings [#password_encoding]_.
159
.. [#password_encoding] Additional password encoding methods may be defined
160
that will rely on external means to store the password which, in these
161
cases, will not appear anymore in the definition but be provided. An
162
encoding named ``netrc`` for example will provide passwords by using the
168
Even if ``~/.bazaar/bazaar.conf`` and ``~/.bazaar/locations.conf`` seems to
169
provide most of the needed infrastructure, we choose to use a dedicated file
170
for the authentication info ``~/.bazaar/authentication.conf`` for the following
173
* allow the user to protect the content of one file only, relaxing security
174
constraints on the others,
176
* while ``locations.conf`` is organized around *local* branches,
177
``authentication.conf`` is organized around *remote* branches or more
178
generally servers. The same authentification definition can even be used
179
for several schemes for servers providing those schemes.
181
``~/.bazaar/authentication.conf`` will use the same file format than
182
``~/.bazaar/bazaar.conf``.
184
Each section will define an authentication definition.
186
The section name is an arbitrary string, only the ``DEFAULT`` value is reserved
187
and should appear as the *last* section.
189
Each section should define:
191
* ``user``: the login to be used,
193
Each section could define:
195
* ``host``: the remote server,
197
* ``port``: the port the server is listening,
199
* ``verify_certificates``: to control certificate verification (useful
200
for self certified hosts). This applies to HTTP[S] only. Accepted values
201
are yes and no, default to yes.
203
* ``path``: the branch location,
205
* ``password``: the password,
207
* ``password_encoding``: the method used to encode the password if any,
209
The default content of the file will be::
213
This section could define:
215
* ``user``: default user to be used.
217
* ``password_encoding``: default password encoding.
222
The use cases described below use the file format defined above.
224
* all FTP connections to the foo.net domain are done with the same (``user``,
227
# Identity on foo.net
234
will provide ('joe', 'secret-pass') for::
236
bzr branch ftp://foo.net/bzr/branch
237
bzr pull ftp://bzr.foo.net/bzr/product/branch/trunk
239
* all connections are done with the same ``user`` (the local one) and the
240
password is always prompted with some exceptions::
242
# Pet projects on hobby.net
246
verify_certificates=no
254
password='c2VjcmV0LXBhc3M='
255
password_encoding=base64
260
* an HTTP server that also acts as a proxy (weird)::
262
# development branches on dev server
285
Note that the proxy should be specified last because it uses no path. An
286
alternative is to specify the port used by the proxy.
291
Depending on the info provided in the URL, bzr will interact with the user in
294
1. ``user`` and ``password`` given in the URL.
298
2. ``user`` given in the URL.
300
Get a password from ``~/.bazaar/authentication.conf`` or prompt
301
for one if none is found.
303
3. No ``user`` given in the URL (and no ``password``).
305
Get a user from ``~/.bazaar/authentication.conf`` or prompt for one if none is
306
found. Continue as 2.
308
Note: A user will be queried only if the server requires it for ``HTTP``, other
309
protocols always require a user.
311
In any case, if the server refuses the authentication, bzr reports to the user
314
Implementation constraints
315
--------------------------
317
* bzr should be able to prompt for a ``user`` for a given (``scheme``, ``host``
318
[, ``realm``]). Note that ``realm`` may be available only after a first
319
connection attempt to the server.
321
* No assumptions should be made about the clients of this service
322
(i.e. Transport is the primary target but plugins must be able to use it as
323
well, the definitions used: (``scheme, host, [port,] path``) are general
324
enough to described credentials for ``svn`` servers or LaunchPad xmlrpc
327
* Policies regarding default users may be taken into account by the
328
implementations, there is no good way to represent that in this specification
329
and stays flexible enough to accommodate various needs (default user policies
330
may differ for different schemes and that may be easier to handle in the code
331
than in the authentication file itself).
333
* If no user can be found by the mechanism described above, bzr should still
334
default to ``getpass.get_user()`` and may attempt a second matching to obtain
337
* As this specification proposes a matching between some credentials
338
definitions and real urls, the implementation should provide an optional UI
339
feedback about which credential definition is used. That will allow the user
340
to validate his definitions.
342
Questions and Answers
343
---------------------
345
* What if a ``.authinfo`` file exists ?
347
* It will be ignored,
349
* Automatic (one-time) conversions may be proposed if sufficient demand
352
* What if a ``.netrc`` file exists ?
354
* It will be honored if the definition specifies
355
``password_encoding=netrc`` once the appropriate plugin have been
358
* What mode should the authentication file use ?
360
* 600 read/write for owner only by default, if another mode (more
361
permissive) is used, a warning will be issued to inform the users of the
364
* What about using ``seahorse`` on Ubuntu or ``KeyChain Access`` on Mac OS X ?
366
* plugins can be written and registered to handle the associated
367
``password_encoding``.
369
* Could it be possible to encode the whole authentication file with a ssh key
372
* yes and if the user configure a ssh-agent it will not be queried for
373
pass-phrase every time we want to query the file for a password. But that
374
seems a bit extreme for a first version.
376
* Why can't bzr update the authentication file when it queried the user for a
379
* a future version may address that but:
381
1. The user may want to decide which passwords are stored in the file and
384
2. The user should decide if the passwords are encoded (and how) or not
385
(but we may default to base64).
387
3. The right definition may be hard to get right, but reducing it to
388
(``scheme, host, [port,] user, password``) may be a good start. I.e. no
389
path so that all paths on the host will match. The user will have to
390
modify it for more complex configurations anyway.