From: Konstantin Ryabitsev <hidden> Date: 2021-09-04 15:18:00
For the server-side to properly respond to v2 protocol requests, the
webserver must set the GIT_PROTOCOL environment variable to the value of
the Git-Protocol: request header.
Link: https://lore.kernel.org/git/YTNtVJy6sCfQ7T3L@coredump.intra.peff.net/
Reported-by: Philippe Blain <redacted>
Signed-off-by: Konstantin Ryabitsev <redacted>
---
Documentation/technical/protocol-v2.txt | 15 +++++++++++++++
1 file changed, 15 insertions(+)
@@ -81,6 +81,21 @@ A v2 server would reply: Subsequent requests are then made directly to the service `$GIT_URL/git-upload-pack`. (This works the same for git-receive-pack).+The web server handling the requests must properly set the GIT_PROTOCOL+environment variable when it finds `Git-Protocol` in the request headers.++Apache example:++ SetEnvIf Git-Protocol ".*" GIT_PROTOCOL=$0++Nginx + uwsgi example:++ uwsgi_param GIT_PROTOCOL $http_git_protocol;++Nginx + fastcgi example:++ fastcgi_param GIT_PROTOCOL $http_git_protocol;+ Capability Advertisement ------------------------
From: Jeff King <hidden> Date: 2021-09-04 15:55:19
On Sat, Sep 04, 2021 at 11:17:21AM -0400, Konstantin Ryabitsev wrote:
For the server-side to properly respond to v2 protocol requests, the
webserver must set the GIT_PROTOCOL environment variable to the value of
the Git-Protocol: request header.
Thanks for assembling these examples.
I don't mind having these in the technical documentation, but I think
most users won't find them there (nor would they even know they need to
be looking). Maybe the manpage for git-http-backend would be a better
spot. We can mention v2 in the "description" section, and then there's
some example config near the end that could include it.
Unfortunately there isn't any nginx example config there at all yet. If
you have kernel.org config you could share, that would be great. But
even starting with just the "here's how you do v2" part would be
welcome.
-Peff
From: Konstantin Ryabitsev <hidden> Date: 2021-09-07 21:11:33
On Sat, Sep 04, 2021 at 11:55:11AM -0400, Jeff King wrote:
Unfortunately there isn't any nginx example config there at all yet. If
you have kernel.org config you could share, that would be great. But
even starting with just the "here's how you do v2" part would be
welcome.
I'll see if I can come up with something to put into
Documentation/git-http-backend.txt, but I can't right away -- hopefully in
early October once a bunch of conferences are over.
Best regards,
-K
From: Jeff King <hidden> Date: 2021-09-08 10:48:49
On Tue, Sep 07, 2021 at 05:11:28PM -0400, Konstantin Ryabitsev wrote:
On Sat, Sep 04, 2021 at 11:55:11AM -0400, Jeff King wrote:
quoted
Unfortunately there isn't any nginx example config there at all yet. If
you have kernel.org config you could share, that would be great. But
even starting with just the "here's how you do v2" part would be
welcome.
I'll see if I can come up with something to put into
Documentation/git-http-backend.txt, but I can't right away -- hopefully in
early October once a bunch of conferences are over.
It would be great if you could add nginx examples at some point. But in
the meantime, we can do this much easier patch to make sure we don't
forget about mentioning the protocol bits.
-- >8 --
Subject: [PATCH] docs/http-backend: mention v2 protocol
There's a little bit of configuration needed at the webserver level in
order to get the client's v2 protocol probes to Git. But when we
introduced the v2 protocol, we never documented these explicitly.
Commit 9181c4a9ac (Docs: web server must setenv GIT_PROTOCOL for v2,
2021-09-04) now mentions them in the v2 docs themselves, but users
configuring git-over-http for the first time are more likely to be
looking in the git-http-backend manpage. Let's make sure we mention it
there, too, and give some examples.
Both of the included examples here have been tested to work. The one for
lighttpd is a little less direct than I'd like, but I couldn't find a
way to directly set an environment variable to the value of a request
header. From my reading of the documentation, lighttpd will set
HTTP_GIT_PROTOCOL automatically, but git-http-backend looks only at
GIT_PROTOCOL. Arguably http-backend should do this translation itself.
Signed-off-by: Jeff King <redacted>
---
Documentation/git-http-backend.txt | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
@@ -16,7 +16,9 @@ A simple CGI program to serve the contents of a Git repository to Git clients accessing the repository over http:// and https:// protocols. The program supports clients fetching using both the smart HTTP protocol and the backwards-compatible dumb HTTP protocol, as well as clients-pushing using the smart HTTP protocol.+pushing using the smart HTTP protocol. It also supports Git's+more-efficient "v2" protocol if properly configured; see the+discussion of `GIT_PROTOCOL` in the ENVIRONMENT section below. It verifies that the directory has the magic file "git-daemon-export-ok", and it will refuse to export any Git directory
@@ -264,6 +270,11 @@ a repository with an extremely large number of refs. The value can be specified with a unit (e.g., `100M` for 100 megabytes). The default is 10 megabytes.+Clients may probe for optional protocol capabilities using the+`Git-Protocol` HTTP header. In order to support these, the webserver+must be configured to pass the contents of that header to+`git-http-backend` in the `GIT_PROTOCOL` environment variable.+ The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}', ensuring that any reflogs created by 'git-receive-pack' contain some
From: Jeff King <hidden> Date: 2021-09-08 10:57:29
On Wed, Sep 08, 2021 at 06:48:47AM -0400, Jeff King wrote:
Both of the included examples here have been tested to work. The one for
lighttpd is a little less direct than I'd like, but I couldn't find a
way to directly set an environment variable to the value of a request
header. From my reading of the documentation, lighttpd will set
HTTP_GIT_PROTOCOL automatically, but git-http-backend looks only at
GIT_PROTOCOL. Arguably http-backend should do this translation itself.
So having discovered this, I kind of wonder if these documentation
patches are barking up the wrong tree. There is no reason we would not
want v2 to work out of the box (after all, it does for git://).
The patch below does that (and could replace both my and Konstantin's
documentation patches).
This also makes me wonder if we should be documenting the use of
AcceptEnv for ssh (which sadly I don't think we can make work
out-of-the-box).
-- >8 --
Subject: [PATCH] http-backend: handle HTTP_GIT_PROTOCOL CGI variable
When a client requests the v2 protocol over HTTP, they set the
Git-Protocol header. Webservers will generaly make that available to our
CGI as HTTP_GIT_PROTOCOL in the environment. However, that's not
sufficient for upload-pack, etc, to respect it; they look in
GIT_PROTOCOL (without the HTTP_ prefix).
Either the webserver or the CGI is responsible for relaying that HTTP
header into the GIT_PROTOCOL variable. Traditionally, our tests have
configured the webserver to do so, but that's a burden on the server
admin. We can make this work out of the box by having the http-backend
CGI copy the contents.
Signed-off-by: Jeff King <redacted>
---
http-backend.c | 4 ++++
t/lib-httpd/apache.conf | 2 --
2 files changed, 4 insertions(+), 2 deletions(-)
From: Eric Wong <hidden> Date: 2021-09-08 16:51:00
Jeff King [off-list ref] wrote:
On Wed, Sep 08, 2021 at 06:48:47AM -0400, Jeff King wrote:
quoted
Both of the included examples here have been tested to work. The one for
lighttpd is a little less direct than I'd like, but I couldn't find a
way to directly set an environment variable to the value of a request
header. From my reading of the documentation, lighttpd will set
HTTP_GIT_PROTOCOL automatically, but git-http-backend looks only at
GIT_PROTOCOL. Arguably http-backend should do this translation itself.
So having discovered this, I kind of wonder if these documentation
patches are barking up the wrong tree. There is no reason we would not
want v2 to work out of the box (after all, it does for git://).
Agreed.
The patch below does that (and could replace both my and Konstantin's
documentation patches).
<snip>
-- >8 --
Subject: [PATCH] http-backend: handle HTTP_GIT_PROTOCOL CGI variable
When a client requests the v2 protocol over HTTP, they set the
Git-Protocol header. Webservers will generaly make that available to our
"generally"
CGI as HTTP_GIT_PROTOCOL in the environment. However, that's not
sufficient for upload-pack, etc, to respect it; they look in
GIT_PROTOCOL (without the HTTP_ prefix).
Either the webserver or the CGI is responsible for relaying that HTTP
header into the GIT_PROTOCOL variable. Traditionally, our tests have
configured the webserver to do so, but that's a burden on the server
admin. We can make this work out of the box by having the http-backend
CGI copy the contents.
Agreed. I've completely overlooked GIT_PROTOCOL support, so far...
This seems to be the right thing to do; I think I'll add support
for it when I spawn git-http-backend in something I work on.
(I also don't currently pass all HTTP headers in env when
spawning CGI, maybe I should *shrug*)
From: Philippe Blain <hidden> Date: 2021-09-09 17:50:22
Hi Peff,
Le 2021-09-08 à 06:57, Jeff King a écrit :
On Wed, Sep 08, 2021 at 06:48:47AM -0400, Jeff King wrote:
quoted
Both of the included examples here have been tested to work. The one for
lighttpd is a little less direct than I'd like, but I couldn't find a
way to directly set an environment variable to the value of a request
header. From my reading of the documentation, lighttpd will set
HTTP_GIT_PROTOCOL automatically, but git-http-backend looks only at
GIT_PROTOCOL. Arguably http-backend should do this translation itself.
So having discovered this, I kind of wonder if these documentation
patches are barking up the wrong tree. There is no reason we would not
want v2 to work out of the box (after all, it does for git://).
The patch below does that (and could replace both my and Konstantin's
documentation patches).
I agree it's nice to make it work out of the box, without the web server
admin having to configure anything. But, I'm not sure we should completely
drop the documentation patches: your patch will only affect future versions
of git-http-backend, and users of previous versions will be left without
any documentation as to how to configure it for protocol v2. So I would think we should
keep the documentation patches, maybe with a mention "this should not be necessary
in Git 2.34 and later versions" or something like that (since your
commit message mentions that it "generally" should work like that depending
on the web servers).
This also makes me wonder if we should be documenting the use of
AcceptEnv for ssh (which sadly I don't think we can make work
out-of-the-box).