Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Git Server Side Hook to put quota on repository sizes?

Tags:

git

I searched around and found some related topics, but they were all related to limiting file sizes or concerns that there were quotas.

I built a Git server with Gitolite for a place for students to share course projects. It all functions under one username on the server, git, with a wild card repositories "projects/Creator/[a-zA-Z0-9].*". The repositories have WRITERS and READERS defined so the user can modify who can write and read their repository.

SSH key files are implemented so the user can just create a repository by:

git clone [email protected]:projects/bob/project1 git clone [email protected]:projects/bob/someotherproj

and so on. The "bob" folder is created the first time they do the git clone (it's their username).

My issue is that, being students, there will be abuse and I will need to limit the size of the "bob" folder. Disk quotas don't work because all the folders and files are owned by git, and that's already limited.

I can probably re-engineer this to serve their projects from their Linux home folders and thus be able to use disk quotas, however, I'd rather not have to re-engineer this server now that I have it working.

Essentially, I was looking for a hook that did something like this rough shell script:

foldersize=`du -s $GITPATH/projects/$USERNAME`
if [ $foldersize > 250000 ]; then
     echo "Quota Exceeded"
     exit 1
fi

I understand there are server side hooks that can be written, I wanted to see if the wheel was already created before I started carving it out. So, any hooks to limit repository size?

like image 759
Bob Avatar asked Jun 06 '12 12:06

Bob


1 Answers

The git pre-receive hook could be used to implement quotas. From the githooks(5) man page:

This hook is invoked by git-receive-pack on the remote repository,
which happens when a git push is done on a local repository. Just
before starting to update refs on the remote repository, the
pre-receive hook is invoked. Its exit status determines the success or
failure of the update.

So you would put your quota checking logic in this script and allow or reject an incoming update depending on the result. It would be your job to actually perform quota management; there are a number of ways to do this, the simplest being relying on your filesystem's support for user quotas.

You could certainly use your du example, although as repositories grow in size this will impose a substantial delay (and i/o burden) for each update. Caching the results from this script for some amount of time would probably help out, although the trade-off here is obviously that someone could then exceed their quota if they push an update before the cache has expired.

Depending on how your storage is organized, you could look into per-directory quotas for the git repositories (if your storage comes from something that supports this, like most enterprise fileservers), or using an LVM volume per repository (as suggested here).

Despite suggestions to the contrary, implementing quotas for a remote repository is fairly common. Most git-hosting services limit your disk storage and will reject updates once you hit your limit.

like image 187
larsks Avatar answered Oct 02 '22 14:10

larsks