5

I have a very specific question on the user model. (I'm guessing asking this question will betray my ignorance, but hey, I just want to know!)

I have a simple Ubuntu server that will hold our project repository from which about 6 guys will clone the project. Each has his own user account on this host. The project repository resides on the path /home/git/project-name.git. I could set up a group to corral these users and the git user.

When the developer users push to this remote repository, I don't want them doing it all as the same user (say user 'git' or something) since I want to know who has done what.

If I have everyone drop an id_rsa.pub.name key onto the path /home/git/.ssh/, then add themselves to */home/git/.ssh/authorized_keys* , I'm not going to find out who did what, right?

Therefore, do I grant full access to /home/git/project-name.git to each the group to which the developer user accounts belong on this host?

Any advice would be warmly welcomed.

Thanks, Russ

Russ Bateman
  • 18,333
  • 14
  • 49
  • 65

4 Answers4

5

Rather than Gitosis, I would recommend Gitolite for fine-grained authorization coupled with ssh-based authentication.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So, day before yesterday, I ultimately went with gitolite. Ordinarily, I hate wrapping things around other things, but in retrospect, I doubt I could have set up Git correctly for a workgroup without this tool. Yesterday, I began adding sources and users who've added sources, etc. I don't have experience with gitosis or other solutions, but once I got over the intellectual hurdles of how gitolite works, I became a believer. Thanks to all responders and commentors here. – Russ Bateman May 06 '11 at 13:46
  • @Russ: any DVCS (Git, Mercurial, bazaar, ...) won't offer you authorization. See http://stackoverflow.com/questions/5683253/distributed-version-control-systems-and-the-enterprise-a-good-mix/5685757#5685757 – VonC May 06 '11 at 15:39
3

The general practice is to have one account rather than having several ssh accounts for everyone wanting to push to a repo.

http://progit.org/book/ch4-4.html

http://blog.felipebalbi.com/2008/01/03/git-push-and-ssh-keys/

This doesn't remove you of the ability to know who committed what. The author/ committer is independent of the ssh user.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Thanks for this clarification. We had reached the other conclusion; it's good to know. I'm very grateful for the other answers and suggestions too. – Russ Bateman May 04 '11 at 19:10
3

I recommend using something like Gitolite (download) for what you want, so you can chose who has access to what. You set up a "git" user that everyone uses for Git pushes. Git itself tracks who did what commit, so you shouldn't lose that.

Shauna
  • 9,495
  • 2
  • 37
  • 54
  • Gitosis is unmaintained and deprecated. Use [gitolite](https://github.com/sitaramc/gitolite) instead. – Arrowmaster May 04 '11 at 19:01
  • Geez, tough crowd. Don't even get upvotes for mentioning git managers, period. =/ @arrowmaster - Thanks for the correction. We were already using Gitosis since before it went unmaintained. – Shauna May 04 '11 at 19:06
  • 1
    I've been using stackOverflow for less than a year and I'm still not certain of the best protocols. This forum has lots of busy stuff to do and I sometimes forget myself to bump other's answers. (I just bumped now.) – Russ Bateman May 04 '11 at 19:18
  • @Russ - Indeed. From what I've seen, the guideline is "if it's good." That, of course, is subjective, but I've taken it to mean valuable in some way (be it well-written if a question or comment, or thorough or spawns a more thorough answer if an answer, or elaborates/clarifies an answer if a comment, stuff like that). – Shauna May 04 '11 at 19:24
2

Letting multiple users write to a repository does not mean that you will be able to determine “who has done what”.

It is true that the first (server-local) user to create a particular object (blob, tree, commit, annotated tag) will be the owner of the object’s loose object file (though any other user with write access could probably delete and rewrite the file), but ultimately those loose object files are ephemeral. The individual loose objects will eventually be packed and deleted (e.g. via git gc, either manually or automatically once enough loose objects have accumulated).

Git does neither authentication, nor authorization, thus is has no idea about the “user” that is doing a push1. Since it has no concept of the active user, it can not provide a log of “who pushed/modified/deleted what”. If you need such an audit log, you will have to rely on whatever tool is actually doing the authentication. Unfortunately, many Git hosting tools focus on the distributed nature of Git so they tend not to offer much support for “centralized” features like an audit log. There are some exceptions, though:

  • Gitolite keeps a log that might be usable as an audit log (the authentication is done by either the SSH server or the HTTP server, but Gitolite does the authorization).
  • Gerrit seems to have some built-in restrictions that try to more strongly associate the committer (and author, depending on configuration) user information with the authenticated user accounts (see Forge Identity); while this is not an audit log, it might suffice if you consistently restrict the “forging” authority.

(There are probably other tools or services that have some logging/restriction features, too.)

See Also: Git Log History

1 Git does keep track of an author and committer for each commit (tagger for each annotated tag), but their values are not restricted by Git. Anyone can change the effective author or committer by changing (or overriding) their user.email and user.name configuration variables or setting the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, and GIT_COMMITTER_EMAIL environment variables while making a commit or tag.

Community
  • 1
  • 1
Chris Johnsen
  • 214,407
  • 26
  • 209
  • 186
  • @Chirs: if you need an audit log, simply add it to the receive-pack hook, e.g. a write to syslog, or a mail sent out. – Marc Mutz - mmutz May 05 '11 at 17:31
  • 1
    @mmutz: The `post-receive`, `post-update`, or (in general) any hook may not have access to the authenticated user identity unless the authentication mechanism (e.g.) sets an environment variable that you can log along with the time and commit(s) received. – Chris Johnsen May 05 '11 at 17:42
  • Sometimes I'm in something just to learn it and other times, like this one, I need to set up something new (I'm a Subversion guy) and have it work as if I actually knew what I was doing when I set it up. I don't have time to do it wrong, then do it over. I'm glad now I ultimately chose gitolite and I don't think I'll live to regret it. – Russ Bateman May 06 '11 at 14:00