Bazaar

Bazaar

 




Wiki Tools

  • Find Page
  • Recent Changes
  • Page History
  • Attachments

Bazaar Smart Server and Apache on Windows

Why?

One of the requirements in our department for revision control tools is to ensure that it is secure. One of those requirements determines that it integrates with Active Directory. Now I've been using Bazaar for some time now and I can see Bazaar having massive benefits for our team that is split into 3 different locations. Not to mention licensing costs or our current antiquated commercial revision control tool.

Status

Currently (11 June 2010) smart server does not support active directory integration. Perusing various documentation on bazaar has led me to believe the best approach is to integrate bazaar smart server with an apache instance.

Being a novice on the Apache web server I found myself at a bit of a loss when it came to running Bazaar under apache. Documentation seems to be out of date talking about pocoo and various other bits which seem to have moved on.

Steps

  • Download and unzip Apache httpd server 2.2.15, note this will also require Visual C++ 2008 redistributable package.
  • I like to test Apache runs at this stage. c:>apache-http-2.2.15/bin> httpd.exe (Browser: http://localhost)

  • Download and install Python 2.6.5 from http://www.python.org/download.

  • Download and install Bazaar using Python Bazaar installer. The reason for this is that the standalone installer does not have the required python transport modules. I downloaded version 2.1.1 for Python 2.6.
  • Download python wsgi module, I used mod_wsgi-win32-ap22py26-3.0.so, from http://code.google.com/p/modwsgi/downloads/list and place it in the modules folder under apache.

  • Download Mod Auth SSPI, I used mod_auth_sspi-1.0.4-2.2.2.zip, from http://sourceforge.net/projects/mod-auth-sspi/files/mod-auth-sspi/mod_auth_sspi%201.0.4/mod_auth_sspi-1.0.4-2.2.2.zip/download and extract the mod_auth_sspi.so and place it in the modules folder under apache.

  • Configure apache to load the modules. Edit conf/httpd.conf (under apache).
    • Uncomment LoadModule rewrite_module modules/mod_rewrite.so line, to enable mod rewrite.

    • Uncomment Include conf/extra/httpd-vhosts.conf

    • Uncomment LoadModule proxy_module modules/mod_proxy.so

    • Uncomment LoadModule proxy_http_module modules/mod_proxy_http.so

    • Add LoadModule wsgi_module modules/mod_wsgi-win32-ap22py26-3.0.so

    • Add LoadModule sspi_auth_module modules/mod_auth_sspi.so

  • Now add the "virtual host" section for bazaar. Edit conf/extra/httpd-vhosts.conf (under apache).
    • Add the following ...

<VirtualHost blah:80>
  ServerAdmin <email address hidden>
  DocumentRoot "C:/apps/apache-http-2.2.15/htdocs"

  ServerName blah.com
  ServerAlias blah.com blah

  ErrorLog logs/bzr-error.log
  CustomLog logs/bzr-access.log common

  WSGIScriptAlias /myapp C:/bzr-sandbox/sh-repo/scripts/myapp.wsgi

  WSGIScriptAliasMatch ^/bzr/.*/\.bzr/smart$ C:/bzr-sandbox/sh-repo/scripts/smartserver.wsgi
  #WSGIScriptAliasMatch ^/bzr/.*/\.bzr/smart$ C:/bzr-sandbox/sh-repo/scripts/myapp.wsgi
  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/bzr/.*/\.bzr/smart$
  RewriteRule ^/bzr/(.*/\.bzr/.*)$ C:/bzr-sandbox/sh-repo/$1 [L]
  RewriteLog logs/bzr-rewrite.log
  RewriteLogLevel 3

  <Directory C:/bzr-sandbox/sh-repo>
      AuthName "Bzr Development"
      AuthType SSPI
      SSPIAuth On
      # module is the final authority
      SSPIAuthoritative On
      # only authenticate against DEVDomain no others
      SSPIDomain DEVDOMAIN
      # keep domain name in userid string
      SSPIOmitDomain Off
      # let non-IE clients authenticate
      SSPIOfferBasic On
      # first we try NTLM authentication and then basic authentication
      SSPIBasicPreferred Off
      # need to be in dev Group to be able to access bzr
      Require group "DEVDOMAIN\DEV-Grp"

      Order allow,deny
      Allow from all
      WSGIApplicationGroup %{GLOBAL}
      SetEnv bzr_wsgi.root C:/bzr-sandbox/sh-repo
      SetEnv bzr_wsgi.prefix /bzr

  </Directory>

</VirtualHost>
  • Create folder, c:/bzr-sandbox/sh-repo/scripts and place the following contents into a file called "myapp.wsgi" inside new folder.

def application(environ, start_response):
    status = '200 OK' 
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]
  • Test the myapp, http://blah/myapp. This should bring up a page with "Hello World!".

  • If this works, congratulations you have WSGI working.
  • In folder, c:/bzr-sandbox/sh-repo/scripts, place the following contents into a file called "smartserver.wsgi".

from bzrlib.transport.http import wsgi

def application(environ, start_response):
    return wsgi.make_app(
        root=environ["bzr_wsgi.root"],
        prefix=environ["bzr_wsgi.prefix"],
        readonly=False,
        enable_logging=True
    )(environ, start_response)
  • Create a bazaar branch or repository under c:/bzr-sandbox/sh-repo (eg called myproject, "bzr init myproject").
  • Start the apache http server.
  • Try and create a branch from the repository.
    • c:> cd %TEMP%

    • bzr branch bzr+http://blah/bzr/myproject myproject. This should create the myproject directory and contents.

Problem Solving

  • For my virtual host setup I wanted to do it on my local PC and not the real server which I've called blah on this page. The way I did this was to edit a file called c:\windows\system32\drivers\etc\hosts. I added an entry such as 127.0.0.1    blah. This way when my browser or bazaar looked up blah it got my local machine. The browser or Bazaar would pass the name of blah into apache which would then match the virtual host section. Remember to remove this entry when done otherwise you will have some strange problems when trying to access the real repository.

  • You probably want to set the environment variable NO_PROXY to be the name of your server e.g. set NO_PROXY=blah for some reason which I could not get to the bottom of bazaar kept wanting to send requests through our proxy which promptly denied any requests. This particular problem caused a lot of wasted time for me which is why I'm mentioning it here.

  • How I found out about bazaar sending these requests was to run wireshark. Once installed I started it and started the capture. I then found the http request that was sent through. The IP addresses were incorrect at this stage. I right clicked on it and clicked on follow stream. This showed the request and response and the response revealed a squid server was responding and not my apache instance.
  • If in the browser you try to access http://blah/myapp and it does not work then something has gone wrong with the wsgi installation. Check that you put the myapp.wsgi file in the scripts folder as above. Check in the apache/logs/error.log file. If it starts correctly you should see something like [Wed Jun 09 13:55:57 2010] [notice] Apache/2.2.15 (Win32) mod_wsgi/3.0 Python/2.6.5 configured -- resuming normal operations

  • If your wsgi module is working and you can see the hello world! page. The next thing to check is that the sspi module is working correctly. Again in the error.log you should see something like [Thu Jun 10 12:26:06 2010] [notice] Apache/2.2.15 (Win32) mod_wsgi/3.0 Python/2.6.5 mod_auth_sspi/1.0.4 configured -- resuming normal operations 

  • If you try and access something through your browser under /bzr e.g. http://blah/bzr/somefile.txt you should check to see that it is appearing in your logs/bzr-access.log file (or whatever you called it in the virtual host section).

  • At some stage I had an error in my smartserver.wsgi script. I found this out by uncommenting the line WSGIScriptAliasMatch ^/bzr/.*/\.bzr/smart$ C:/bzr-sandbox/sh-repo/scripts/myapp.wsgi and commenting out the previous WSGIScriptAliasMatch entry and then accessing a url such as http://blah/bzr/.bzr/smart/whatever. This displayed the test page, at this stage I realised that I had the incorrect path to my shared repository.

Finishing Touches

  • Remove the commented out entries.
  • Set the RewriteLogLevel to 1

  • If you played with your c:\Windows\system32\drivers\etc\hosts file then revert it.

Something to Ponder

I've created a shared repository at the top level in the bazaar folder but you probably want to create a shared repository for each project.

Please feel free to correct this page if you see something incorrect with it. I have provided this so that others can learn from it and not have to go through the hassle I went through. I am by no means an apache, python or bazaar expert. I have put this page together by scouring documentation and the web and my original problem is documented at: https://answers.launchpad.net/bzr/+question/113185