2

I'm new to Git and trying to get an installation of Git, Gitolite, and Gitweb working with LDAP. So far, we have Gitweb working with LDAP. I've reviewed many posts and guides posted around the web, but have not found a solution yet. This is on an Ubuntu 12.04.2 server with Apache 2.2.22. I'm not an expert in any of these technologies, so if I'm missing something obvious please let me know. :)

My site file contains:

<VirtualHost *:80>
    ServerAdmin admin
    ServerName myserver

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    DocumentRoot /home/git/myserver/http/

    <Directory /home/git/myserver/http/>
    </Directory>

   ErrorLog /home/git/myserver/logs/error.log
   CustomLog /home/git/myserver/logs/access.log combined

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug

    AssignUserID git git


</VirtualHost>

<VirtualHost myserver:443>
        ServerAdmin me
    ServerName myserver

    DocumentRoot /usr/share/gitweb/
    <Directory /usr/share/gitweb/>
            AuthBasicProvider ldap
            AuthType Basic
            AuthName "Git Server"
            AuthLDAPURL "ldaps://myldap:636/DC=XX,DC=com?sAMAccountName?sub?(objectClass=user)" NONE
            AuthLDAPBindDN "CN=User,OU=Service Accounts,DC=XX,DC=com"
            AuthLDAPBindPassword "password"
            ### If you need them to be just a member of the domain, use this:
            #require ldap-attribute objectClass=user

            ### Group based authentication. Users should be part of the group exactly, and not nested inside other groups
            require ldap-group CN=XX,OU=Groups,DC=nov,DC=com
            require ldap-group CN=YY,OU=Security Mail Enabled,OU=Groups,DC=XX,DC=com
    </Directory>

   ErrorLog /home/git/myserver/logs/error.log
   CustomLog /home/git/myserver/logs/access.log combined

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug

    AssignUserID git git

    SSLEngine On
    SSLCertificateFile /etc/ssl/apache/myserver.cer
    SSLCertificateKeyFile /etc/ssl/apache/myserver.key


</VirtualHost>

My gitweb.conf file:

# path to git projects (<project>.git)
$projectroot = "/var/lib/gitolite/repositories";

# directory to use for temp files
$git_temp = "/tmp";

$site_name = "Git";

# target of the home link on top of all pages
#$home_link = $my_uri || "/";

# html text to include at home page
#$home_text = "indextext.html";

# file with project list; by default, simply scan the projectroot dir.
$projects_list = "/var/lib/gitolite/projects.list";

@git_base_url_list = qw(ssh://gitolite@myip);

# stylesheet to use
#@stylesheets = ("static/gitweb.css");

# javascript code for gitweb
#$javascript = "static/gitweb.js";

# logo to use
#$logo = "static/git-logo.png";

# the 'favicon'
#$favicon = "static/git-favicon.png";

# git-diff-tree(1) options to use for generated patches
#@diff_opts = ("-M");
@diff_opts = ();

$feature{'highlight'}{'default'} = [1];

And my conf.d/gitweb file:

Alias /gitweb /usr/share/gitweb

<Directory /usr/share/gitweb>
  Options FollowSymLinks +ExecCGI
  AddHandler cgi-script .cgi
</Directory>

Any thoughts or suggestions are much appreciated.

Thanks!

user1167926
  • 21
  • 1
  • 3

2 Answers2

4

Git with LDAP (git itself, not gitweb) is precisely what I do in my project:
See my httpd.conf

I define first a couple of LDAP aliases (you can authenticate against several LDAP if you want):

<AuthnProviderAlias ldap myldap>
  AuthLDAPBindDN cn=Manager,dc=example,dc=com
  AuthLDAPBindPassword secret
  AuthLDAPURL ldap://localhost:@PORT_LDAP_TEST@/dc=example,dc=com?uid?sub?(objectClass=*)
</AuthnProviderAlias>

# LDAP_START
<AuthnProviderAlias ldap companyldap>
  AuthLDAPBindDN "@LDAP_BINDDN@"
  AuthLDAPBindPassword @LDAP_PASSWORD@
  AuthLDAPURL @LDAP_URL@
</AuthnProviderAlias>
# LDAP_END

(All the @xxx@ you see are template placeholders that I replace with actual values later)

Then I define my VirtualHost (on a different port than the one used for gitweb):

(extract):

# GitHttp on @PORT_HTTP_HGIT@
Listen @PORT_HTTP_HGIT@
<VirtualHost @FQN@:@PORT_HTTP_HGIT@>
    ServerName @FQN@
    ServerAlias @HOSTNAME@

    SSLCertificateFile "@H@/apache/crt"
    SSLCertificateKeyFile "@H@/apache/key"
    SSLEngine on

    SetEnv GIT_PROJECT_ROOT @H@/repositories
    SetEnv GIT_HTTP_EXPORT_ALL
    SetEnv GITOLITE_HTTP_HOME @H@
    ScriptAlias /hgit/ @H@/sbin/gitolite-shell/
    SetEnv GIT_HTTP_BACKEND "@H@/usr/local/apps/git/libexec/git-core/git-http-backend"
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
      SSLOptions +StdEnvVars
    </FilesMatch>
    <Location /hgit>
        SSLOptions +StdEnvVars
        Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
        #AllowOverride All
        order allow,deny
        Allow from all
        AuthName "LDAP authentication for Smart HTTP Git repositories"
        AuthType Basic
        AuthBasicProvider myldap companyldap
        AuthzLDAPAuthoritative Off
        Require valid-user
        AddHandler cgi-script cgi
    </Location>

</VirtualHost>

Here this is calling gitolite, but if you call directly git-http-backend (which is a script from git itself, nothing to do with gitolite), you would give unrestricted access to your git repo, through http(s) with LDAP authentication

ScriptAlias /hgit/ @H@/usr/local/apps/git/libexec/git-core/git-http-backend
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks VonC, I am still having trouble with my setup. I don't have gitolite-shell. Am I missing something from my installation? I don't know if that is the root of my issues, but it seems like a good place to start. – user1167926 Aug 02 '13 at 20:25
  • @user1167926 strange, I had someone else having the [exact same problem](http://stackoverflow.com/questions/17990402/gitolite-with-ldap-not-working/17991421#comment26348186_17991421). Yet, when I [install gitolite like so](https://github.com/VonC/compileEverything/blob/master/gitolite/install_or_update_gitolite.sh#L27-L53), meaning `"${github}/install" -to "${gtl}/bin" ; GITOLITE_HTTP_HOME= gitolite setup -pk "${H}/.ssh/gitoliteadm.pub"` to install gitolite in `${gtl}/bin` (which is in my `$PATH`), I do get `gitolite-shell`. – VonC Aug 02 '13 at 21:38
  • It turns out that apt-get installs gitolite 2.2, thus no gitolite-shell. So I've installed it from source and now have /home/gitolite/gitolite-shell. Although I'm still having issues, and after reading the post that you linked I'm considering dropping gitolite altogether. – user1167926 Aug 06 '13 at 19:55
  • @user1167926 gitolite 3.5+ works really well, but I find it particularely true when only one account launches apache httpd and manages gitolite repos: no permission issue then. – VonC Aug 06 '13 at 20:22
  • Is there configuration anywhere else that I need to be doing? My virtual host is http://pastebin.com/2VVWqKQf. I've seen mention of editing the git.conf file, but I can't find one. – user1167926 Aug 07 '13 at 16:05
  • @user1167926 for a gitweb to call gitolite, you need to declare in your [`gitweb/gitweb_config.perl`](https://github.com/VonC/compileEverything/blob/master/gitweb/gitweb_config.perl) a file like [`gitweb.conf.pl`](https://github.com/VonC/compileEverything/blob/master/gitweb/gitweb.conf.pl.tpl), which will call gitolite. – VonC Aug 08 '13 at 16:56
0

Hope you got your problem fixed. I have been messing around a few days with Git / Gitweb / gitolite myself before I gave up and just installed GitLab using a Bitnami installer

Worked like a charm (some minor hickups but it was a real eye-opener for me: don't try to configure everything yourself if you can find a good "out-of-the-box" solution.

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • Hi. Your answer intrigued me. Since I'm trying to setup a similar infrastructure. My git server is hosted on Centos(6.5); and LDAP is on windows. Till now we have been using SSH for access to repos; but we want to migrate to authentication on git server via LDAP. Do you think GitLab can help me setup the same. (Although I;m trying the same on my own) – vintrojan Nov 17 '16 at 10:06
  • yes I managed to do that; but way back in the past. It is possible :) – Chris Maes Nov 17 '16 at 13:42
  • Thanks for the response :). M working on it. Got the server up and running; but struggling with LDAP. I'll work on it. – vintrojan Nov 18 '16 at 06:20