/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to doc/http_smart_server.txt

  • Committer: Robert Collins
  • Date: 2007-03-29 06:03:18 UTC
  • mto: (2018.18.6 hpss-faster-copy)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: robertc@robertcollins.net-20070329060318-uqqabpbnzsnaldx7
Make the InterRepository tests less abusive of the API for InterRepository. (Robert Collins, Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Serving Bazaar with Apache
2
 
==========================
 
1
===========================
 
2
Serving Bazaar with FastCGI
 
3
===========================
 
4
 
 
5
**This feature is EXPERIMENTAL and is NOT SECURE.  It will allow access to
 
6
arbitrary files on your server.**
3
7
 
4
8
This document describes one way to set up a Bazaar HTTP smart server,
5
 
using Apache 2.0 and FastCGI or mod_python or mod_wsgi.
6
 
 
7
 
For more information on the smart server, and other ways to configure it
8
 
see the main `smart server documentation`_.
9
 
 
10
 
.. _smart server documentation: #running-a-smart-server
 
9
using Apache 2.0 and FastCGI or mod_python.
11
10
 
12
11
Example
13
 
-------
 
12
=======
14
13
 
15
14
You have a webserver already publishing `/srv/example.com/www/code` as
16
15
`http://example.com/code/...` with plain HTTP.  It contains bzr branches and
30
29
 
31
30
    LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
32
31
    FastCgiIpcDir /var/lib/apache2/fastcgi
33
 
 
 
32
    
34
33
In our example, we're already serving `/srv/example.com/www/code` at
35
34
`http://example.com/code`, so our existing Apache configuration would look
36
35
like::
46
45
 
47
46
    Alias /code /srv/example.com/www/code
48
47
    <Directory /srv/example.com/www/code>
49
 
        Options Indexes FollowSymLinks
 
48
        Options Indexes, FollowSymLinks
50
49
        RewriteEngine On
51
50
        RewriteBase /code
52
51
        RewriteRule ^(.*/|)\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi
53
52
    </Directory>
54
 
 
 
53
    
55
54
    # bzr-smart.fcgi isn't under the DocumentRoot, so Alias it into the URL
56
55
    # namespace so it can be executed.
57
56
    Alias /srv/example.com/scripts/bzr-smart.fcgi /srv/example.com/scripts/bzr-smart.fcgi
61
60
            SetHandler fastcgi-script
62
61
        </Files>
63
62
    </Directory>
64
 
 
 
63
    
65
64
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
66
65
inside `/code` to a Bazaar smart server via FastCGI.
67
66
 
102
101
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
103
102
inside `/code` to a Bazaar smart server via mod_python.
104
103
 
105
 
NOTE: If you don't have bzrlib in your PATH, you will be need to change the
106
 
following line::
107
 
 
108
 
            PythonPath "sys.path+['/srv/example.com/scripts']"
109
 
 
110
 
To::
111
 
 
112
 
            PythonPath "['/path/to/bzr']+sys.path+['/srv/example.com/scripts']"
113
 
 
114
 
 
115
104
Refer to the mod_python_ documentation for further information.
116
105
 
117
106
.. _mod_python: http://www.modpython.org/
118
107
 
119
108
 
120
 
mod_wsgi
121
 
~~~~~~~~
122
 
 
123
 
First, configure mod_wsgi, e.g. enabling the mod with a2enmod wsgi.
124
 
We need to change it to handle all requests for URLs ending in `.bzr/smart`.  It
125
 
will look like::
126
 
 
127
 
    WSGIScriptAliasMatch ^/code/.*/\.bzr/smart$ /srv/example.com/scripts/bzr.wsgi
128
 
 
129
 
    #The three next lines allow regular GETs to work too
130
 
    RewriteEngine On
131
 
    RewriteCond %{REQUEST_URI} !^/code/.*/\.bzr/smart$
132
 
    RewriteRule ^/code/(.*/\.bzr/.*)$ /srv/example.com/www/code/$1 [L]
133
 
 
134
 
    <Directory /srv/example.com/www/code>
135
 
        WSGIApplicationGroup %{GLOBAL}
136
 
    </Directory>
137
 
 
138
 
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
139
 
inside `/code` to a Bazaar smart server via WSGI, and any other URL inside
140
 
`/code` to be served directly by Apache.
141
 
 
142
 
Refer to the mod_wsgi_ documentation for further information.
143
 
 
144
 
.. _mod_wsgi: http://code.google.com/p/modwsgi/
145
 
 
146
109
Configuring Bazaar
147
110
------------------
148
111
 
158
121
    from bzrlib.transport.http import wsgi
159
122
 
160
123
    smart_server_app = wsgi.make_app(
161
 
        root='/srv/example.com/www/code',
 
124
        root='/srv/example.com/code',
162
125
        prefix='/code/',
163
126
        path_var='REQUEST_URI',
164
 
        readonly=True,
165
 
        load_plugins=True,
166
 
        enable_logging=True)
 
127
        readonly=True)
167
128
 
168
129
    fcgi.WSGIServer(smart_server_app).run()
169
 
 
 
130
        
170
131
The `fcgi` module can be found at http://svn.saddi.com/py-lib/trunk/fcgi.py.  It
171
132
is part of flup_.
172
133
 
184
145
    from bzrlib.transport.http import wsgi
185
146
 
186
147
    smart_server_app = wsgi.make_app(
187
 
        root='/srv/example.com/www/code',
 
148
        root='/srv/example.com/code',
188
149
        prefix='/code/',
189
150
        path_var='REQUEST_URI',
190
 
        readonly=True,
191
 
        load_plugins=True,
192
 
        enable_logging=True)
 
151
        readonly=True)
193
152
 
194
153
    def handler(request):
195
154
        """Handle a single request."""
196
155
        wsgi_server = modpywsgi.WSGIServer(smart_server_app)
197
156
        return wsgi_server.run(request)
198
 
 
199
 
The `modpywsgi` module can be found at
200
 
http://ice.usq.edu.au/svn/ice/trunk/apps/ice-server/modpywsgi.py. It was
201
 
part of pocoo_. You sould make sure you place modpywsgi.py in the same
202
 
directory as bzr-smart.py (ie. /srv/example.com/scripts/).
203
 
 
204
 
.. _pocoo: http://dev.pocoo.org/projects/pocoo/
205
 
 
206
 
 
207
 
mod_wsgi
208
 
~~~~~~~~
209
 
 
210
 
We've configured Apache to run the smart server at
211
 
`/srv/example.com/scripts/bzr.wsgi`.  This is just a simple script we need
212
 
to write to configure a smart server, and glue it to the WSGI gateway.
213
 
Here's what it looks like::
214
 
 
215
 
    from bzrlib.transport.http import wsgi
216
 
 
217
 
    def application(environ, start_response):
218
 
        app = wsgi.make_app(
219
 
            root="/srv/example.com/www/code/",
220
 
            prefix="/code",
221
 
            readonly=True,
222
 
            enable_logging=False)
223
 
        return app(environ, start_response)
 
157
        
 
158
The `modpywsgi` module can be found at http://trac.pocoo.org/wiki/ModPyWsgi.  It
 
159
is part of pocoo_.
 
160
 
 
161
.. _pocoo: http://trac.pocoo.org/wiki/
224
162
 
225
163
Clients
226
164
-------
227
165
 
228
 
Now you can use `bzr+http://` URLs or just `http://` URLs, e.g.::
 
166
Now you can use `bzr+http://` URLs, e.g.::
229
167
 
230
168
    bzr log bzr+http://example.com/code/my-branch
231
169
 
233
171
 
234
172
    bzr log http://example.com/code/my-branch
235
173
 
 
174
 
236
175
Advanced configuration
237
 
----------------------
 
176
======================
238
177
 
239
178
Because the Bazaar HTTP smart server is a WSGI application, it can be used with
240
179
any 3rd-party WSGI middleware or server that conforms the WSGI standard.  The
260
199
.. _WSGI standard: http://www.python.org/dev/peps/pep-0333/
261
200
 
262
201
 
263
 
Pushing over the http smart server
264
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
202
Pushing over ``bzr+http://``
 
203
----------------------------
265
204
 
266
205
It is possible to allow pushing data over the http smart server. The
267
206
easiest way to do this, is to just supply ``readonly=False`` to the
268
207
``wsgi.make_app()`` call. But be careful, because the smart protocol does
269
208
not contain any Authentication. So if you enable write support, you will
270
209
want to restrict access to ``.bzr/smart`` URLs to restrict who can
271
 
actually write data on your system, e.g. in apache it looks like::
272
 
 
273
 
    <Location /code>
274
 
        AuthType Basic
275
 
        AuthName "example"
276
 
        AuthUserFile /srv/example.com/conf/auth.passwd
277
 
        <LimitExcept GET>
278
 
            Require valid-user
279
 
        </LimitExcept>
280
 
    </Location>
281
 
 
282
 
At this time, it is not possible to allow some people to have read-only
283
 
access and others to have read-write access to the same urls. Because at
284
 
the HTTP layer (which is doing the Authenticating), everything is just a
285
 
POST request.  However, it would certainly be possible to have HTTPS
286
 
require authentication and use a writable server, and plain HTTP allow
287
 
read-only access.
288
 
 
289
 
If bzr gives an error like this when accessing your HTTPS site::
290
 
 
291
 
  bzr: ERROR: Connection error: curl connection error (server certificate verification failed.
292
 
  CAfile:/etc/ssl/certs/ca-certificates.crt CRLfile: none)
293
 
 
294
 
You can workaround it by using ``https+urllib`` rather than ``http`` in your
295
 
URL, or by uninstalling pycurl.  See `bug 82086`_ for more details.
296
 
 
297
 
.. _bug 82086: https://bugs.launchpad.net/bzr/+bug/82086
298
 
 
299
 
..
 
210
actually write data on your system.  At this time, it is not possible to
 
211
allow some people to have read-only access and others to have read-write
 
212
access to the same urls. Because at the HTTP layer (which is doing the
 
213
Authenticating), everything is just a POST request.  However, it would
 
214
certainly be possible to have HTTPS require authentication and use a
 
215
writable server, and plain HTTP allow read-only access.
 
216
 
 
217
 
 
218
.. 
300
219
   vim: ft=rst tw=74 et