Git over Http(s) and per user/group rights

lockdoc

Well-Known Member
Hier wollte ich mal meine Erfahrungen berichten, wie man git repos simple mit Apache verwaltet ohne auf tools wie gitolite oder aehnliche zurueckgreifen zu muessen.

Die User Verwaltung erfolgt ueber Apache AuthType Basic, kann dann auch spaeter recht simpel ins LDAP uebernommen werden (sofern Apache dagegen kompiliert worden ist), was die Verwaltung der user noch um einiges erleichtert.
Das geht mit gitolite AFAIK nicht.


Vorraussetzungen
* Apache ist installiert
* Git ist installiert
* Gti Repo Location: /var/git


Apache Konfigurieren

Code:
Hier ist die Grundkonfiguration des vHosts (noch ohne Repo Access)

# Git over HTTP: http://git.repo.yourdomain.tld/git/<project>.git
<VirtualHost *:80>
        ServerName      git.repo.yourdomain.tld
        ServerAlias     git.repo.yourdomain.tld
        ServerAdmin     user@git.repo.yourdomain.tld

        ErrorLog        /var/log/apache/git.repo.yourdomain.tld-error_log
        CustomLog       /var/log/apache/git.repo.yourdomain.tld-access_log combined

        # ------------- Git Clone Environment Variables
        SetEnv GIT_PROJECT_ROOT /var/git/base
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

        ScriptAlias /git/ /usr/local/libexec/git-core/git-http-backend/
</VirtualHost>

Remote Repo erstellen

Dieser Vorgang ist fuer jedes Repo gleich.
Das Beispiel Repo heisst test.git
Code:
 root> mkdir /var/git/base/test.git
 root> chown root:www /var/git/base/test.git
 root> cd /var/git/base/test.git
 root> git init --bare --shared


Apache vHost erweitern

Jetzt wird das repo in den vHost eingebunden

Code:
Hier ist die Grundkonfiguration des vHosts (noch ohne Repo Access)

# Git over HTTP: http://git.repo.yourdomain.tld/git/<project>.git
<VirtualHost *:80>
        ServerName      git.repo.yourdomain.tld
        ServerAlias     git.repo.yourdomain.tld
        ServerAdmin     user@git.repo.yourdomain.tld

        ErrorLog        /var/log/apache/git.repo.yourdomain.tld-error_log
        CustomLog       /var/log/apache/git.repo.yourdomain.tld-access_log combined

        # ------------- Git Clone Environment Variables
        SetEnv GIT_PROJECT_ROOT /var/git/base
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

        ScriptAlias /git/ /usr/local/libexec/git-core/git-http-backend/

        ########## Git Repository Access Definitions ##########

[B]        ### Project: test.git
        <Location "/git/test.git">
                Order allow,deny
                Allow from All
                AuthType Basic
                AuthName "Repo: test.git"
                AuthUserFile    /usr/local/etc/apache22/auth/auth-users
                AuthGroupFile   /usr/local/etc/apache22/auth/auth-groups
                Require group test
        </Location>
[/B]
</VirtualHost>

auth-users
Jetzt muessen noch die Dateien "auth-users" und "auth-groups" angelegt werden.
Beim erstmaligen anlegen der auth-users muss die -c Option (fuer create) angegeben werden:
Code:
 root> htpasswd -c /usr/local/etc/apache22/auth/auth-users lockdoc
Beim hinzufuegen von weiteren usern kann der -c Schalter weggelassen werden
Code:
 root> htpasswd  /usr/local/etc/apache22/auth/auth-users lockdoc2

Also einfach alle User anlegen, die jemahls irgendwie git Zugriff brauchen.

auth-groups
Danach werden die user den Projekten zugeordnet. In unserem Fall hatte ich in der vHost angegeben:
Code:
                Require group test

Das heisst, alle user in der Gruppe "test" koennen auf das Repo zugreifen.
Hierzu wird die auth-groups wie folgt angelegt
Code:
test: lockdoc lockdoc2
test2: lockdoc

Jetzt koennen lockdoc und lockdoc2 auf das test.git repo zugreifen.
test2 ist nur da, um zu zeien, wie eine weitere Gruppe angelegt wird.

Repository auschecken
Jetzt kann ich einfach von der shell aus (egal welcher System User ich bin) das test.git repo auschecken
Code:
user> git clone -v http://git.repo.yourdomain.tld/git/test.git
  Cloning into 'test'...
  Username for 'http://git.repo.yourdomain.tld':
  Password for 'http://lockdoc@git.repo.yourdomain.tld':
  POST git-upload-pack (192 bytes)
  remote: Counting objects: 3, done.
  remote: Total 3 (delta 0), reused 0 (delta 0)
  Unpacking objects: 100% (3/3), done.


Das ganze sollte natuerlich auf einem https laufen, aber der einfachheit halber, habe ich das mal weggelassen.
 
So hier ist das Update fuer die LDAP Integration:

Code:
# Git over HTTP: http://git.repo.yourdomain.org/git/<project>.git
<VirtualHost *:80>
        ServerName      git.repo.yourdomain.org
        ServerAlias     git.repo.yourdomain.org
        ServerAdmin     user@yourdomain.org

        ErrorLog        /var/log/apache/git.repo.yourdomain.org-error_log
        CustomLog       /var/log/apache/git.repo.yourdomain.org-access_log combined

        # ------------- Git Clone Environment Variables
        SetEnv GIT_PROJECT_ROOT /var/git/base
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

        ScriptAlias /git/ /usr/local/libexec/git-core/git-http-backend/

        ### Project: test.git
        <Location "/git/test.git">
                Order allow,deny
                Allow from All
                AuthName "GIT Repo: test.git"
                AuthType Basic
                AuthBasicProvider ldap
                AuthLDAPURL "ldap://ldap.yourdomain.org:389/ou=People,dc=yourdomain,dc=org?uid?sub?(objectClass=*)"
                AuthLDAPGroupAttribute memberUid
                AuthLDAPGroupAttributeIsDn off
                # access only to ldap-group 'developer'
                Require ldap-group cn=developer,ou=Groups,dc=yourdomain,dc=org
                Require valid-user
        </Location>


        ### Project: test2.git
        <Location "/git/test2.git">
                Order allow,deny
                Allow from All
                AuthName "GIT Repo test2.git"
                AuthType Basic
                AuthBasicProvider ldap
                AuthLDAPURL "ldap://ldap.yourdomain.org:389/ou=People,dc=yourdomain,dc=org?uid?sub?(objectClass=*)"
                AuthLDAPGroupAttribute memberUid
                AuthLDAPGroupAttributeIsDn off
                # access only to ldap-group 'admin'
                Require ldap-group cn=admin,ou=Groups,dc=yourdomain,dc=org
                Require valid-user
        </Location>

</VirtualHost>
 
Anstelle von
Code:
...
<Location "/git/test.git">
...
Was fuer ein einzelnes Repo gilt, kannst du es auch global fuer alle machen:

Code:
...
<Location "/git/">
...



Btw, ich arbeite gerade noch daran, dass, wenn sich jemand zu gitweb verbindet, das ganze auch ueber http auth passiert und er dann auch nur die Repos sieht, zu denen er Gruppen Rechte hat.

Hat das schon Jemand hier hinbekommen?

Derzeit habe ich nur
Code:
    <Directory "/var/www/intranet/ssl/git">
        SSLRequireSSL

        # GIT Web GUI
        AddHandler cgi-script .cgi
        Options +ExecCGI
        DirectoryIndex gitweb.cgi
        AddHandler cgi-script .cgi
        AllowOverride Limit FileInfo Indexes


        # Authentication via LDAP group "www-git"
        AuthName "example"
        AuthType Basic
        AuthBasicProvider ldap
        AuthLDAPURL "ldap://ldap.example.lan:389/ou=People,dc=the-wire,dc=lan?uid?sub?(objectClass=*)"
        AuthLDAPGroupAttribute memberUid
        AuthLDAPGroupAttributeIsDn off
        Require ldap-group cn=www-git,ou=Groups,dc=example,dc=lan

        # Allow from all via password and all from LAN without password
        Order allow,deny
        Allow from 192.168.0.0/24
        Satisfy any
    </Directory>
 
Zurück
Oben