Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give Read-only access to a git repository

I'm not sure if this should go here, or on superuser (as it seems to pertain to both topics), so I've put it here, if it's not appropriate, I'll go ask it on superuser.

Anyway, I have a git repository that can't go completely open source (otherwise I would just put it on github and be done with it), and I have a server that I have ssh access (but not superuser access) to, this server has all of the git binaries already on it. I need to give someone read-only access to this git-repo (or at least read-only access to some of the branches, although I would imagine that's a lot harder).

Currently I'm using ssh to push and poll my local git repo to this server. Is there any way to give another person read only access to the server? (I suppose I am fine with us both having write access to the repo, although I'm not sure how to do that with unix permissions, as I don't have the ability to make new unix groups as I don't have superuser permissions).

Thank you for your help.

like image 359
Leif Andersen Avatar asked Oct 11 '10 17:10

Leif Andersen


People also ask

How do I restrict access to GitHub repository?

Under your repository name, click Settings. In the sidebar, select Moderation options, then click Interaction limits. Under "Temporary interaction limits", to the right of the type of interaction limit you want to set, use the Enable drop-down menu, then click the duration you want for your interaction limit.


2 Answers

You want to use the git protocol. http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html

It'll be public to everybody, which may not be what you want, but nobody will be able to do a push over git://.

You can control what branches they can access by only pushing the branches you want to be accessible to it.
I would do this by having a separate clone from your ssh enabled private repository, and then add that as a remote. Then you can do git push pub public-branch, so then private-branch won't be accessible from that location.

like image 132
jonescb Avatar answered Oct 02 '22 01:10

jonescb


In .ssh/authorized_keys you can specify a command that is always run when a given public key is used to log in. You could probably set this to git-upload-pack /path/to/repo.git and git pull just might work. There may very well be non-obvious security pitfalls with this approach.

See the sshd manual page for the format of the authorized_keys file.

like image 45
Jouni K. Seppänen Avatar answered Oct 01 '22 23:10

Jouni K. Seppänen