0

I have been following the steps on Hosting a Git server under Apache on Windows and got everything working fine. I then wanted to add in a basic authentication for push requests and so made changes following the solution given to this question to my httpd.conf file and created a user with a password.

But when I try to push to my repository (on localhost) I get a 403 error. Why might this be?

The addition at the end of my httpd.conf file is below.

# Local git repository setup

# Git repository information
SetEnv GIT_PROJECT_ROOT C:/Repositories
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAliasMatch \
"(?x)^/(.*/(HEAD | info/refs | objects/(info/[^/]+ | [0-9a-f]{2}/[0-9a-f]{38} | pack/pack-[0-9a-f]{40}.(pack|idx)) | git-(upload|receive)-pack))$" \
"C:/Program Files/git/libexec/git-core/git-http-backend.exe/$1"

# Allow cloning of repository without authentication
<Directory />
    Require all granted
</Directory>

# Authentication
<LocationMatch "^/.*/git-receive-pack$">
    Options +ExecCGI
    AuthType Basic
    AuthName "Git Login"
    AuthUserFile "C:/wamp/bin/apache/apache2.4.9/passwords/git_passwords"
    Require user alec
</LocationMatch>

Also, I have seen questions like this both on SuperUser and StackOverflow. If someone could tell me which site it is suited to more that would be great.

Edit

Checking the apache error log reveals this error

AH01215: Service not enabled: 'receive-pack'

Solution with new problem Adding SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER allows me to push to the repo but I never get asked for a password...

0

You have a location match for git-receive-pack but not for git-upload-pack. Do the same LocationMatch block for git-upload-pack as well.

  • Just tried adding the same block immediately after with git-upload-pack instead of git-receive-pack but still get the same error. I've added the apache error log, does that explain it? – Kvothe Jun 28 '15 at 18:38
  • @Kvothe hmm.. I will investigate further, in that case. – oldmud0 Jun 28 '15 at 21:09
0

Finally got things working (although I'm not entirely sure how). The changes to my httpd.conf file are at the end like this:

# Local git repository setup

# Git repository information
SetEnv GIT_PROJECT_ROOT C:/Repositories
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
ScriptAliasMatch \
"(?x)^/(.*/(HEAD | info/refs | objects/(info/[^/]+ | [0-9a-f]{2}/[0-9a-f]{38} | pack/pack-[0-9a-f]{40}.(pack|idx)) | git-(upload|receive)-pack))$" \
"C:/Program Files/git/libexec/git-core/git-http-backend.exe/$1"

# Allow cloning of repository without authentication
<Directory />
    Require all granted
</Directory>

# Authentication
<LocationMatch "^/.*/git-receive-pack$">
    Options +ExecCGI
    AuthType Basic
    AuthName "Git Login"
    AuthUserFile "C:/wamp/bin/apache/apache2.4.9/passwords/git_passwords"
    Require user alec
</LocationMatch>
<LocationMatch "^/.*/git-upload-pack$">
    Options +ExecCGI
    AuthType Basic
    AuthName "Git Login"
    AuthUserFile "C:/wamp/bin/apache/apache2.4.9/passwords/git_passwords"
    Require user alec
</LocationMatch>

It appears that a key line was SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.