2

I have a situation where I have to restrict some users from pushing to master branch on remote repo. I found that any user can change the "git config user.name " on his machine to push it to the master branch on remote repo. How do I verify the users login account(ssh/http) and git config user.name is same?

Ramkumar D
  • 9,226
  • 2
  • 17
  • 18
  • How do the users currently access your repository? Do they need to authenticate in any way? – michas May 20 '13 at 08:43
  • I cloned the repo like below 1) git clone ssh://abc@hostname/gitrepos/test.git 2) git config user.name xyz 3) after some changes I pushed to remote "git push origin master" 4) git log on the remote repo shows that committer is xyz and author is xyz. Even though I have used user abc for cloning and pushing. – Ramkumar D May 20 '13 at 09:30
  • 1
    Yes, you have to tell git who you are in order for git to produce a meaningful commit, but that is never meant for authentication. - The question is: When connecting to the *remote* repository, does it require some kind of authentication, e.g. password, some key, etc. – michas May 20 '13 at 09:48
  • i have used ssh password (not public/private key pair) – Ramkumar D May 20 '13 at 10:06
  • Now if you have many users for your repository. Do they all use the same name/password, or do they have their own account? If they all use the same account, git has no way of finding out who they are. – michas May 20 '13 at 10:16
  • everyone uses their own account. but issue is we cannot identify if a user impersonates other by setting git config user.name – Ramkumar D May 20 '13 at 10:26

3 Answers3

2

You have two totally different questions:

1. How do I restrict the users allowed to push on a given branch?

First you need a way to authenticate your users. The easiest way to do so is by personalized ssh keys. Then you need a layer of authorization to determine who is allowed to push on which branch. This can be done by a software like gitolite. Please read this link for more information.

2. How do I make sure people do not use a fake identity via git config user.name?

First you cannot prevent people to use arbitrary names while committing at their local repositories. You can only check once they try to push those commits to your central repository.

A single push is able to transfer multiple commits. If you want to make sure each commit contains the correct user name and mail address, you first have to make sure you know who is currently pushing. And then you need to check all pushed commits for the correct user name and mail address.

You can again use gitolite for that. Also gerrit is able to do this kind of checks.

Community
  • 1
  • 1
michas
  • 25,361
  • 15
  • 76
  • 121
  • I used gitolite and tested the acl. it is working fine. but still users be able to use different names in git coing user.name. I think writing one more hook should solve this problem. thanks to all for your suggestions/answers. – Ramkumar D Jul 10 '13 at 05:50
0

Git itself is not able to enforce that kind of restriction.

You need some authentication layer like gitolite for your situation.

michas
  • 25,361
  • 15
  • 76
  • 121
  • even if i use gitolite, user can set "git config user.name any_allowed_user" and then able to push under master branch on remote repo. I want to know a mechanism to verify the user doing the commit and git config user.name is same. – Ramkumar D May 20 '13 at 09:29
  • 1
    Please *read* the provided link. First you need a way to authenticate your users, e.g. each of them having there own ssh key. Then gitolite *knows* who they are and you can place your restrictions. The user.name configured is not meant for authentication. – michas May 20 '13 at 10:19
  • hi michas, hope now you have understood the requirements clearly in the above comments section. help me if you have different ideas. – Ramkumar D May 21 '13 at 05:24
0

If you're thinking about this kind of restrictions, maybe it's time to change your project organisation.

You can ask your developers to fork the project and work on their own repository.

You'll keep a full control of what is merged in your project (on all branches). Each developer grab a branch and work on it. Once the job is done, you (from the main repo) will merge its modifications.

aymericbeaumet
  • 6,853
  • 2
  • 37
  • 50
  • thanks for your reply. please see the comments section where I have given more details about this requirements. – Ramkumar D May 21 '13 at 05:22