Show More
@@ -1,273 +1,273 b'' | |||||
1 | .. -*- mode: rst; compile-command: "rst2html README.txt README.html" -*- |
|
1 | .. -*- mode: rst; compile-command: "rst2html README.txt README.html" -*- | |
2 |
|
2 | |||
3 | ================= |
|
3 | ================= | |
4 | Mercurial Keyring |
|
4 | Mercurial Keyring | |
5 | ================= |
|
5 | ================= | |
6 |
|
6 | |||
7 | Mercurial Keyring is a Mercurial_ extension used to securely save HTTP |
|
7 | Mercurial Keyring is a Mercurial_ extension used to securely save HTTP | |
8 | and SMTP authentication passwords in password databases (Gnome |
|
8 | and SMTP authentication passwords in password databases (Gnome | |
9 | Keyring, KDE KWallet, OSXKeyChain, Windows Vault etc). |
|
9 | Keyring, KDE KWallet, OSXKeyChain, Windows Vault etc). | |
10 |
|
10 | |||
11 | With ``mercurial_keyring`` active, Mercurial remembers your passwords |
|
11 | With ``mercurial_keyring`` active, Mercurial remembers your passwords | |
12 | and reuses them without prompting (as if you stored them in ``.hgrc``), |
|
12 | and reuses them without prompting (as if you stored them in ``.hgrc``), | |
13 | but password storage is reasonably secure. |
|
13 | but password storage is reasonably secure. | |
14 |
|
14 | |||
15 | Actual password storage is implemented by the keyring_ library, this |
|
15 | Actual password storage is implemented by the keyring_ library, this | |
16 | extension glues it to Mercurial. |
|
16 | extension glues it to Mercurial. | |
17 |
|
17 | |||
18 | .. _keyring: http://pypi.python.org/pypi/keyring |
|
18 | .. _keyring: http://pypi.python.org/pypi/keyring | |
19 | .. _Mercurial: http://mercurial.selenic.com |
|
19 | .. _Mercurial: http://mercurial.selenic.com | |
20 |
|
20 | |||
21 | How does it work |
|
21 | How does it work | |
22 | ================ |
|
22 | ================ | |
23 |
|
23 | |||
24 | On your first pull or push to HTTP url (or first email sent via given |
|
24 | On your first pull or push to HTTP url (or first email sent via given | |
25 | SMTP server), you are prompted for the password, just like bare |
|
25 | SMTP server), you are prompted for the password, just like bare | |
26 | Mercurial does. But the password you entered is saved to appropriate |
|
26 | Mercurial does. But the password you entered is saved to appropriate | |
27 | password database. On successive runs, whenever the password is |
|
27 | password database. On successive runs, whenever the password is | |
28 | needed, ``mercurial_keyring`` checks for password in password |
|
28 | needed, ``mercurial_keyring`` checks for password in password | |
29 | database, and uses it without troubling you. |
|
29 | database, and uses it without troubling you. | |
30 |
|
30 | |||
31 | In case password turns out to be incorrect (for example, because you |
|
31 | In case password turns out to be incorrect (for example, because you | |
32 | changed it, or entered it incorrectly), ``mercurial_keyring`` wipes |
|
32 | changed it, or entered it incorrectly), ``mercurial_keyring`` wipes | |
33 | it, and prompts you again. |
|
33 | it, and prompts you again. | |
34 |
|
34 | |||
35 | You can use many passwords (for various remote urls). Saved passwords |
|
35 | You can use many passwords (for various remote urls). Saved passwords | |
36 | are identified by pair of username and url prefix. See below for |
|
36 | are identified by pair of username and url prefix. See below for | |
37 | information how to configure those properly. |
|
37 | information how to configure those properly. | |
38 |
|
38 | |||
39 | Installation |
|
39 | Installation | |
40 | ============ |
|
40 | ============ | |
41 |
|
41 | |||
42 | Prerequisites |
|
42 | Prerequisites | |
43 | ------------- |
|
43 | ------------- | |
44 |
|
44 | |||
45 | This extension requires keyring_ and `mercurial_extension_utils`_ to |
|
45 | This extension requires keyring_ and `mercurial_extension_utils`_ to | |
46 | work. In many cases both will be installed automatically while you |
|
46 | work. In many cases both will be installed automatically while you | |
47 |
install `mercurial_keyring` |
|
47 | install ``mercurial_keyring``, but you may need to control the process. | |
48 |
|
48 | |||
49 | The keyring_ library can usually be installed by:: |
|
49 | The keyring_ library can usually be installed by:: | |
50 |
|
50 | |||
51 | pip install --user keyring |
|
51 | pip install --user keyring | |
52 |
|
52 | |||
53 | (or ``easy_install keyring``), but on some systems it is preferable to |
|
53 | (or ``easy_install keyring``), but on some systems it is preferable to | |
54 | use official distribution archive. For example, on Debian and Ubuntu, |
|
54 | use official distribution archive. For example, on Debian and Ubuntu, | |
55 | you may install ``python-keyring`` and either ``python-keyring-gnome`` |
|
55 | you may install ``python-keyring`` and either ``python-keyring-gnome`` | |
56 | or ``python-keyring-kwallet`` packages:: |
|
56 | or ``python-keyring-kwallet`` packages:: | |
57 |
|
57 | |||
58 | sudo apt-get install python-keyring python-keyring-gnome |
|
58 | sudo apt-get install python-keyring python-keyring-gnome | |
59 |
|
59 | |||
60 | (this will save you the need to provide working compiler and various |
|
60 | (this will save you the need to provide working compiler and various | |
61 | development libraries). |
|
61 | development libraries). | |
62 |
|
62 | |||
63 | The `mercurial_extension_utils`_ module is tiny Python-only module, |
|
63 | The `mercurial_extension_utils`_ module is tiny Python-only module, | |
64 | which can be installed by:: |
|
64 | which can be installed by:: | |
65 |
|
65 | |||
66 | pip install --user mercurial_extension_utils |
|
66 | pip install --user mercurial_extension_utils | |
67 |
|
67 | |||
68 | but in some cases (Windowsβ¦) require more care. See |
|
68 | but in some cases (Windowsβ¦) require more care. See | |
69 | `mercurial_extension_utils`_ documentation. |
|
69 | `mercurial_extension_utils`_ documentation. | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | Extension installation |
|
72 | Extension installation | |
73 | ---------------------- |
|
73 | ---------------------- | |
74 |
|
74 | |||
75 | There are two possible ways of installing the extension: using PyPi package, |
|
75 | There are two possible ways of installing the extension: using PyPi package, | |
76 | or using source clone. |
|
76 | or using source clone. | |
77 |
|
77 | |||
78 | To install as a package:: |
|
78 | To install as a package:: | |
79 |
|
79 | |||
80 | pip install --user mercurial_keyring |
|
80 | pip install --user mercurial_keyring | |
81 |
|
81 | |||
82 | (or ``sudo pip install mercurial_keyring`` for system-wide |
|
82 | (or ``sudo pip install mercurial_keyring`` for system-wide | |
83 | installation) and then enable it in ``~/.hgrc`` (or |
|
83 | installation) and then enable it in ``~/.hgrc`` (or | |
84 | ``/etc/mercurial/hgrc`` or ``Mercurial.ini``) using:: |
|
84 | ``/etc/mercurial/hgrc`` or ``Mercurial.ini``) using:: | |
85 |
|
85 | |||
86 | [extensions] |
|
86 | [extensions] | |
87 | mercurial_keyring = |
|
87 | mercurial_keyring = | |
88 |
|
88 | |||
89 | To install as source clone, install keyring_ according to instructions above, then |
|
89 | To install as source clone, install keyring_ according to instructions above, then | |
90 | clone:: |
|
90 | clone:: | |
91 |
|
91 | |||
92 | hg clone https://bitbucket.org/Mekk/mercurial_keyring/ |
|
92 | hg clone https://bitbucket.org/Mekk/mercurial_keyring/ | |
93 | hg clone https://bitbucket.org/Mekk/mercurial-extension_utils/ |
|
93 | hg clone https://bitbucket.org/Mekk/mercurial-extension_utils/ | |
94 |
|
94 | |||
95 | and configure Mercurial by telling it full path to the extension |
|
95 | and configure Mercurial by telling it full path to the extension | |
96 | (in ):: |
|
96 | (in ):: | |
97 |
|
97 | |||
98 | [extensions] |
|
98 | [extensions] | |
99 | mercurial_keyring = /path/to/mercurial_keyring/mercurial_keyring.py |
|
99 | mercurial_keyring = /path/to/mercurial_keyring/mercurial_keyring.py | |
100 |
|
100 | |||
101 | .. _the code: |
|
101 | .. _the code: | |
102 | .. _mercurial_keyring.py: http://bitbucket.org/Mekk/mercurial_keyring/src/tip/mercurial_keyring.py |
|
102 | .. _mercurial_keyring.py: http://bitbucket.org/Mekk/mercurial_keyring/src/tip/mercurial_keyring.py | |
103 |
|
103 | |||
104 | Password backend configuration |
|
104 | Password backend configuration | |
105 | ============================== |
|
105 | ============================== | |
106 |
|
106 | |||
107 | The library should usually pick the most appropriate password backend |
|
107 | The library should usually pick the most appropriate password backend | |
108 | without configuration. Still, if necessary, it can be configured using |
|
108 | without configuration. Still, if necessary, it can be configured using | |
109 | ``keyringrc.cfg`` file. Refer to keyring_ docs for more details. |
|
109 | ``keyringrc.cfg`` file. Refer to keyring_ docs for more details. | |
110 |
|
110 | |||
111 | .. note:: |
|
111 | .. note:: | |
112 |
|
112 | |||
113 | With current (as I write) keyring (5.6), this file is (on Linux) |
|
113 | With current (as I write) keyring (5.6), this file is (on Linux) | |
114 | located at ``~/.local/share/python_keyring/keyringrc.cfg`` and |
|
114 | located at ``~/.local/share/python_keyring/keyringrc.cfg`` and | |
115 | it's example content look like:: |
|
115 | it's example content look like:: | |
116 |
|
116 | |||
117 | [backend] |
|
117 | [backend] | |
118 | default-keyring=keyring.backends.Gnome.Keyring |
|
118 | default-keyring=keyring.backends.Gnome.Keyring | |
119 | # default-keyring=keyring.backends.kwallet.Keyring |
|
119 | # default-keyring=keyring.backends.kwallet.Keyring | |
120 |
|
120 | |||
121 | For list of known backends run ``pydoc keyring.backends``. |
|
121 | For list of known backends run ``pydoc keyring.backends``. | |
122 |
|
122 | |||
123 |
|
123 | |||
124 | ``hgrc`` configuration (HTTP) |
|
124 | ``hgrc`` configuration (HTTP) | |
125 | =============================== |
|
125 | =============================== | |
126 |
|
126 | |||
127 | Mercurial Keyring uses standard Mercurial ``[auth]`` configuration to |
|
127 | Mercurial Keyring uses standard Mercurial ``[auth]`` configuration to | |
128 | detect your username (on given remote) and url prefix. You are |
|
128 | detect your username (on given remote) and url prefix. You are | |
129 | strongly advised to configure both. |
|
129 | strongly advised to configure both. | |
130 |
|
130 | |||
131 | Without the username ``mercurial_keyring`` can't save or restore |
|
131 | Without the username ``mercurial_keyring`` can't save or restore | |
132 | passwords, so it disables itself. |
|
132 | passwords, so it disables itself. | |
133 |
|
133 | |||
134 | Without url prefix ``mercurial_keyring`` works, but binds passwords to |
|
134 | Without url prefix ``mercurial_keyring`` works, but binds passwords to | |
135 | repository urls. That means you will have to (re)enter password for |
|
135 | repository urls. That means you will have to (re)enter password for | |
136 | every repository cloned from given remote (and that there will be many |
|
136 | every repository cloned from given remote (and that there will be many | |
137 | copies of this password in secure storage). |
|
137 | copies of this password in secure storage). | |
138 |
|
138 | |||
139 | Repository level configuration |
|
139 | Repository level configuration | |
140 | ------------------------------------ |
|
140 | ------------------------------------ | |
141 |
|
141 | |||
142 | Edit repository-local ``.hg/hgrc`` and save there the remote |
|
142 | Edit repository-local ``.hg/hgrc`` and save there the remote | |
143 | repository path and the username, but do not save the password. For |
|
143 | repository path and the username, but do not save the password. For | |
144 | example: |
|
144 | example: | |
145 |
|
145 | |||
146 | :: |
|
146 | :: | |
147 |
|
147 | |||
148 | [paths] |
|
148 | [paths] | |
149 | myremote = https://my.server.com/hgrepo/someproject |
|
149 | myremote = https://my.server.com/hgrepo/someproject | |
150 |
|
150 | |||
151 | [auth] |
|
151 | [auth] | |
152 | myremote.prefix = https://my.server.com/hgrepo |
|
152 | myremote.prefix = https://my.server.com/hgrepo | |
153 | myremote.username = John |
|
153 | myremote.username = John | |
154 |
|
154 | |||
155 | Simpler form with url-embedded name can also be used: |
|
155 | Simpler form with url-embedded name can also be used: | |
156 |
|
156 | |||
157 | :: |
|
157 | :: | |
158 |
|
158 | |||
159 | [paths] |
|
159 | [paths] | |
160 | bitbucket = https://John@my.server.com/hgrepo/someproject/ |
|
160 | bitbucket = https://John@my.server.com/hgrepo/someproject/ | |
161 |
|
161 | |||
162 | Note that all repositories sharing the same ``prefix`` share the same |
|
162 | Note that all repositories sharing the same ``prefix`` share the same | |
163 | password. |
|
163 | password. | |
164 |
|
164 | |||
165 | Mercurial allows also for password in ``.hg/hgrc`` (either given by |
|
165 | Mercurial allows also for password in ``.hg/hgrc`` (either given by | |
166 | ``Β«prefixΒ».password``, or embedded in url). If such password is found, |
|
166 | ``Β«prefixΒ».password``, or embedded in url). If such password is found, | |
167 |
Mercurial Keyring disables itself |
|
167 | Mercurial Keyring disables itself. | |
168 |
|
168 | |||
169 |
|
169 | |||
170 | Account-level configuration |
|
170 | Account-level configuration | |
171 | --------------------------- |
|
171 | --------------------------- | |
172 |
|
172 | |||
173 | If you are consistent about remote repository nicknames, you can |
|
173 | If you are consistent about remote repository nicknames, you can | |
174 | configure the username in your `~/.hgrc` (`.hgrc` in your home |
|
174 | configure the username in your `~/.hgrc` (`.hgrc` in your home | |
175 | directory). For example, write there:: |
|
175 | directory). For example, write there:: | |
176 |
|
176 | |||
177 | [auth] |
|
177 | [auth] | |
178 | acme.prefix = hg.acme.com/repositories |
|
178 | acme.prefix = hg.acme.com/repositories | |
179 | acme.username = johnny |
|
179 | acme.username = johnny | |
180 | acme.schemes = http https |
|
180 | acme.schemes = http https | |
181 | bitbucket.prefix = https://bitbucket.org |
|
181 | bitbucket.prefix = https://bitbucket.org | |
182 | bitbucket.username = Mekk |
|
182 | bitbucket.username = Mekk | |
183 | mydep.prefix = https://dev.acmeorg.com |
|
183 | mydep.prefix = https://dev.acmeorg.com | |
184 | mydep.username = drmartin |
|
184 | mydep.username = drmartin | |
185 |
|
185 | |||
186 | and as long as you will be using alias `acme` for repositories like |
|
186 | and as long as you will be using alias ``acme`` for repositories like | |
187 | `https://hg.acme.com/repositories/my_beautiful_app`, username |
|
187 | ``https://hg.acme.com/repositories/my_beautiful_app``, username | |
188 |
`johnn |
|
188 | ``johnny`` will be used, and the same password reused. Similarly | |
189 | any ``hg push bitbucket`` will share the same password. |
|
189 | any ``hg push bitbucket`` will share the same password. | |
190 |
|
190 | |||
191 | With such config repository-level ``.hg/hgrc`` need only contain |
|
191 | With such config repository-level ``.hg/hgrc`` need only contain | |
192 | ``[paths]``. |
|
192 | ``[paths]``. | |
193 |
|
193 | |||
194 | Additional advantage of this method is that it works also during |
|
194 | Additional advantage of this method is that it works also during | |
195 | `clone`. |
|
195 | `clone`. | |
196 |
|
196 | |||
197 |
|
197 | |||
198 | .. note:: |
|
198 | .. note:: | |
199 |
|
199 | |||
200 | Mercurial Keyring works well with `Path Pattern`_. On my setup I use:: |
|
200 | Mercurial Keyring works well with `Path Pattern`_. On my setup I use:: | |
201 |
|
201 | |||
202 | [path_pattern] |
|
202 | [path_pattern] | |
203 | bitbucket.local = ~/devel/{below} |
|
203 | bitbucket.local = ~/devel/{below} | |
204 | bitbucket.remote = https://bitbucket.org/Mekk/{below:/=-} |
|
204 | bitbucket.remote = https://bitbucket.org/Mekk/{below:/=-} | |
205 |
|
205 | |||
206 | so all my repositories understand ``hg push bitbucket`` without |
|
206 | so all my repositories understand ``hg push bitbucket`` without | |
207 | any repository-level configuration. |
|
207 | any repository-level configuration. | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | ``hgrc`` configuration (SMTP) |
|
210 | ``hgrc`` configuration (SMTP) | |
211 | =============================== |
|
211 | =============================== | |
212 |
|
212 | |||
213 | Edit either repository-local ``.hg/hgrc``, or ``~/.hgrc`` and set |
|
213 | Edit either repository-local ``.hg/hgrc``, or ``~/.hgrc`` and set | |
214 | there all standard email and smtp properties, including SMTP |
|
214 | there all standard email and smtp properties, including SMTP | |
215 | username, but without SMTP password. For example: |
|
215 | username, but without SMTP password. For example: | |
216 |
|
216 | |||
217 | :: |
|
217 | :: | |
218 |
|
218 | |||
219 | [email] |
|
219 | [email] | |
220 | method = smtp |
|
220 | method = smtp | |
221 | from = Joe Doe <Joe.Doe@remote.com> |
|
221 | from = Joe Doe <Joe.Doe@remote.com> | |
222 |
|
222 | |||
223 | [smtp] |
|
223 | [smtp] | |
224 | host = smtp.gmail.com |
|
224 | host = smtp.gmail.com | |
225 | port = 587 |
|
225 | port = 587 | |
226 | username = JoeDoe@gmail.com |
|
226 | username = JoeDoe@gmail.com | |
227 | tls = true |
|
227 | tls = true | |
228 |
|
228 | |||
229 | Just as in case of HTTP, you *must* set username, but *must not* set |
|
229 | Just as in case of HTTP, you *must* set username, but *must not* set | |
230 | password here to use the extension, in other cases it will revert to |
|
230 | password here to use the extension, in other cases it will revert to | |
231 | the default behavior. |
|
231 | the default behavior. | |
232 |
|
232 | |||
233 | Usage |
|
233 | Usage | |
234 | ===== |
|
234 | ===== | |
235 |
|
235 | |||
236 | Configure the repository as above, then just ``hg pull``, ``hg push``, |
|
236 | Configure the repository as above, then just ``hg pull``, ``hg push``, | |
237 | etc. You should be asked for the password only once (per every |
|
237 | etc. You should be asked for the password only once (per every | |
238 | username and remote repository prefix or url combination). |
|
238 | username and remote repository prefix or url combination). | |
239 |
|
239 | |||
240 | Similarly, for email, configure as above and just ``hg email``. |
|
240 | Similarly, for email, configure as above and just ``hg email``. | |
241 | Again, you will be asked for the password once (per every username and |
|
241 | Again, you will be asked for the password once (per every username and | |
242 | email server address combination). |
|
242 | email server address combination). | |
243 |
|
243 | |||
244 | Implementation details |
|
244 | Implementation details | |
245 | ====================== |
|
245 | ====================== | |
246 |
|
246 | |||
247 | The extension is monkey-patching the mercurial ``passwordmgr`` class |
|
247 | The extension is monkey-patching the mercurial ``passwordmgr`` class | |
248 | to replace the find_user_password method. Detailed order of operations |
|
248 | to replace the ``find_user_password`` method. Detailed order of operations | |
249 | is described in the comments inside `the code`_. |
|
249 | is described in the comments inside `the code`_. | |
250 |
|
250 | |||
251 | History |
|
251 | History | |
252 | ========== |
|
252 | ========== | |
253 |
|
253 | |||
254 | See `HISTORY.txt`_. |
|
254 | See `HISTORY.txt`_. | |
255 |
|
255 | |||
256 | Development |
|
256 | Development | |
257 | =========== |
|
257 | =========== | |
258 |
|
258 | |||
259 | Development is tracked on BitBucket, see |
|
259 | Development is tracked on BitBucket, see | |
260 | http://bitbucket.org/Mekk/mercurial_keyring/ |
|
260 | http://bitbucket.org/Mekk/mercurial_keyring/ | |
261 |
|
261 | |||
262 |
|
262 | |||
263 | Additional notes |
|
263 | Additional notes | |
264 | ================ |
|
264 | ================ | |
265 |
|
265 | |||
266 | Information about this extension is also available |
|
266 | Information about this extension is also available | |
267 | on Mercurial Wiki: http://mercurial.selenic.com/wiki/KeyringExtension |
|
267 | on Mercurial Wiki: http://mercurial.selenic.com/wiki/KeyringExtension | |
268 |
|
268 | |||
269 | .. _HISTORY.txt: http://bitbucket.org/Mekk/mercurial_keyring/src/tip/HISTORY.txt |
|
269 | .. _HISTORY.txt: http://bitbucket.org/Mekk/mercurial_keyring/src/tip/HISTORY.txt | |
270 | .. _TortoiseHg: http://tortoisehg.bitbucket.org/ |
|
270 | .. _TortoiseHg: http://tortoisehg.bitbucket.org/ | |
271 | .. _Mercurial: http://mercurial.selenic.com |
|
271 | .. _Mercurial: http://mercurial.selenic.com | |
272 | .. _mercurial_extension_utils: https://bitbucket.org/Mekk/mercurial-extension_utils/ |
|
272 | .. _mercurial_extension_utils: https://bitbucket.org/Mekk/mercurial-extension_utils/ | |
273 | .. _Path Pattern: https://bitbucket.org/Mekk/mercurial-path_pattern/ |
|
273 | .. _Path Pattern: https://bitbucket.org/Mekk/mercurial-path_pattern/ |
General Comments 0
You need to be logged in to leave comments.
Login now