Skip to content

Commit 4d65a9e

Browse files
committed
Solve authentication problem
There is an issue with the authentication section. The initial ref advertisement request will fail without even giving an opportunity for authentication. This is described in the git-http-backend man page examples. Update authentication section according to the example to fix the problem. Merge the section with the git-core access authorization section for brevity. Signed-off-by: Vitaly Kuznetsov <[email protected]>
1 parent bf8d8a0 commit 4d65a9e

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

book/04-git-server/sections/smart-http.asc

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ If you don't have Apache setup, you can do so on a Linux box with something like
1313
[source,console]
1414
----
1515
$ sudo apt-get install apache2 apache2-utils
16-
$ a2enmod cgi alias env
16+
$ a2enmod cgi alias env rewrite
1717
----
1818

19-
This also enables the `mod_cgi`, `mod_alias`, and `mod_env` modules, which are all needed for this to work properly.
19+
This also enables the `mod_cgi`, `mod_alias`, `mod_env`, and `mod_rewrite` modules, which are all needed for this to work properly.
2020

2121
You’ll also need to set the Unix user group of the `/opt/git` directories to `www-data` so your web server can read- and write-access the repositories, because the Apache instance running the CGI script will (by default) be running as that user:
2222

@@ -36,28 +36,24 @@ ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
3636

3737
If you leave out `GIT_HTTP_EXPORT_ALL` environment variable, then Git will only serve to unauthenticated clients the repositories with the `git-daemon-export-ok` file in them, just like the Git daemon did.
3838

39-
Then you'll have to tell Apache to allow requests to that path with something like this:
39+
Finally you'll want to tell Apache to allow requests to `git-http-backend` and make writes be authenticated somehow, possibly with an Auth block like this:
4040

4141
[source,console]
4242
----
43-
<Directory "/usr/lib/git-core*">
44-
Options ExecCGI Indexes
45-
Order allow,deny
46-
Allow from all
47-
Require all granted
48-
</Directory>
49-
----
50-
51-
Finally you'll want to make writes be authenticated somehow, possibly with an Auth block like this:
43+
RewriteEngine On
44+
RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
45+
RewriteCond %{REQUEST_URI} /git-receive-pack$
46+
RewriteRule ^/git/ - [E=AUTHREQUIRED]
5247
53-
[source,console]
54-
----
55-
<LocationMatch "^/git/.*/git-receive-pack$">
48+
<Files "git-http-backend">
5649
AuthType Basic
5750
AuthName "Git Access"
5851
AuthUserFile /opt/git/.htpasswd
5952
Require valid-user
60-
</LocationMatch>
53+
Order deny,allow
54+
Deny from env=AUTHREQUIRED
55+
Satisfy any
56+
</Files>
6157
----
6258

6359
That will require you to create a `.htpasswd` file containing the passwords of all the valid users.

0 commit comments

Comments
 (0)