nemunai.re/content/en/post/use-gitolite-access-control-in-gitweb.md
Pierre-Olivier Mercier 9862b5aa22
All checks were successful
continuous-integration/drone/push Build is passing
Multilingual blog
2023-05-14 12:38:56 +02:00

1.3 KiB

title date update tags
Use Gitolite Access Control In Gitweb 2015-09-24 00:00:00 2019-04-09 12:45:00
git

Are you using gitolite and gitweb? Two nice and lightweight projects, but perhaps you are tired to manage access control in gitweb?

Here is some simple tricks to use gitolite access list directly into gitweb, automatically.

As you may know, the configuration file /etc/gitweb.conf is in fact no less than a perl script fragment. As it is simply imported by gitweb, it is possible to include some code.

Gitolite is also a piece of software writen in Perl. So it is pretty easy to make gitweb relying on gitolite permissions. Here is what I append to my /etc/gitweb.conf:

# Most of the code comes from https://gitolite.com/gitolite/gitweb.conf.html
# where comments live.

BEGIN {
    $ENV{HOME} = "/var/lib/gitolite";  # Home of the gitolite user in gentoo
    $ENV{GL_BINDIR} = "/usr/libexec/gitolite";
}

use Gitolite::Easy;

$ENV{GL_USER} = $cgi->remote_user || "gitweb";

$export_auth_hook = sub {
    my $repo = shift;

    return unless $repo =~ s/^\Q$projectroot\E\/?(.+)\.git$/$1/;

    return Gitolite::Easy::can_read($repo);
};