AuthenticatingHg » History » Version 15

Chris Cannam, 2010-08-11 05:49 PM

1 2 Chris Cannam
h2. Authentication for Mercurial activity
2 2 Chris Cannam
3 2 Chris Cannam
h3. Requirements
4 2 Chris Cannam
5 2 Chris Cannam
# *Clone/pull from repo for public project*: Any user, no authentication required
6 4 Chris Cannam
# *Clone/pull from repo for private project*: Permitted users only
7 4 Chris Cannam
# *Push to repo for public project*: Permitted users only
8 4 Chris Cannam
# *Push to repo for private project*: Permitted users only
9 11 Chris Cannam
# *Create repo for public project*: User with manager role on project
10 12 Chris Cannam
# *Delete repo or carry out command-line admin tasks*: System admin only
11 1 Chris Cannam
12 10 Chris Cannam
What constitutes a permitted user for limited push or pull activity?
13 4 Chris Cannam
14 4 Chris Cannam
* A user who is a member of the project?
15 4 Chris Cannam
* A user who is identified in the [web] section of the repository?
16 4 Chris Cannam
* A user who is both a member and identified in the [web] section?
17 4 Chris Cannam
* A user who is either a member or identified in the [web] section?
18 4 Chris Cannam
* A user who is identified in the [web] section, if any, or is a member if there is no such section?
19 5 Chris Cannam
20 5 Chris Cannam
h3. Techniques
21 1 Chris Cannam
22 10 Chris Cannam
* Hg repository creation using "reposman.rb":http://temporary.lividcity.com/projects/soundsoftware-site/repository/entry/extra/svn/reposman.rb
23 5 Chris Cannam
* Apache authentication against Redmine user database using mod_auth_mysql (no support for LDAP-authenticated users?)
24 13 Chris Cannam
* Apache authentication against Redmine users using "the mod_perl module Redmine.pm":http://redmine.rubyforge.org/svn/trunk/extra/svn/Redmine.pm ("local copy":http://temporary.lividcity.com/projects/soundsoftware-site/repository/entry/extra/svn/Redmine.pm) or a variant thereof.  Redmine.pm was designed for SVN access via WebDAV, but the code itself handles access and authentication only?
25 8 Chris Cannam
* Hg repository [web]-section authorisation using "hgwebdir.cgi":http://mercurial.selenic.com/wiki/PublishingRepositories#Setting_up_the_hgweb.cgi_script
26 7 Chris Cannam
27 7 Chris Cannam
Other links on this subject:
28 7 Chris Cannam
29 8 Chris Cannam
* "Separation between authentication and authorisation activities":http://markmail.org/message/xmav6qg3is3xptve#query:+page:1+mid:xmav6qg3is3xptve+state:results
30 8 Chris Cannam
* "hgrc [web] section":http://www.selenic.com/mercurial/hgrc.5.html#web
31 8 Chris Cannam
* "Using mod_auth_mysql to authenticate against the Redmine database directly":http://maff.ailoo.net/2009/03/authenticate-apache-against-redmine-with-authmysql/
32 14 Chris Cannam
* "Apache2 logging from mod_perl code":http://perl.apache.org/docs/2.0/api/Apache2/Log.html (for use in debugging Redmine.pm)
33 15 Chris Cannam
34 15 Chris Cannam
h3. Plan
35 15 Chris Cannam
36 15 Chris Cannam
We are currently using proxypass from a front-end server to the actual code server, so this complicates matters somewhat.
37 15 Chris Cannam
38 15 Chris Cannam
It seems reasonable-ish to assume that all hg traffic will use SSL.  Apart from anything else, pushes and any other authenticated traffic really must be over SSL, so this avoids irritations when someone pulls from an http URL and then gets kicked out when attempting to push to the default target.
39 15 Chris Cannam
40 15 Chris Cannam
Therefore,
41 15 Chris Cannam
42 15 Chris Cannam
* Front-end server needs to have the relevant certificates
43 15 Chris Cannam
* Front-end server is currently running too old a version of Apache 2 to support SNI, so it can only support one https domain (question: does Mercurial's own Python client support SNI?) -- fortunately for us it is not currently running any other, but this suggests we really need to replace the front-end arch
44 15 Chris Cannam
* Front-end server redirects all http traffic on the hg domain to https and then proxypasses to the back-end server via http (connection is presumed trusted?)
45 15 Chris Cannam
46 15 Chris Cannam
At the back-end server,
47 15 Chris Cannam
48 15 Chris Cannam
* We will use hgwebdir.cgi instead of serving the hg directories directly as static HTTP
49 15 Chris Cannam
* The server's document root will be just a placeholder
50 15 Chris Cannam
* ScriptAlias is used to point all traffic to hgwebdir.cgi
51 15 Chris Cannam
* We will use something based on Redmine.pm to manage access
52 15 Chris Cannam
* We probably want to prevent people reading the list of repositories (so that per-project authentication is always in force)
53 15 Chris Cannam
54 15 Chris Cannam
The net result is that we should have hg over https with basic authentication based on the Redmine database and LDAP as appropriate, with access controls that we can define based on the project rules set out above.
55 15 Chris Cannam
56 15 Chris Cannam
Apache config snippet:
57 15 Chris Cannam
<pre>
58 15 Chris Cannam
PerlLoadModule Apache::Authn::Redmine
59 15 Chris Cannam
60 15 Chris Cannam
<VirtualHost *:80>
61 15 Chris Cannam
        ServerName hg.soundsoftware.ac.uk
62 15 Chris Cannam
        ServerAlias temphg.lividcity.com
63 15 Chris Cannam
        ServerAdmin chris.cannam@eecs.qmul.ac.uk
64 15 Chris Cannam
        DocumentRoot /var/www/hg
65 15 Chris Cannam
66 15 Chris Cannam
        <DirectoryMatch "^/.*/\.svn/">
67 15 Chris Cannam
                Order allow,deny
68 15 Chris Cannam
                Deny from all
69 15 Chris Cannam
                Satisfy All
70 15 Chris Cannam
        </DirectoryMatch>
71 15 Chris Cannam
72 15 Chris Cannam
        ScriptAlias / "/var/hg/index.cgi/"
73 15 Chris Cannam
74 15 Chris Cannam
        <Location />
75 15 Chris Cannam
                AuthName "Mercurial"
76 15 Chris Cannam
                AuthType Basic
77 15 Chris Cannam
                Require valid-user
78 15 Chris Cannam
                PerlAccessHandler Apache::Authn::Redmine::access_handler
79 15 Chris Cannam
                PerlAuthenHandler Apache::Authn::Redmine::authen_handler
80 15 Chris Cannam
                RedmineDSN "DBI:mysql:database=<database>;host=localhost"
81 15 Chris Cannam
                RedmineDbUser "<user>"
82 15 Chris Cannam
                RedmineDbPass "<password>"
83 15 Chris Cannam
                Options +ExecCGI
84 15 Chris Cannam
                AddHandler cgi-script .cgi
85 15 Chris Cannam
        </Location>
86 15 Chris Cannam
87 15 Chris Cannam
        ErrorLog /var/log/apache2/error.log
88 15 Chris Cannam
89 15 Chris Cannam
        # Possible values include: debug, info, notice, warn, error, crit,
90 15 Chris Cannam
        # alert, emerg.
91 15 Chris Cannam
        LogLevel warn
92 15 Chris Cannam
93 15 Chris Cannam
        ServerSignature Off
94 15 Chris Cannam
</VirtualHost>
95 15 Chris Cannam
96 15 Chris Cannam
</pre>