I made a git server with git http backend.
I created 2 repositories (Project1
, Project2
) and 3 users (user1
, user2
, user3
).
When I clone with command:
git clone http://myodmain/Project1/
I want only user1
and user2
to have access to this clone (Project1
).
When I clone with command:
git clone http://myodmain/Project2/
I want only user3
to have access to this clone (Project2
), and that user1
and user2
can't access it.
Now, my config server can clone, push, pull, merge,... but all users have the same permission.
Please help me with some examples.
You have not provided any information on your server setup, so the answer may vary. I think the most important part you are missing is setting up authentication in your web server. However, once you do that, you will run into an issue with git-http-backend, if you wish to authenticate users separately for different repositories. I posted an answer that covers both issues. You may want to view that post as well to view other comments:
Disabling access for git to specific Directory with Apache Basic Authentication
Here is what I originally posted there: Solution Using Apache 2.4
The problem I found is that the git-http-backend script really controls all access to the repositories. Additionally, ScriptAlias is configured as such that it will be routing all /git/ requests to git-http-backend, regardless of the rest of the path. And, because you have provided access to this script for GITGROUP, that group will have access to any repository starting with /git/ in the URL. As per the documentation,
https://git-scm.com/docs/git-http-backend
git-http-backend knows the location to each repository because Apache is providing it with an environment variable. I suspect this means that git-http-backend is the only process on the server that directly accesses your repositories, and then provides the response back to Apache.
My solution adds a few extra steps. Essentially, you would force any access to git-http-backend to occur only after you have already authenticated to the location of your repository, not before. This is done by placing a link to the script in the repository directory itself, and then authenticating that location.
NOTE: I've only done this with bare repositories (git init --bare). I suspect that if for some reason you need to use a non-bare repository, this solution would need some tweaking (Ideas on that at the end):
In a nutshell:
Details:
If you're not using a bare repository:
I only use bare repositories on the git server, but I think that you might see an issue creating this symlink if you didn't have bare repositories. What I'm worried is that someone could somehow add your link to the repository. I'm not sure if this is possible, but a couple of ideas to get around it: