tags:

views:

1239

answers:

4

I have installed git and gitosis and I need to add a check that the user name is valid when something is pushed into the repository.

I reckon the pre-receive hook is the correct hook to place this, but I'm unable to find the real user name and email address which gitosis enters into the repository (the ones set by git config user.name and git config user.email) from environment variables. LOGNAME and USER are both 'git'. How does gitosis detect this info and can I find it in the pre-receive hook as well?

+3  A: 

Hmm, from what I gather from githooks(5) the pre-receive hook gets fed the updated refs on stdin.

#!/bin/sh

while read old new name; do
    email=$(git log -1 --pretty=format:%ae $new)
    # check email
done

You would need to check the email addresses (there can be more than one line of data) and exit the script accordingly, i.e. exit 0 for success and e.g. exit 1 for failure.

Bombe
OK, that actually answers my question but in fact my question was not the correct one :( What I really need to see is the email address gitosis uses to match the ssh key. The reason: we have an autobuild system which has limited access. Everyone can write to the repository (so gitosis access doesn't help), but only some are allowed to build.Let's assume I have permission to build. Someone else only needs to change the email address (git config user.email) to mine and he is granted access as well. I would need to check the email address used by gitosis to check the ssh key to prevent this.
Makis
I have never worked with gitosis so I can not help you there, sorry.
Bombe
Sorry, I tested and as far as I can tell, that does not work in pre-receive, since the log only holds commited events.
Makis
+1  A: 

Adding os.environ['WHATVER_USER']=user at ~line 202 in serve.py should do the trick...

pan1nx
+2  A: 
Makis
+2  A: