Setup bazaar over HTTP server

From Notes_Wiki
Revision as of 12:13, 30 November 2012 by Saurabh (talk | contribs)

Setup bazaar over HTTP server

To setup bazaar over HTTP server use following steps:

  1. Install mod_python package using 'yum -y install mod_python'. (Requires epel repository)
  2. Create folder /var/www/scripts and download file 'modpywsgi.py' in it from here.
  3. Rename file using 'mv Modpywsgi.py.txt modpywsgi.py'
  4. Assuming bazaar repository is configured in '/var/www/bzr' and branch named 'repo1' is configured using:
    cd /var/www
    bzr init-repo bzr
    cd bzr
    bzr init repo1
    cd /var/www
    chown -R apache:apache .
  5. Configure basic download access using
    Alias /bzr /var/www/bzr
    <Directory /var/www/bzr>
    Options All
    AllowOverride all
    Order allow,deny
    Allow from all
    </Directory>
  6. Use 'service httpd restart'
  7. Try to access log using 'bzr log http://<server_ip_or_name>/bzr/repo1'
  8. Configure smart access using:
    Alias /bzr /var/www/bzr
    <Directory /var/www/bzr>
    Options All
    AllowOverride all
    Order allow,deny
    Allow from all
    RewriteEngine On
    RewriteBase /bzr
    RewriteRule ^(.*/)?\.bzr/smart$ /scripts/bzr-smart.py
    </Directory>
    Alias /scripts/bzr-smart.py /var/www/scripts/bzr-smart.py
    <Directory /var/www/scripts>
    Options All
    AllowOverride all
    Order allow,deny
    Allow from all
    <Files bzr-smart.py>
    PythonPath "['/usr/lib64/python2.6/site-packages/bzrlib']+sys.path+['/srv/example.com/scripts']"
    AddHandler python-program .py
    PythonHandler bzr-smart::handler
    </Files>
    </Directory>
    Replace /bzr with repository name and /var/www/bzr with repository base folder appropriately at various places.
  9. Create file named '/var/www/scripts/bzr-smart.py' with contents similar to:
    import modpywsgi
    from bzrlib.transport.http import wsgi
    smart_server_app = wsgi.make_app(
    root='/var/www/bzr',
    prefix='/bzr/',
    path_var='REQUEST_URI',
    readonly=False,
    load_plugins=True,
    enable_logging=True)
    def handler(request):
    """Handle a single request."""
    wsgi_server = modpywsgi.WSGIServer(smart_server_app)
    return wsgi_server.run(request)
    Replace /bzr with repository name and /var/www/bzr with repository base folder appropriately at various places.
  10. Again use 'service httpd restart'
  11. Do 'chown -R apache:apache /var/www/scripts'
  12. Try to checkout repository using:
    bzr co bzr+http://<server_ip_or_name>/bzr/repo1
  13. Or try to branch repository for decentralized usage using:
    bzr branch bzr+http://<server_ip_or_name>/bzr/repo1
  14. Make changes to repository and try to commit.


Note that above setup of repository should be secured. It can be done by restricting access to web server through firewall or by enablng LDAP authentication as explained at Configuring LDAP based authentication for apache


Configuring LDAP based authentication for bazaar repository

Note that during authentication configuration, authentication needs to be enabled only for repository folder such as /bzr and not for scripts folder. Also line 'Allow from all' should be removed for authentication to take place.. For example, in above case part of configuration with authentication would look like:

    Alias /bzr /var/www/bzr
    <Directory /var/www/bzr>
        Options All
        AllowOverride all
        Order allow,deny

        RewriteEngine On
        RewriteBase /bzr
        RewriteRule ^(.*/)?\.bzr/smart$ /scripts/bzr-smart.py

        AuthType Basic
        AuthName "bzr bazaar repository"
        AuthBasicProvider ldap
        AuthzLDAPAuthoritative on
        AuthLDAPURL ldap://ldap.virtual-labs.ac.in:389/ou=people,dc=virtual-labs,dc=ac,dc=in?uid
        AuthLDAPGroupAttribute memberUid
        AuthLDAPGroupAttributeIsDN off
        Require ldap-group cn=admin,ou=groups,dc=virtual-labs,dc=ac,dc=in
        Require ldap-attribute gidNumber=501
        Satisfy any
    </Directory>

This information is just provided here for fast access. For detailed information related to ldap authentication with apache use article Configuring LDAP based authentication for apache


Example configuration

If all repositories are under /var/www/bazaar and same set of users should be allowed access to all repositories then 'httpd.conf' configuration can be like:

    Alias /bazaar /var/www/bazaar
    <Directory /var/www/bazaar>
        Options All
        AllowOverride all
        Order allow,deny
    Allow from all
    AuthType Basic
    AuthName "Authentication for bazaar repositories"
    AuthUserFile /var/www/auth/passwd
    Require valid-user       
        RewriteEngine On
        RewriteBase /bazaar
        RewriteRule ^(.*/)?\.bzr/smart$ /scripts/bzr-smart.py
    </Directory>

    Alias /scripts/bzr-smart.py /var/www/scripts/bzr-smart.py
    <Directory /var/www/scripts> 
        Options All 
        AllowOverride all 
        Order allow,deny 
        Allow from all 
        <Files bzr-smart.py> 
            PythonPath "['/usr/lib64/python2.6/site-packages/bzrlib']+sys.path+['/srv/example.com/scripts']"
            AddHandler python-program .py 
            PythonHandler bzr-smart::handler
        </Files> 
    </Directory>


The corresponding 'bzr-smart.py' file would contain:

import modpywsgi 
from bzrlib.transport.http import wsgi 

smart_server_app = wsgi.make_app(
    root='/var/www/bazaar', 
    prefix='/bazaar/', 
    path_var='REQUEST_URI', 
    readonly=False, 
    load_plugins=True, 
    enable_logging=True)
 
def handler(request): 
    """Handle a single request.""" 
    wsgi_server = modpywsgi.WSGIServer(smart_server_app) 
    return wsgi_server.run(request)