##// END OF EJS Templates
ssh: mention in docs how to use multiple authorized_keys files
Mads Kiilerich -
r8237:a9e71e61 stable
parent child Browse files
Show More
@@ -1,636 +1,646 b''
1 .. _setup:
1 .. _setup:
2
2
3 =====
3 =====
4 Setup
4 Setup
5 =====
5 =====
6
6
7
7
8 Setting up Kallithea
8 Setting up Kallithea
9 --------------------
9 --------------------
10
10
11 First, you will need to create a Kallithea configuration file. Run the
11 First, you will need to create a Kallithea configuration file. Run the
12 following command to do so::
12 following command to do so::
13
13
14 kallithea-cli config-create my.ini
14 kallithea-cli config-create my.ini
15
15
16 This will create the file ``my.ini`` in the current directory. This
16 This will create the file ``my.ini`` in the current directory. This
17 configuration file contains the various settings for Kallithea, e.g.
17 configuration file contains the various settings for Kallithea, e.g.
18 proxy port, email settings, usage of static files, cache, Celery
18 proxy port, email settings, usage of static files, cache, Celery
19 settings, and logging. Extra settings can be specified like::
19 settings, and logging. Extra settings can be specified like::
20
20
21 kallithea-cli config-create my.ini host=8.8.8.8 "[handler_console]" formatter=color_formatter
21 kallithea-cli config-create my.ini host=8.8.8.8 "[handler_console]" formatter=color_formatter
22
22
23 Next, you need to create the databases used by Kallithea. It is recommended to
23 Next, you need to create the databases used by Kallithea. It is recommended to
24 use PostgreSQL or SQLite (default). If you choose a database other than the
24 use PostgreSQL or SQLite (default). If you choose a database other than the
25 default, ensure you properly adjust the database URL in your ``my.ini``
25 default, ensure you properly adjust the database URL in your ``my.ini``
26 configuration file to use this other database. Kallithea currently supports
26 configuration file to use this other database. Kallithea currently supports
27 PostgreSQL, SQLite and MySQL databases. Create the database by running
27 PostgreSQL, SQLite and MySQL databases. Create the database by running
28 the following command::
28 the following command::
29
29
30 kallithea-cli db-create -c my.ini
30 kallithea-cli db-create -c my.ini
31
31
32 This will prompt you for a "root" path. This "root" path is the location where
32 This will prompt you for a "root" path. This "root" path is the location where
33 Kallithea will store all of its repositories on the current machine. After
33 Kallithea will store all of its repositories on the current machine. After
34 entering this "root" path ``db-create`` will also prompt you for a username
34 entering this "root" path ``db-create`` will also prompt you for a username
35 and password for the initial admin account which ``db-create`` sets
35 and password for the initial admin account which ``db-create`` sets
36 up for you.
36 up for you.
37
37
38 The ``db-create`` values can also be given on the command line.
38 The ``db-create`` values can also be given on the command line.
39 Example::
39 Example::
40
40
41 kallithea-cli db-create -c my.ini --user=nn --password=secret --email=nn@example.com --repos=/srv/repos
41 kallithea-cli db-create -c my.ini --user=nn --password=secret --email=nn@example.com --repos=/srv/repos
42
42
43 The ``db-create`` command will create all needed tables and an
43 The ``db-create`` command will create all needed tables and an
44 admin account. When choosing a root path you can either use a new
44 admin account. When choosing a root path you can either use a new
45 empty location, or a location which already contains existing
45 empty location, or a location which already contains existing
46 repositories. If you choose a location which contains existing
46 repositories. If you choose a location which contains existing
47 repositories Kallithea will add all of the repositories at the chosen
47 repositories Kallithea will add all of the repositories at the chosen
48 location to its database. (Note: make sure you specify the correct
48 location to its database. (Note: make sure you specify the correct
49 path to the root).
49 path to the root).
50
50
51 .. note:: the given path for Mercurial_ repositories **must** be write
51 .. note:: the given path for Mercurial_ repositories **must** be write
52 accessible for the application. It's very important since
52 accessible for the application. It's very important since
53 the Kallithea web interface will work without write access,
53 the Kallithea web interface will work without write access,
54 but when trying to do a push it will fail with permission
54 but when trying to do a push it will fail with permission
55 denied errors unless it has write access.
55 denied errors unless it has write access.
56
56
57 Finally, prepare the front-end by running::
57 Finally, prepare the front-end by running::
58
58
59 kallithea-cli front-end-build
59 kallithea-cli front-end-build
60
60
61 You are now ready to use Kallithea. To run it simply execute::
61 You are now ready to use Kallithea. To run it simply execute::
62
62
63 gearbox serve -c my.ini
63 gearbox serve -c my.ini
64
64
65 - This command runs the Kallithea server. The web app should be available at
65 - This command runs the Kallithea server. The web app should be available at
66 http://127.0.0.1:5000. The IP address and port is configurable via the
66 http://127.0.0.1:5000. The IP address and port is configurable via the
67 configuration file created in the previous step.
67 configuration file created in the previous step.
68 - Log in to Kallithea using the admin account created when running ``db-create``.
68 - Log in to Kallithea using the admin account created when running ``db-create``.
69 - The default permissions on each repository is read, and the owner is admin.
69 - The default permissions on each repository is read, and the owner is admin.
70 Remember to update these if needed.
70 Remember to update these if needed.
71 - In the admin panel you can toggle LDAP, anonymous, and permissions
71 - In the admin panel you can toggle LDAP, anonymous, and permissions
72 settings, as well as edit more advanced options on users and
72 settings, as well as edit more advanced options on users and
73 repositories.
73 repositories.
74
74
75
75
76 Internationalization (i18n support)
76 Internationalization (i18n support)
77 -----------------------------------
77 -----------------------------------
78
78
79 The Kallithea web interface is automatically displayed in the user's preferred
79 The Kallithea web interface is automatically displayed in the user's preferred
80 language, as indicated by the browser. Thus, different users may see the
80 language, as indicated by the browser. Thus, different users may see the
81 application in different languages. If the requested language is not available
81 application in different languages. If the requested language is not available
82 (because the translation file for that language does not yet exist or is
82 (because the translation file for that language does not yet exist or is
83 incomplete), English is used.
83 incomplete), English is used.
84
84
85 If you want to disable automatic language detection and instead configure a
85 If you want to disable automatic language detection and instead configure a
86 fixed language regardless of user preference, set ``i18n.enabled = false`` and
86 fixed language regardless of user preference, set ``i18n.enabled = false`` and
87 specify another language by setting ``i18n.lang`` in the Kallithea
87 specify another language by setting ``i18n.lang`` in the Kallithea
88 configuration file.
88 configuration file.
89
89
90
90
91 Using Kallithea with SSH
91 Using Kallithea with SSH
92 ------------------------
92 ------------------------
93
93
94 Kallithea supports repository access via SSH key based authentication.
94 Kallithea supports repository access via SSH key based authentication.
95 This means:
95 This means:
96
96
97 - repository URLs like ``ssh://kallithea@example.com/name/of/repository``
97 - repository URLs like ``ssh://kallithea@example.com/name/of/repository``
98
98
99 - all network traffic for both read and write happens over the SSH protocol on
99 - all network traffic for both read and write happens over the SSH protocol on
100 port 22, without using HTTP/HTTPS nor the Kallithea WSGI application
100 port 22, without using HTTP/HTTPS nor the Kallithea WSGI application
101
101
102 - encryption and authentication protocols are managed by the system's ``sshd``
102 - encryption and authentication protocols are managed by the system's ``sshd``
103 process, with all users using the same Kallithea system user (e.g.
103 process, with all users using the same Kallithea system user (e.g.
104 ``kallithea``) when connecting to the SSH server, but with users' public keys
104 ``kallithea``) when connecting to the SSH server, but with users' public keys
105 in the Kallithea system user's `.ssh/authorized_keys` file granting each user
105 in the Kallithea system user's `.ssh/authorized_keys` file granting each user
106 sandboxed access to the repositories.
106 sandboxed access to the repositories.
107
107
108 - users and admins can manage SSH public keys in the web UI
108 - users and admins can manage SSH public keys in the web UI
109
109
110 - in their SSH client configuration, users can configure how the client should
110 - in their SSH client configuration, users can configure how the client should
111 control access to their SSH key - without passphrase, with passphrase, and
111 control access to their SSH key - without passphrase, with passphrase, and
112 optionally with passphrase caching in the local shell session (``ssh-agent``).
112 optionally with passphrase caching in the local shell session (``ssh-agent``).
113 This is standard SSH functionality, not something Kallithea provides or
113 This is standard SSH functionality, not something Kallithea provides or
114 interferes with.
114 interferes with.
115
115
116 - network communication between client and server happens in a bidirectional
116 - network communication between client and server happens in a bidirectional
117 stateful stream, and will in some cases be faster than HTTP/HTTPS with several
117 stateful stream, and will in some cases be faster than HTTP/HTTPS with several
118 stateless round-trips.
118 stateless round-trips.
119
119
120 .. note:: At this moment, repository access via SSH has been tested on Unix
120 .. note:: At this moment, repository access via SSH has been tested on Unix
121 only. Windows users that care about SSH are invited to test it and report
121 only. Windows users that care about SSH are invited to test it and report
122 problems, ideally contributing patches that solve these problems.
122 problems, ideally contributing patches that solve these problems.
123
123
124 Users and admins can upload SSH public keys (e.g. ``.ssh/id_rsa.pub``) through
124 Users and admins can upload SSH public keys (e.g. ``.ssh/id_rsa.pub``) through
125 the web interface. The server's ``.ssh/authorized_keys`` file is automatically
125 the web interface. The server's ``.ssh/authorized_keys`` file is automatically
126 maintained with an entry for each SSH key. Each entry will tell ``sshd`` to run
126 maintained with an entry for each SSH key. Each entry will tell ``sshd`` to run
127 ``kallithea-cli`` with the ``ssh-serve`` sub-command and the right Kallithea user ID
127 ``kallithea-cli`` with the ``ssh-serve`` sub-command and the right Kallithea user ID
128 when encountering the corresponding SSH key.
128 when encountering the corresponding SSH key.
129
129
130 To enable SSH repository access, Kallithea must be configured with the path to
130 To enable SSH repository access, Kallithea must be configured with the path to
131 the ``.ssh/authorized_keys`` file for the Kallithea user, and the path to the
131 the ``.ssh/authorized_keys`` file for the Kallithea user, and the path to the
132 ``kallithea-cli`` command. Put something like this in the ``.ini`` file::
132 ``kallithea-cli`` command. Put something like this in the ``.ini`` file::
133
133
134 ssh_enabled = true
134 ssh_enabled = true
135 ssh_authorized_keys = /home/kallithea/.ssh/authorized_keys
135 ssh_authorized_keys = /home/kallithea/.ssh/authorized_keys
136 kallithea_cli_path = /srv/kallithea/venv/bin/kallithea-cli
136 kallithea_cli_path = /srv/kallithea/venv/bin/kallithea-cli
137
137
138 The SSH service must be running, and the Kallithea user account must be active
138 The SSH service must be running, and the Kallithea user account must be active
139 (not necessarily with password access, but public key access must be enabled),
139 (not necessarily with password access, but public key access must be enabled),
140 all file permissions must be set as sshd wants it, and ``authorized_keys`` must
140 all file permissions must be set as sshd wants it, and ``authorized_keys`` must
141 be writeable by the Kallithea user.
141 be writeable by the Kallithea user.
142
142
143 .. note:: The ``authorized_keys`` file will be rewritten from scratch on
143 .. note:: The ``authorized_keys`` file will be rewritten from scratch on
144 each update. If it already exists with other data, Kallithea will not
144 each update. If it already exists with other data, Kallithea will not
145 overwrite the existing ``authorized_keys``, and the server process will
145 overwrite the existing ``authorized_keys``, and the server process will
146 instead throw an exception. The system administrator thus cannot ssh
146 instead throw an exception. The system administrator thus cannot ssh
147 directly to the Kallithea user but must use su/sudo from another account.
147 directly to the Kallithea user but must use su/sudo from another account.
148
148
149 If ``/home/kallithea/.ssh/`` (the directory of the path specified in the
149 If ``/home/kallithea/.ssh/`` (the directory of the path specified in the
150 ``ssh_authorized_keys`` setting of the ``.ini`` file) does not exist as a
150 ``ssh_authorized_keys`` setting of the ``.ini`` file) does not exist as a
151 directory, Kallithea will attempt to create it. If that path exists but is
151 directory, Kallithea will attempt to create it. If that path exists but is
152 *not* a directory, or is not readable-writable-executable by the server
152 *not* a directory, or is not readable-writable-executable by the server
153 process, the server process will raise an exception each time it attempts to
153 process, the server process will raise an exception each time it attempts to
154 write the ``authorized_keys`` file.
154 write the ``authorized_keys`` file.
155
155
156 .. note:: It is possible to configure the SSH server to look for authorized
157 keys in multiple files, for example reserving ``ssh/authorized_keys`` to be
158 used for normal SSH and with Kallithea using
159 ``.ssh/authorized_keys_kallithea``. In ``/etc/ssh/sshd_config`` set
160 ``AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys_kallithea``
161 and restart sshd, and in ``my.ini`` set ``ssh_authorized_keys =
162 /home/kallithea/.ssh/authorized_keys_kallithea``. Note that this new
163 location will apply to all system users, and that multiple entries for the
164 same SSH key will shadow each other.
165
156 .. warning:: The handling of SSH access is steered directly by the command
166 .. warning:: The handling of SSH access is steered directly by the command
157 specified in the ``authorized_keys`` file. There is no interaction with the
167 specified in the ``authorized_keys`` file. There is no interaction with the
158 web UI. Once SSH access is correctly configured and enabled, it will work
168 web UI. Once SSH access is correctly configured and enabled, it will work
159 regardless of whether the Kallithea web process is actually running. Hence,
169 regardless of whether the Kallithea web process is actually running. Hence,
160 if you want to perform repository or server maintenance and want to fully
170 if you want to perform repository or server maintenance and want to fully
161 disable all access to the repositories, disable SSH access by setting
171 disable all access to the repositories, disable SSH access by setting
162 ``ssh_enabled = false`` in the correct ``.ini`` file (i.e. the ``.ini`` file
172 ``ssh_enabled = false`` in the correct ``.ini`` file (i.e. the ``.ini`` file
163 specified in the ``authorized_keys`` file.)
173 specified in the ``authorized_keys`` file.)
164
174
165 The ``authorized_keys`` file can be updated manually with ``kallithea-cli
175 The ``authorized_keys`` file can be updated manually with ``kallithea-cli
166 ssh-update-authorized-keys -c my.ini``. This command is not needed in normal
176 ssh-update-authorized-keys -c my.ini``. This command is not needed in normal
167 operation but is for example useful after changing SSH-related settings in the
177 operation but is for example useful after changing SSH-related settings in the
168 ``.ini`` file or renaming that file. (The path to the ``.ini`` file is used in
178 ``.ini`` file or renaming that file. (The path to the ``.ini`` file is used in
169 the generated ``authorized_keys`` file).
179 the generated ``authorized_keys`` file).
170
180
171
181
172 Setting up Whoosh full text search
182 Setting up Whoosh full text search
173 ----------------------------------
183 ----------------------------------
174
184
175 Kallithea provides full text search of repositories using `Whoosh`__.
185 Kallithea provides full text search of repositories using `Whoosh`__.
176
186
177 .. __: https://whoosh.readthedocs.io/en/latest/
187 .. __: https://whoosh.readthedocs.io/en/latest/
178
188
179 For an incremental index build, run::
189 For an incremental index build, run::
180
190
181 kallithea-cli index-create -c my.ini
191 kallithea-cli index-create -c my.ini
182
192
183 For a full index rebuild, run::
193 For a full index rebuild, run::
184
194
185 kallithea-cli index-create -c my.ini --full
195 kallithea-cli index-create -c my.ini --full
186
196
187 The ``--repo-location`` option allows the location of the repositories to be overridden;
197 The ``--repo-location`` option allows the location of the repositories to be overridden;
188 usually, the location is retrieved from the Kallithea database.
198 usually, the location is retrieved from the Kallithea database.
189
199
190 The ``--index-only`` option can be used to limit the indexed repositories to a comma-separated list::
200 The ``--index-only`` option can be used to limit the indexed repositories to a comma-separated list::
191
201
192 kallithea-cli index-create -c my.ini --index-only=vcs,kallithea
202 kallithea-cli index-create -c my.ini --index-only=vcs,kallithea
193
203
194 To keep your index up-to-date it is necessary to do periodic index builds;
204 To keep your index up-to-date it is necessary to do periodic index builds;
195 for this, it is recommended to use a crontab entry. Example::
205 for this, it is recommended to use a crontab entry. Example::
196
206
197 0 3 * * * /path/to/virtualenv/bin/kallithea-cli index-create -c /path/to/kallithea/my.ini
207 0 3 * * * /path/to/virtualenv/bin/kallithea-cli index-create -c /path/to/kallithea/my.ini
198
208
199 When using incremental mode (the default), Whoosh will check the last
209 When using incremental mode (the default), Whoosh will check the last
200 modification date of each file and add it to be reindexed if a newer file is
210 modification date of each file and add it to be reindexed if a newer file is
201 available. The indexing daemon checks for any removed files and removes them
211 available. The indexing daemon checks for any removed files and removes them
202 from index.
212 from index.
203
213
204 If you want to rebuild the index from scratch, you can use the ``-f`` flag as above,
214 If you want to rebuild the index from scratch, you can use the ``-f`` flag as above,
205 or in the admin panel you can check the "build from scratch" checkbox.
215 or in the admin panel you can check the "build from scratch" checkbox.
206
216
207
217
208 Integration with issue trackers
218 Integration with issue trackers
209 -------------------------------
219 -------------------------------
210
220
211 Kallithea provides a simple integration with issue trackers. It's possible
221 Kallithea provides a simple integration with issue trackers. It's possible
212 to define a regular expression that will match an issue ID in commit messages,
222 to define a regular expression that will match an issue ID in commit messages,
213 and have that replaced with a URL to the issue.
223 and have that replaced with a URL to the issue.
214
224
215 This is achieved with following three variables in the ini file::
225 This is achieved with following three variables in the ini file::
216
226
217 issue_pat = #(\d+)
227 issue_pat = #(\d+)
218 issue_server_link = https://issues.example.com/{repo}/issue/\1
228 issue_server_link = https://issues.example.com/{repo}/issue/\1
219 issue_sub =
229 issue_sub =
220
230
221 ``issue_pat`` is the regular expression describing which strings in
231 ``issue_pat`` is the regular expression describing which strings in
222 commit messages will be treated as issue references. The expression can/should
232 commit messages will be treated as issue references. The expression can/should
223 have one or more parenthesized groups that can later be referred to in
233 have one or more parenthesized groups that can later be referred to in
224 ``issue_server_link`` and ``issue_sub`` (see below). If you prefer, named groups
234 ``issue_server_link`` and ``issue_sub`` (see below). If you prefer, named groups
225 can be used instead of simple parenthesized groups.
235 can be used instead of simple parenthesized groups.
226
236
227 If the pattern should only match if it is preceded by whitespace, add the
237 If the pattern should only match if it is preceded by whitespace, add the
228 following string before the actual pattern: ``(?:^|(?<=\s))``.
238 following string before the actual pattern: ``(?:^|(?<=\s))``.
229 If the pattern should only match if it is followed by whitespace, add the
239 If the pattern should only match if it is followed by whitespace, add the
230 following string after the actual pattern: ``(?:$|(?=\s))``.
240 following string after the actual pattern: ``(?:$|(?=\s))``.
231 These expressions use lookbehind and lookahead assertions of the Python regular
241 These expressions use lookbehind and lookahead assertions of the Python regular
232 expression module to avoid the whitespace to be part of the actual pattern,
242 expression module to avoid the whitespace to be part of the actual pattern,
233 otherwise the link text will also contain that whitespace.
243 otherwise the link text will also contain that whitespace.
234
244
235 Matched issue references are replaced with the link specified in
245 Matched issue references are replaced with the link specified in
236 ``issue_server_link``, in which any backreferences are resolved. Backreferences
246 ``issue_server_link``, in which any backreferences are resolved. Backreferences
237 can be ``\1``, ``\2``, ... or for named groups ``\g<groupname>``.
247 can be ``\1``, ``\2``, ... or for named groups ``\g<groupname>``.
238 The special token ``{repo}`` is replaced with the full repository path
248 The special token ``{repo}`` is replaced with the full repository path
239 (including repository groups), while token ``{repo_name}`` is replaced with the
249 (including repository groups), while token ``{repo_name}`` is replaced with the
240 repository name (without repository groups).
250 repository name (without repository groups).
241
251
242 The link text is determined by ``issue_sub``, which can be a string containing
252 The link text is determined by ``issue_sub``, which can be a string containing
243 backreferences to the groups specified in ``issue_pat``. If ``issue_sub`` is
253 backreferences to the groups specified in ``issue_pat``. If ``issue_sub`` is
244 empty, then the text matched by ``issue_pat`` is used verbatim.
254 empty, then the text matched by ``issue_pat`` is used verbatim.
245
255
246 The example settings shown above match issues in the format ``#<number>``.
256 The example settings shown above match issues in the format ``#<number>``.
247 This will cause the text ``#300`` to be transformed into a link:
257 This will cause the text ``#300`` to be transformed into a link:
248
258
249 .. code-block:: html
259 .. code-block:: html
250
260
251 <a href="https://issues.example.com/example_repo/issue/300">#300</a>
261 <a href="https://issues.example.com/example_repo/issue/300">#300</a>
252
262
253 The following example transforms a text starting with either of 'pullrequest',
263 The following example transforms a text starting with either of 'pullrequest',
254 'pull request' or 'PR', followed by an optional space, then a pound character
264 'pull request' or 'PR', followed by an optional space, then a pound character
255 (#) and one or more digits, into a link with the text 'PR #' followed by the
265 (#) and one or more digits, into a link with the text 'PR #' followed by the
256 digits::
266 digits::
257
267
258 issue_pat = (pullrequest|pull request|PR) ?#(\d+)
268 issue_pat = (pullrequest|pull request|PR) ?#(\d+)
259 issue_server_link = https://issues.example.com/\2
269 issue_server_link = https://issues.example.com/\2
260 issue_sub = PR #\2
270 issue_sub = PR #\2
261
271
262 The following example demonstrates how to require whitespace before the issue
272 The following example demonstrates how to require whitespace before the issue
263 reference in order for it to be recognized, such that the text ``issue#123`` will
273 reference in order for it to be recognized, such that the text ``issue#123`` will
264 not cause a match, but ``issue #123`` will::
274 not cause a match, but ``issue #123`` will::
265
275
266 issue_pat = (?:^|(?<=\s))#(\d+)
276 issue_pat = (?:^|(?<=\s))#(\d+)
267 issue_server_link = https://issues.example.com/\1
277 issue_server_link = https://issues.example.com/\1
268 issue_sub =
278 issue_sub =
269
279
270 If needed, more than one pattern can be specified by appending a unique suffix to
280 If needed, more than one pattern can be specified by appending a unique suffix to
271 the variables. For example, also demonstrating the use of named groups::
281 the variables. For example, also demonstrating the use of named groups::
272
282
273 issue_pat_wiki = wiki-(?P<pagename>\S+)
283 issue_pat_wiki = wiki-(?P<pagename>\S+)
274 issue_server_link_wiki = https://wiki.example.com/\g<pagename>
284 issue_server_link_wiki = https://wiki.example.com/\g<pagename>
275 issue_sub_wiki = WIKI-\g<pagename>
285 issue_sub_wiki = WIKI-\g<pagename>
276
286
277 With these settings, wiki pages can be referenced as wiki-some-id, and every
287 With these settings, wiki pages can be referenced as wiki-some-id, and every
278 such reference will be transformed into:
288 such reference will be transformed into:
279
289
280 .. code-block:: html
290 .. code-block:: html
281
291
282 <a href="https://wiki.example.com/some-id">WIKI-some-id</a>
292 <a href="https://wiki.example.com/some-id">WIKI-some-id</a>
283
293
284 Refer to the `Python regular expression documentation`_ for more details about
294 Refer to the `Python regular expression documentation`_ for more details about
285 the supported syntax in ``issue_pat``, ``issue_server_link`` and ``issue_sub``.
295 the supported syntax in ``issue_pat``, ``issue_server_link`` and ``issue_sub``.
286
296
287
297
288 Hook management
298 Hook management
289 ---------------
299 ---------------
290
300
291 Hooks can be managed in similar way to that used in ``.hgrc`` files.
301 Hooks can be managed in similar way to that used in ``.hgrc`` files.
292 To manage hooks, choose *Admin > Settings > Hooks*.
302 To manage hooks, choose *Admin > Settings > Hooks*.
293
303
294 The built-in hooks cannot be modified, though they can be enabled or disabled in the *VCS* section.
304 The built-in hooks cannot be modified, though they can be enabled or disabled in the *VCS* section.
295
305
296 To add another custom hook simply fill in the first textbox with
306 To add another custom hook simply fill in the first textbox with
297 ``<name>.<hook_type>`` and the second with the hook path. Example hooks
307 ``<name>.<hook_type>`` and the second with the hook path. Example hooks
298 can be found in ``kallithea.lib.hooks``.
308 can be found in ``kallithea.lib.hooks``.
299
309
300
310
301 Changing default encoding
311 Changing default encoding
302 -------------------------
312 -------------------------
303
313
304 By default, Kallithea uses UTF-8 encoding.
314 By default, Kallithea uses UTF-8 encoding.
305 This is configurable as ``default_encoding`` in the .ini file.
315 This is configurable as ``default_encoding`` in the .ini file.
306 This affects many parts in Kallithea including user names, filenames, and
316 This affects many parts in Kallithea including user names, filenames, and
307 encoding of commit messages. In addition Kallithea can detect if the ``chardet``
317 encoding of commit messages. In addition Kallithea can detect if the ``chardet``
308 library is installed. If ``chardet`` is detected Kallithea will fallback to it
318 library is installed. If ``chardet`` is detected Kallithea will fallback to it
309 when there are encode/decode errors.
319 when there are encode/decode errors.
310
320
311 The Mercurial encoding is configurable as ``hgencoding``. It is similar to
321 The Mercurial encoding is configurable as ``hgencoding``. It is similar to
312 setting the ``HGENCODING`` environment variable, but will override it.
322 setting the ``HGENCODING`` environment variable, but will override it.
313
323
314
324
315 Celery configuration
325 Celery configuration
316 --------------------
326 --------------------
317
327
318 Kallithea can use the distributed task queue system Celery_ to run tasks like
328 Kallithea can use the distributed task queue system Celery_ to run tasks like
319 cloning repositories or sending emails.
329 cloning repositories or sending emails.
320
330
321 Kallithea will in most setups work perfectly fine out of the box (without
331 Kallithea will in most setups work perfectly fine out of the box (without
322 Celery), executing all tasks in the web server process. Some tasks can however
332 Celery), executing all tasks in the web server process. Some tasks can however
323 take some time to run and it can be better to run such tasks asynchronously in
333 take some time to run and it can be better to run such tasks asynchronously in
324 a separate process so the web server can focus on serving web requests.
334 a separate process so the web server can focus on serving web requests.
325
335
326 For installation and configuration of Celery, see the `Celery documentation`_.
336 For installation and configuration of Celery, see the `Celery documentation`_.
327 Note that Celery requires a message broker service like RabbitMQ_ (recommended)
337 Note that Celery requires a message broker service like RabbitMQ_ (recommended)
328 or Redis_.
338 or Redis_.
329
339
330 The use of Celery is configured in the Kallithea ini configuration file.
340 The use of Celery is configured in the Kallithea ini configuration file.
331 To enable it, simply set::
341 To enable it, simply set::
332
342
333 use_celery = true
343 use_celery = true
334
344
335 and add or change the ``celery.*`` configuration variables.
345 and add or change the ``celery.*`` configuration variables.
336
346
337 Configuration settings are prefixed with 'celery.', so for example setting
347 Configuration settings are prefixed with 'celery.', so for example setting
338 `broker_url` in Celery means setting `celery.broker_url` in the configuration
348 `broker_url` in Celery means setting `celery.broker_url` in the configuration
339 file.
349 file.
340
350
341 To start the Celery process, run::
351 To start the Celery process, run::
342
352
343 kallithea-cli celery-run -c my.ini
353 kallithea-cli celery-run -c my.ini
344
354
345 Extra options to the Celery worker can be passed after ``--`` - see ``-- -h``
355 Extra options to the Celery worker can be passed after ``--`` - see ``-- -h``
346 for more info.
356 for more info.
347
357
348 .. note::
358 .. note::
349 Make sure you run this command from the same virtualenv, and with the same
359 Make sure you run this command from the same virtualenv, and with the same
350 user that Kallithea runs.
360 user that Kallithea runs.
351
361
352
362
353 HTTPS support
363 HTTPS support
354 -------------
364 -------------
355
365
356 Kallithea will by default generate URLs based on the WSGI environment.
366 Kallithea will by default generate URLs based on the WSGI environment.
357
367
358 Alternatively, you can use some special configuration settings to control
368 Alternatively, you can use some special configuration settings to control
359 directly which scheme/protocol Kallithea will use when generating URLs:
369 directly which scheme/protocol Kallithea will use when generating URLs:
360
370
361 - With ``https_fixup = true``, the scheme will be taken from the
371 - With ``https_fixup = true``, the scheme will be taken from the
362 ``X-Url-Scheme``, ``X-Forwarded-Scheme`` or ``X-Forwarded-Proto`` HTTP header
372 ``X-Url-Scheme``, ``X-Forwarded-Scheme`` or ``X-Forwarded-Proto`` HTTP header
363 (default ``http``).
373 (default ``http``).
364 - With ``force_https = true`` the default will be ``https``.
374 - With ``force_https = true`` the default will be ``https``.
365 - With ``use_htsts = true``, Kallithea will set ``Strict-Transport-Security`` when using https.
375 - With ``use_htsts = true``, Kallithea will set ``Strict-Transport-Security`` when using https.
366
376
367 .. _nginx_virtual_host:
377 .. _nginx_virtual_host:
368
378
369
379
370 Nginx virtual host example
380 Nginx virtual host example
371 --------------------------
381 --------------------------
372
382
373 Sample config for Nginx using proxy:
383 Sample config for Nginx using proxy:
374
384
375 .. code-block:: nginx
385 .. code-block:: nginx
376
386
377 upstream kallithea {
387 upstream kallithea {
378 server 127.0.0.1:5000;
388 server 127.0.0.1:5000;
379 # add more instances for load balancing
389 # add more instances for load balancing
380 #server 127.0.0.1:5001;
390 #server 127.0.0.1:5001;
381 #server 127.0.0.1:5002;
391 #server 127.0.0.1:5002;
382 }
392 }
383
393
384 ## gist alias
394 ## gist alias
385 server {
395 server {
386 listen 443;
396 listen 443;
387 server_name gist.example.com;
397 server_name gist.example.com;
388 access_log /var/log/nginx/gist.access.log;
398 access_log /var/log/nginx/gist.access.log;
389 error_log /var/log/nginx/gist.error.log;
399 error_log /var/log/nginx/gist.error.log;
390
400
391 ssl on;
401 ssl on;
392 ssl_certificate gist.your.kallithea.server.crt;
402 ssl_certificate gist.your.kallithea.server.crt;
393 ssl_certificate_key gist.your.kallithea.server.key;
403 ssl_certificate_key gist.your.kallithea.server.key;
394
404
395 ssl_session_timeout 5m;
405 ssl_session_timeout 5m;
396
406
397 ssl_protocols SSLv3 TLSv1;
407 ssl_protocols SSLv3 TLSv1;
398 ssl_ciphers DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:EDH-RSA-DES-CBC3-SHA:AES256-SHA:DES-CBC3-SHA:AES128-SHA:RC4-SHA:RC4-MD5;
408 ssl_ciphers DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:EDH-RSA-DES-CBC3-SHA:AES256-SHA:DES-CBC3-SHA:AES128-SHA:RC4-SHA:RC4-MD5;
399 ssl_prefer_server_ciphers on;
409 ssl_prefer_server_ciphers on;
400
410
401 rewrite ^/(.+)$ https://kallithea.example.com/_admin/gists/$1;
411 rewrite ^/(.+)$ https://kallithea.example.com/_admin/gists/$1;
402 rewrite (.*) https://kallithea.example.com/_admin/gists;
412 rewrite (.*) https://kallithea.example.com/_admin/gists;
403 }
413 }
404
414
405 server {
415 server {
406 listen 443;
416 listen 443;
407 server_name kallithea.example.com
417 server_name kallithea.example.com
408 access_log /var/log/nginx/kallithea.access.log;
418 access_log /var/log/nginx/kallithea.access.log;
409 error_log /var/log/nginx/kallithea.error.log;
419 error_log /var/log/nginx/kallithea.error.log;
410
420
411 ssl on;
421 ssl on;
412 ssl_certificate your.kallithea.server.crt;
422 ssl_certificate your.kallithea.server.crt;
413 ssl_certificate_key your.kallithea.server.key;
423 ssl_certificate_key your.kallithea.server.key;
414
424
415 ssl_session_timeout 5m;
425 ssl_session_timeout 5m;
416
426
417 ssl_protocols SSLv3 TLSv1;
427 ssl_protocols SSLv3 TLSv1;
418 ssl_ciphers DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:EDH-RSA-DES-CBC3-SHA:AES256-SHA:DES-CBC3-SHA:AES128-SHA:RC4-SHA:RC4-MD5;
428 ssl_ciphers DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:EDH-RSA-DES-CBC3-SHA:AES256-SHA:DES-CBC3-SHA:AES128-SHA:RC4-SHA:RC4-MD5;
419 ssl_prefer_server_ciphers on;
429 ssl_prefer_server_ciphers on;
420
430
421 ## uncomment root directive if you want to serve static files by nginx
431 ## uncomment root directive if you want to serve static files by nginx
422 ## requires static_files = false in .ini file
432 ## requires static_files = false in .ini file
423 #root /srv/kallithea/kallithea/kallithea/public;
433 #root /srv/kallithea/kallithea/kallithea/public;
424 include /etc/nginx/proxy.conf;
434 include /etc/nginx/proxy.conf;
425 location / {
435 location / {
426 try_files $uri @kallithea;
436 try_files $uri @kallithea;
427 }
437 }
428
438
429 location @kallithea {
439 location @kallithea {
430 proxy_pass http://127.0.0.1:5000;
440 proxy_pass http://127.0.0.1:5000;
431 }
441 }
432
442
433 }
443 }
434
444
435 Here's the proxy.conf. It's tuned so it will not timeout on long
445 Here's the proxy.conf. It's tuned so it will not timeout on long
436 pushes or large pushes::
446 pushes or large pushes::
437
447
438 proxy_redirect off;
448 proxy_redirect off;
439 proxy_set_header Host $host;
449 proxy_set_header Host $host;
440 ## needed for container auth
450 ## needed for container auth
441 #proxy_set_header REMOTE_USER $remote_user;
451 #proxy_set_header REMOTE_USER $remote_user;
442 #proxy_set_header X-Forwarded-User $remote_user;
452 #proxy_set_header X-Forwarded-User $remote_user;
443 proxy_set_header X-Url-Scheme $scheme;
453 proxy_set_header X-Url-Scheme $scheme;
444 proxy_set_header X-Host $http_host;
454 proxy_set_header X-Host $http_host;
445 proxy_set_header X-Real-IP $remote_addr;
455 proxy_set_header X-Real-IP $remote_addr;
446 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
456 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
447 proxy_set_header Proxy-host $proxy_host;
457 proxy_set_header Proxy-host $proxy_host;
448 proxy_buffering off;
458 proxy_buffering off;
449 proxy_connect_timeout 7200;
459 proxy_connect_timeout 7200;
450 proxy_send_timeout 7200;
460 proxy_send_timeout 7200;
451 proxy_read_timeout 7200;
461 proxy_read_timeout 7200;
452 proxy_buffers 8 32k;
462 proxy_buffers 8 32k;
453 client_max_body_size 1024m;
463 client_max_body_size 1024m;
454 client_body_buffer_size 128k;
464 client_body_buffer_size 128k;
455 large_client_header_buffers 8 64k;
465 large_client_header_buffers 8 64k;
456
466
457 .. _apache_virtual_host_reverse_proxy:
467 .. _apache_virtual_host_reverse_proxy:
458
468
459
469
460 Apache virtual host reverse proxy example
470 Apache virtual host reverse proxy example
461 -----------------------------------------
471 -----------------------------------------
462
472
463 Here is a sample configuration file for Apache using proxy:
473 Here is a sample configuration file for Apache using proxy:
464
474
465 .. code-block:: apache
475 .. code-block:: apache
466
476
467 <VirtualHost *:80>
477 <VirtualHost *:80>
468 ServerName kallithea.example.com
478 ServerName kallithea.example.com
469
479
470 <Proxy *>
480 <Proxy *>
471 # For Apache 2.4 and later:
481 # For Apache 2.4 and later:
472 Require all granted
482 Require all granted
473
483
474 # For Apache 2.2 and earlier, instead use:
484 # For Apache 2.2 and earlier, instead use:
475 # Order allow,deny
485 # Order allow,deny
476 # Allow from all
486 # Allow from all
477 </Proxy>
487 </Proxy>
478
488
479 #important !
489 #important !
480 #Directive to properly generate url (clone url) for Kallithea
490 #Directive to properly generate url (clone url) for Kallithea
481 ProxyPreserveHost On
491 ProxyPreserveHost On
482
492
483 #kallithea instance
493 #kallithea instance
484 ProxyPass / http://127.0.0.1:5000/
494 ProxyPass / http://127.0.0.1:5000/
485 ProxyPassReverse / http://127.0.0.1:5000/
495 ProxyPassReverse / http://127.0.0.1:5000/
486
496
487 #to enable https use line below
497 #to enable https use line below
488 #SetEnvIf X-Url-Scheme https HTTPS=1
498 #SetEnvIf X-Url-Scheme https HTTPS=1
489 </VirtualHost>
499 </VirtualHost>
490
500
491 Additional tutorial
501 Additional tutorial
492 http://pylonsbook.com/en/1.1/deployment.html#using-apache-to-proxy-requests-to-pylons
502 http://pylonsbook.com/en/1.1/deployment.html#using-apache-to-proxy-requests-to-pylons
493
503
494 .. _apache_subdirectory:
504 .. _apache_subdirectory:
495
505
496
506
497 Apache as subdirectory
507 Apache as subdirectory
498 ----------------------
508 ----------------------
499
509
500 Apache subdirectory part:
510 Apache subdirectory part:
501
511
502 .. code-block:: apache
512 .. code-block:: apache
503
513
504 <Location /PREFIX >
514 <Location /PREFIX >
505 ProxyPass http://127.0.0.1:5000/PREFIX
515 ProxyPass http://127.0.0.1:5000/PREFIX
506 ProxyPassReverse http://127.0.0.1:5000/PREFIX
516 ProxyPassReverse http://127.0.0.1:5000/PREFIX
507 SetEnvIf X-Url-Scheme https HTTPS=1
517 SetEnvIf X-Url-Scheme https HTTPS=1
508 </Location>
518 </Location>
509
519
510 Besides the regular apache setup you will need to add the following line
520 Besides the regular apache setup you will need to add the following line
511 into ``[app:main]`` section of your .ini file::
521 into ``[app:main]`` section of your .ini file::
512
522
513 filter-with = proxy-prefix
523 filter-with = proxy-prefix
514
524
515 Add the following at the end of the .ini file::
525 Add the following at the end of the .ini file::
516
526
517 [filter:proxy-prefix]
527 [filter:proxy-prefix]
518 use = egg:PasteDeploy#prefix
528 use = egg:PasteDeploy#prefix
519 prefix = /PREFIX
529 prefix = /PREFIX
520
530
521 then change ``PREFIX`` into your chosen prefix
531 then change ``PREFIX`` into your chosen prefix
522
532
523 .. _apache_mod_wsgi:
533 .. _apache_mod_wsgi:
524
534
525
535
526 Apache with mod_wsgi
536 Apache with mod_wsgi
527 --------------------
537 --------------------
528
538
529 Alternatively, Kallithea can be set up with Apache under mod_wsgi. For
539 Alternatively, Kallithea can be set up with Apache under mod_wsgi. For
530 that, you'll need to:
540 that, you'll need to:
531
541
532 - Install mod_wsgi. If using a Debian-based distro, you can install
542 - Install mod_wsgi. If using a Debian-based distro, you can install
533 the package libapache2-mod-wsgi::
543 the package libapache2-mod-wsgi::
534
544
535 aptitude install libapache2-mod-wsgi
545 aptitude install libapache2-mod-wsgi
536
546
537 - Enable mod_wsgi::
547 - Enable mod_wsgi::
538
548
539 a2enmod wsgi
549 a2enmod wsgi
540
550
541 - Add global Apache configuration to tell mod_wsgi that Python only will be
551 - Add global Apache configuration to tell mod_wsgi that Python only will be
542 used in the WSGI processes and shouldn't be initialized in the Apache
552 used in the WSGI processes and shouldn't be initialized in the Apache
543 processes::
553 processes::
544
554
545 WSGIRestrictEmbedded On
555 WSGIRestrictEmbedded On
546
556
547 - Create a WSGI dispatch script, like the one below. Make sure you
557 - Create a WSGI dispatch script, like the one below. Make sure you
548 check that the paths correctly point to where you installed Kallithea
558 check that the paths correctly point to where you installed Kallithea
549 and its Python Virtual Environment.
559 and its Python Virtual Environment.
550
560
551 .. code-block:: python
561 .. code-block:: python
552
562
553 import os
563 import os
554 os.environ['PYTHON_EGG_CACHE'] = '/srv/kallithea/.egg-cache'
564 os.environ['PYTHON_EGG_CACHE'] = '/srv/kallithea/.egg-cache'
555
565
556 # sometimes it's needed to set the current dir
566 # sometimes it's needed to set the current dir
557 os.chdir('/srv/kallithea/')
567 os.chdir('/srv/kallithea/')
558
568
559 import site
569 import site
560 site.addsitedir("/srv/kallithea/venv/lib/python3.7/site-packages")
570 site.addsitedir("/srv/kallithea/venv/lib/python3.7/site-packages")
561
571
562 ini = '/srv/kallithea/my.ini'
572 ini = '/srv/kallithea/my.ini'
563 from logging.config import fileConfig
573 from logging.config import fileConfig
564 fileConfig(ini, {'__file__': ini, 'here': '/srv/kallithea'})
574 fileConfig(ini, {'__file__': ini, 'here': '/srv/kallithea'})
565 from paste.deploy import loadapp
575 from paste.deploy import loadapp
566 application = loadapp('config:' + ini)
576 application = loadapp('config:' + ini)
567
577
568 Or using proper virtualenv activation:
578 Or using proper virtualenv activation:
569
579
570 .. code-block:: python
580 .. code-block:: python
571
581
572 activate_this = '/srv/kallithea/venv/bin/activate_this.py'
582 activate_this = '/srv/kallithea/venv/bin/activate_this.py'
573 execfile(activate_this, dict(__file__=activate_this))
583 execfile(activate_this, dict(__file__=activate_this))
574
584
575 import os
585 import os
576 os.environ['HOME'] = '/srv/kallithea'
586 os.environ['HOME'] = '/srv/kallithea'
577
587
578 ini = '/srv/kallithea/kallithea.ini'
588 ini = '/srv/kallithea/kallithea.ini'
579 from logging.config import fileConfig
589 from logging.config import fileConfig
580 fileConfig(ini, {'__file__': ini, 'here': '/srv/kallithea'})
590 fileConfig(ini, {'__file__': ini, 'here': '/srv/kallithea'})
581 from paste.deploy import loadapp
591 from paste.deploy import loadapp
582 application = loadapp('config:' + ini)
592 application = loadapp('config:' + ini)
583
593
584 - Add the necessary ``WSGI*`` directives to the Apache Virtual Host configuration
594 - Add the necessary ``WSGI*`` directives to the Apache Virtual Host configuration
585 file, like in the example below. Notice that the WSGI dispatch script created
595 file, like in the example below. Notice that the WSGI dispatch script created
586 above is referred to with the ``WSGIScriptAlias`` directive.
596 above is referred to with the ``WSGIScriptAlias`` directive.
587 The default locale settings Apache provides for web services are often not
597 The default locale settings Apache provides for web services are often not
588 adequate, with `C` as the default language and `ASCII` as the encoding.
598 adequate, with `C` as the default language and `ASCII` as the encoding.
589 Instead, use the ``lang`` parameter of ``WSGIDaemonProcess`` to specify a
599 Instead, use the ``lang`` parameter of ``WSGIDaemonProcess`` to specify a
590 suitable locale. See also the :ref:`overview` section and the
600 suitable locale. See also the :ref:`overview` section and the
591 `WSGIDaemonProcess documentation`_.
601 `WSGIDaemonProcess documentation`_.
592
602
593 Apache will by default run as a special Apache user, on Linux systems
603 Apache will by default run as a special Apache user, on Linux systems
594 usually ``www-data`` or ``apache``. If you need to have the repositories
604 usually ``www-data`` or ``apache``. If you need to have the repositories
595 directory owned by a different user, use the user and group options to
605 directory owned by a different user, use the user and group options to
596 WSGIDaemonProcess to set the name of the user and group.
606 WSGIDaemonProcess to set the name of the user and group.
597
607
598 Once again, check that all paths are correctly specified.
608 Once again, check that all paths are correctly specified.
599
609
600 .. code-block:: apache
610 .. code-block:: apache
601
611
602 WSGIDaemonProcess kallithea processes=5 threads=1 maximum-requests=100 \
612 WSGIDaemonProcess kallithea processes=5 threads=1 maximum-requests=100 \
603 python-home=/srv/kallithea/venv lang=C.UTF-8
613 python-home=/srv/kallithea/venv lang=C.UTF-8
604 WSGIProcessGroup kallithea
614 WSGIProcessGroup kallithea
605 WSGIScriptAlias / /srv/kallithea/dispatch.wsgi
615 WSGIScriptAlias / /srv/kallithea/dispatch.wsgi
606 WSGIPassAuthorization On
616 WSGIPassAuthorization On
607
617
608 Or if using a dispatcher WSGI script with proper virtualenv activation:
618 Or if using a dispatcher WSGI script with proper virtualenv activation:
609
619
610 .. code-block:: apache
620 .. code-block:: apache
611
621
612 WSGIDaemonProcess kallithea processes=5 threads=1 maximum-requests=100 lang=en_US.utf8
622 WSGIDaemonProcess kallithea processes=5 threads=1 maximum-requests=100 lang=en_US.utf8
613 WSGIProcessGroup kallithea
623 WSGIProcessGroup kallithea
614 WSGIScriptAlias / /srv/kallithea/dispatch.wsgi
624 WSGIScriptAlias / /srv/kallithea/dispatch.wsgi
615 WSGIPassAuthorization On
625 WSGIPassAuthorization On
616
626
617
627
618 Other configuration files
628 Other configuration files
619 -------------------------
629 -------------------------
620
630
621 A number of `example init.d scripts`__ can be found in
631 A number of `example init.d scripts`__ can be found in
622 the ``init.d`` directory of the Kallithea source.
632 the ``init.d`` directory of the Kallithea source.
623
633
624 .. __: https://kallithea-scm.org/repos/kallithea/files/tip/init.d/ .
634 .. __: https://kallithea-scm.org/repos/kallithea/files/tip/init.d/ .
625
635
626
636
627 .. _python: http://www.python.org/
637 .. _python: http://www.python.org/
628 .. _Python regular expression documentation: https://docs.python.org/2/library/re.html
638 .. _Python regular expression documentation: https://docs.python.org/2/library/re.html
629 .. _Mercurial: https://www.mercurial-scm.org/
639 .. _Mercurial: https://www.mercurial-scm.org/
630 .. _Celery: http://celeryproject.org/
640 .. _Celery: http://celeryproject.org/
631 .. _Celery documentation: http://docs.celeryproject.org/en/latest/getting-started/index.html
641 .. _Celery documentation: http://docs.celeryproject.org/en/latest/getting-started/index.html
632 .. _RabbitMQ: http://www.rabbitmq.com/
642 .. _RabbitMQ: http://www.rabbitmq.com/
633 .. _Redis: http://redis.io/
643 .. _Redis: http://redis.io/
634 .. _mercurial-server: http://www.lshift.net/mercurial-server.html
644 .. _mercurial-server: http://www.lshift.net/mercurial-server.html
635 .. _PublishingRepositories: https://www.mercurial-scm.org/wiki/PublishingRepositories
645 .. _PublishingRepositories: https://www.mercurial-scm.org/wiki/PublishingRepositories
636 .. _WSGIDaemonProcess documentation: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html
646 .. _WSGIDaemonProcess documentation: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html
General Comments 0
You need to be logged in to leave comments. Login now