0

I had a functioning setup on Ubuntu 14.04 with Lighttpd 1.4.33 installed via apt which passed to git-http-backend for git http pull/push. This was authenticated via ldap. A new requirement for ldap group lookups meant I needed to update lighttpd to support it.

As lighttpd only goes upto 1.4.33 on trusty/universe the old version was removed, a copy of Lighttpd 1.4.51 was downloaded and complied from source with:

./configure --with-openssl --with-openssl-libs=/usr/bin/openssl --with-ldap

After setting up a couple of cache folders and setting permissions lighttpd started and appeared to be serving requests. When doing a git pull from a client the logs show the request making it to git-http-backend however after authenticating the client sees on a git pull:

fatal: repository 'https://git.company.co.uk/repos/project_portal.git/' not found

The permissions on the folder where the git repos reside look correct, and lighttpd is running as the same user as in the working setup.

My guess is the setenv.add-environment config items in lighttpd.conf are not being passed/picked up by git-http-backend, so it's not aware where the physical files are.

I've also tried compiling different versions lighttpd however all of them had the same issue, possibly I'm missing a compile option.

Relevant sections from lighttpd.conf below.

server.modules = (
    "mod_auth",
    "mod_access",
    "mod_accesslog",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
    "mod_rewrite",
    "mod_webdav",
    "mod_fastcgi",
    "mod_cgi",
    "mod_setenv",
    "mod_proxy",
    "mod_authn_ldap",
    "mod_openssl"
)

server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80
accesslog.filename          = "/var/log/lighttpd/access.log" 

debug.log-request-handling = "enable"

index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

$SERVER["socket"] == "0.0.0.0:443" {

    ssl.engine = "enable"
    ssl.pemfile = "/etc/lighttpd/ssl/git.company.co.uk.pem"
    ssl.ca-file = "/etc/lighttpd/ssl/xxxIntermediateCertificate.crt"

    $HTTP["host"] == "git.company.co.uk" {
        ssl.pemfile = "/etc/lighttpd/ssl/git.company.co.uk.pem"
        alias.url = ( "/repos" => "/usr/lib/git-core/git-http-backend" )
        $HTTP["url"] =~ "^/repos" {
            cgi.assign = ("" => "")
            setenv.add-environment = (
                "GIT_PROJECT_ROOT" => "/var/www/repositories",
                "GIT_HTTP_EXPORT_ALL" => ""
            )
            auth.require = ( "" => (
                "method" => "basic",
                "realm" => "repos",
                "require" => "valid-user"
            ))
            auth.backend = "ldap"
            auth.backend.ldap.hostname              = "172.xxx"
            auth.backend.ldap.base-dn               = "OU=ITS,xxx"
            auth.backend.ldap.filter                = "(CN=$)"
            auth.backend.ldap.bind-dn               = "CN=xxx"
            auth.backend.ldap.bind-pw               = "xxx"
            auth.backend.ldap.allow-empty-pw        = "disable"
        }
    }
}

lighttpd -V

lighttpd/1.4.51 (ssl) - a light and fast webserver

Event Handlers:

        + select (generic)
        + poll (Unix)
        + epoll (Linux)
        - /dev/poll (Solaris)
        - eventports (Solaris)
        - kqueue (FreeBSD)
        - libev (generic)

Network handler:

        + linux-sendfile
        - freebsd-sendfile
        - darwin-sendfile
        - solaris-sendfilev
        + writev
        + write
        - mmap support

Features:

        + IPv6 support
        + zlib support
        + bzip2 support
        + crypt support
        + SSL support
        + PCRE support
        - MySQL support
        - PgSQL support
        - DBI support
        - Kerberos support
        + LDAP support
        - PAM support
        - memcached support
        - FAM support
        - LUA support
        - xml support
        - SQLite support
        - GDBM support

Error.log

2018-10-22 07:21:55: (response.c.422) -- splitting Request-URI
2018-10-22 07:21:55: (response.c.423) Request-URI     :  /repos/project_portal.git/info/refs?service=git-                             upload-pack
2018-10-22 07:21:55: (response.c.424) URI-scheme      :  https
2018-10-22 07:21:55: (response.c.425) URI-authority   :  git.company.co.uk
2018-10-22 07:21:55: (response.c.426) URI-path (raw)  :  /repos/project_portal.git/info/refs
2018-10-22 07:21:55: (response.c.427) URI-path (clean):  /repos/project_portal.git/info/refs
2018-10-22 07:21:55: (response.c.428) URI-query       :  service=git-upload-pack
2018-10-22 07:21:55: (mod_access.c.156) -- mod_access_uri_handler called
2018-10-22 07:21:55: (response.c.573) -- before doc_root
2018-10-22 07:21:55: (response.c.574) Doc-Root     : /var/www
2018-10-22 07:21:55: (response.c.575) Rel-Path     : /repos/project_portal.git/info/refs
2018-10-22 07:21:55: (response.c.576) Path         :
2018-10-22 07:21:55: (response.c.628) -- after doc_root
2018-10-22 07:21:55: (response.c.629) Doc-Root     : /var/www
2018-10-22 07:21:55: (response.c.630) Rel-Path     : /repos/project_portal.git/info/refs
2018-10-22 07:21:55: (response.c.631) Path         : /var/www/repos/project_portal.git/info/refs
2018-10-22 07:21:55: (response.c.655) -- logical -> physical
2018-10-22 07:21:55: (response.c.656) Doc-Root     : /var/www
2018-10-22 07:21:55: (response.c.657) Basedir      : /usr/lib/git-core/git-http-backend
2018-10-22 07:21:55: (response.c.658) Rel-Path     : /repos/project_portal.git/info/refs
2018-10-22 07:21:55: (response.c.659) Path         : /usr/lib/git-core/git-http-backend/project_portal.gi                             t/info/refs
2018-10-22 07:21:55: (response.c.671) -- handling physical path
2018-10-22 07:21:55: (response.c.672) Path         : /usr/lib/git-core/git-http-backend/project_portal.gi                             t/info/refs
2018-10-22 07:21:55: (response.c.679) -- handling subrequest
2018-10-22 07:21:55: (response.c.680) Path         : /usr/lib/git-core/git-http-backend
2018-10-22 07:21:55: (response.c.681) URI          : /repos
2018-10-22 07:21:55: (response.c.682) Pathinfo     : /project_portal.git/info/refs
2018-10-22 07:21:55: (mod_access.c.156) -- mod_access_uri_handler called
2018-10-22 07:21:55: (mod_compress.c.854) -- handling file as static file

Any suggestions are welcome, thanks.

1 Answers1

0

Check the lighttpd error log in /var/log/lighttpd/error.log.

Check the path to git-http-backend on your server. It might be /usr/lib/git-core/git-http-backend, or it might be /usr/libexec/git-core/git-http-backend.

Try setting a value for "GIT_HTTP_EXPORT_ALL" => "1" or else git does not export the repos. You can see this if you look at the lighttpd breakage log (output from CGI), if configured, or if you start up lighttpd in the foreground (-D) and see trace from git-http-backend.

gstrauss
  • 2,091
  • 1
  • 12
  • 16
  • Nothing obvious in the error log, have updated the question it with a copy. Double checked the path you suggested and it is correct. – Richard Pryce Oct 22 '18 at 06:28
  • Try disabling mod_compress. If the log you provided is complete, then why is mod_compress handling the request? Try (temporarily) disabling other modules to create a simpler config and possibly help narrow down where the issue exists. – gstrauss Oct 23 '18 at 09:15
  • Disabling mod_compress (and the other non-required mods) didn't make a change to the git pull message. The log didn't show any change either apart from losing a couple of mod specific lines. – Richard Pryce Oct 23 '18 at 11:55
  • Try setting a value for "GIT_HTTP_EXPORT_ALL" => "1" or else git does not export the repos. You can see this if you look at the lighttpd breakage log (output from CGI), if configured, or if you start up lighttpd in the foreground (-D) and see trace from git-http-backend. I'll edit this into my answer above as well. – gstrauss Oct 24 '18 at 05:04
  • Setting the git_http_export_all value did the trick, I find it strange that having it initialised but empty as defined in the git-http-backend docs worked previously. Something must have changed at some point. Thanks for your help. – Richard Pryce Oct 24 '18 at 06:36
  • Turns out that lighttpd 1.4.46 (released Oct 2017) added setenv.set-environment to complement setenv.add-environment. In lighttpd 1.4.51 (released Oct 2018), setenv.add-environment was modified to not add blank values, but setenv.set-environment will do so. For backward compatibility with older version of lighttpd (without setenv.set-environment) using setenv.add-environment, "GIT_HTTP_EXPORT_ALL" => "1" works with older and newer lighttpd. I submitted https://github.com/git/git/pull/546 to update git-http-backend documentation. – gstrauss Oct 27 '18 at 22:37
  • 1
    Oh man! I just bumped lighttpd to 1.4.59 on Ubuntu Impish and was troubleshooting this for day. Ended up needing `"GIT_HTTP_EXPORT_ALL" => "1"` to fix it. Wasn't necessary before. So the behaviour was changed again, so that `add-environment` do not add empty vars? @gstrauss ? Also, it's still not in the git docs > https://github.com/git/git/pull/546 – Lars Bingchong Mar 08 '22 at 20:24
  • @LarsBingchong ick, sorry. You are correct. It looks like this is a regression since lighttpd 1.4.56, which was released over a year ago. (bug due to difference between "unset" () and "blank" string ("")) This will be fixed (again) in lighttpd 1.4.65, and a test has been added to the test suite to prevent this from breaking again. Unfortunately, Ubuntu is historically horrid at picking up and backporting lighttpd patches, so I expect this to continue to be broken in Ubuntu for years until the next major Ubuntu release which picks up lighttpd 1.4.65 or later. – gstrauss Mar 09 '22 at 22:11
  • @gstrauss fair enough. Hard to do much about the way Ubuntu picks up packages. I appreciate you chiming in. So I can pretty much just specify "1" to the `GIT_HTTP_EXPORT_ALL` env. var. And be safe for a long time to come. And doing that will also work in v1.4.65 of lighttpd? Thank you very much – Lars Bingchong Mar 11 '22 at 18:30