git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Make http-backend REMOTE_USER configurable

From
WSWilliam Strecker-Kellogg <willsk@bnl.gov>
Date
Mar 29, 2012, 19:58 UTC
Message-ID
<1333051139-14262-1-git-send-email-willsk@bnl.gov>

The http-backend looks at $REMOTE_USER and sets $GIT_COMMITTER_NAME to that for use in the hooks. At our site we have a third party authentication module for our proxy (Shibboleth) which sets an alternative environment variable that our backend sees instead of REMOTE USER.

This patch adds the config option http.remoteuser which changes what environment variable is inspected by the http-backend code (it defaults to REMOTE_USER).

Reported-by: Jason Smith <smithj4@bnl.gov>
Tested-by: William Strecker-Kellogg <willsk@bnl.gov>
Signed-off-by: William Strecker-Kellogg <willsk@bnl.gov>
---

I do not know if anyone else may find this useful, but FWIW, this works for us. It may even be a good idea to add the ability to overwrite other default CGI environment variables, although I can't think of any other ones at the moment.

 Documentation/git-http-backend.txt |   14 ++++++++++----
 http-backend.c                     |   13 +++++++++++--
 2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt
index f4e0741..b320a45 100644
--- a/Documentation/git-http-backend.txt
+++ b/Documentation/git-http-backend.txt
@@ -42,6 +42,10 @@ http.getanyfile::
 	It is enabled by default, but a repository can disable it
 	by setting this configuration item to `false`.
 
+http.remoteuser::
+	This setting, if present, changes what environment variable is inspected
+	to determine the remote user (the default is "REMOTE_USER").
+
 http.uploadpack::
 	This serves 'git fetch-pack' and 'git ls-remote' clients.
 	It is enabled by default, but a repository can disable it
@@ -175,10 +179,12 @@ The GIT_HTTP_EXPORT_ALL environmental variable may be passed to
 'git-http-backend' to bypass the check for the "git-daemon-export-ok"
 file in each repository before allowing export of that repository.
 
-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
-identifying information of the remote user who performed the push.
+The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' (or
+if http.remoteuser is present it sets it to $\{http.remoteuser\})
+and GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
+ensuring that any reflogs created by 'git-receive-pack' contain
+some identifying information of the remote user who performed the
+push.
 
 All CGI environment variables are available to each of the hooks
 invoked by the 'git-receive-pack'.
diff --git a/http-backend.c b/http-backend.c
index 869d515..69756f0 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -11,6 +11,7 @@
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
 static const char last_modified[] = "Last-Modified";
+static char *remoteuser = "REMOTE_USER";
 static int getanyfile = 1;
 
 static struct string_list *query_params;
@@ -225,6 +226,14 @@ static int http_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if(!strcmp(var, "http.remoteuser")) {
+		char *tmp;
+		if(git_config_string(&tmp, var, value) == 0) {
+			remoteuser = tmp;
+		}
+		return 0;
+	}
+
 	if (!prefixcmp(var, "http.")) {
 		int i;
 
@@ -261,7 +270,7 @@ static struct rpc_service *select_service(const char *name)
 		forbidden("Unsupported service: '%s'", name);
 
 	if (svc->enabled < 0) {
-		const char *user = getenv("REMOTE_USER");
+		const char *user = getenv(remoteuser);
 		svc->enabled = (user && *user) ? 1 : 0;
 	}
 	if (!svc->enabled)
@@ -315,7 +324,7 @@ done:
 static void run_service(const char **argv)
 {
 	const char *encoding = getenv("HTTP_CONTENT_ENCODING");
-	const char *user = getenv("REMOTE_USER");
+	const char *user = getenv(remoteuser);
 	const char *host = getenv("REMOTE_ADDR");
 	char *env[3];
 	struct strbuf buf = STRBUF_INIT;
-- 
1.7.7.6
Next: Junio C Hamano
Message 1 of 8 in “Make http-backend REMOTE_USER configurable”
  1. Make http-backend REMOTE_USER configurableWilliam Strecker-Kellogg, Mar 29, 2012
  2. Junio C HamanoMar 29, 2012
  3. Jeff KingMar 29, 2012
  4. Jeff KingMar 29, 2012
  5. Junio C HamanoMar 30, 2012
  6. William Strecker-KelloggMar 30, 2012
  7. Jeff KingMar 30, 2012
  8. Junio C HamanoMar 30, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.