threads / discuss / 50134

Git extra hook, pre-upload

Subject: Git extra hook, pre-upload

## tl;dr

5 messages between Dec 30, 2018 and Jan 6, 2019.

replies: 4people: 4as markdown or json

Xheroz 128· Dec 30, 2018, 20:11 UTC · lore
Hello,
My name is Kenneth Lee, a student at Teikyo University, Japan.
Currently, I’m doing my Final Year Project that requires a hook that executes automatically on the server side of the repository, before the objects been pulled to the client side, and after the objects have been pushed to the server side, which is "post-receive" hook. The post-receive hook work well for me, but I couldn’t find any hook to be executed immediately before an upload-operation is performed, i.e. before data is sent to the client. 
Why Git doesn't have a hook that executed immediately before the data is sent to the client? Any advice on getting this hook or any similar function of the hook? 
Thanks,

Kenneth Lee Zhen Kang +8180-9828-2935

Ævar Arnfjörð Bjarmason· Dec 30, 2018, 21:34 UTC · re: Xheroz 128 · lore

Re: Git extra hook, pre-upload

On Sun, Dec 30 2018, Xheroz 128 wrote:
> Currently, I’m doing my Final Year Project that requires a hook that executes automatically on the server side of the repository, before the objects been pulled to the client side, and after the objects have been pushed to the server side, which is "post-receive" hook. The post-receive hook work well for me, but I couldn’t find any hook to be executed immediately before an upload-operation is performed, i.e. before data is sent to the client.
>
> Why Git doesn't have a hook that executed immediately before the data is sent to the client? Any advice on getting this hook or any similar function of the hook?

We do not have such a pre-upload hook, but could have one. There's an old thread from 2011 detailing some potential downsides:

https://public-inbox.org/git/CAMK1S_jaEWV=F6iHKZw_6u5ncDW0bPosNx-03W9bOLOfEEEY1Q@mail.gmail.com/

FWIW I think most servers who find themselves needing such a hook use it to e.g. log how many fetches a given repository might serve, and end up instead wrapping git commands in some custom shell.

It's also possible to imagine a much deeper integration for such a hook, e.g. something that would allow you to implement the functionality of the uploadpack.* variables and more in your own code, but I don't know if that's the sort of thing you're imagining.

Junio C Hamano· Jan 2, 2019, 17:27 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: Git extra hook, pre-upload

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 8 quoted lines
> We do not have such a pre-upload hook, but could have one. There's an
> old thread from 2011 detailing some potential downsides:
>
> https://public-inbox.org/git/CAMK1S_jaEWV=F6iHKZw_6u5ncDW0bPosNx-03W9bOLOfEEEY1Q@mail.gmail.com/
>
> FWIW I think most servers who find themselves needing such a hook use it
> to e.g. log how many fetches a given repository might serve, and end up
> instead wrapping git commands in some custom shell.
Thanks for a concise summary.
Jeff King· Jan 3, 2019, 07:29 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: Git extra hook, pre-upload

On Sun, Dec 30, 2018 at 10:34:26PM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 20 quoted lines
> 
> On Sun, Dec 30 2018, Xheroz 128 wrote:
> 
> > Currently, I’m doing my Final Year Project that requires a hook that executes automatically on the server side of the repository, before the objects been pulled to the client side, and after the objects have been pushed to the server side, which is "post-receive" hook. The post-receive hook work well for me, but I couldn’t find any hook to be executed immediately before an upload-operation is performed, i.e. before data is sent to the client.
> >
> > Why Git doesn't have a hook that executed immediately before the data is sent to the client? Any advice on getting this hook or any similar function of the hook?
> 
> We do not have such a pre-upload hook, but could have one. There's an
> old thread from 2011 detailing some potential downsides:
> 
> https://public-inbox.org/git/CAMK1S_jaEWV=F6iHKZw_6u5ncDW0bPosNx-03W9bOLOfEEEY1Q@mail.gmail.com/
> 
> FWIW I think most servers who find themselves needing such a hook use it
> to e.g. log how many fetches a given repository might serve, and end up
> instead wrapping git commands in some custom shell.
> 
> It's also possible to imagine a much deeper integration for such a hook,
> e.g. something that would allow you to implement the functionality of
> the uploadpack.* variables and more in your own code, but I don't know
> if that's the sort of thing you're imagining.
Since that thread, we've added this config:
  uploadpack.packObjectsHook
	     If this option is set, when upload-pack would run git
	     pack-objects to create a packfile for a client, it will run
	     this shell command instead. The pack-objects command and
	     arguments it would have run (including the git pack-objects
	     at the beginning) are appended to the shell command. The
	     stdin and stdout of the hook are treated as if pack-objects
	     itself was run. I.e., upload-pack will feed input intended
	     for pack-objects to the hook, and expects a completed
	     packfile on stdout.
	     Note that this configuration variable is ignored if it is
	     seen in the repository-level config (this is a safety
	     measure against fetching from untrusted repositories).
So:
  1. That's some prior art for how an upload-pack hook could behave
     without introducing a security problem.
  2. Depending on what you want to do, this hook may be enough already.
     But it can't do everything (for instance, a fetch which results in
     no objects being requested would not trigger the hook at all, so if
     you were planning to keep stats about no-op fetches, it would not
     work).
-Peff
Jeff King· Jan 6, 2019, 06:07 UTC · lore

Re: Git extra hook, pre-upload

[re-add git@vger cc]
On Sat, Jan 05, 2019 at 01:47:11PM +0900, Xheroz 128 wrote:
Show 6 quoted lines
> Thank you for all your replies. I have read the thread from 2011 and
> understand the reason of the insecure part using pre and post upload
> hooks.
> But for my project I would still like to use pre-upload hook. But I do
> not know how to enable the ALLOW_INSECURE_HOOKS in my system. How to
> configure it?

We never actually merged that patch, so there is no such build-time knob in Git. I.e., you can either use the uploadpack.packObjectsHook feature, or you will have to make a custom patch yourself.

-Peff

← back to recent threads