troglobit/merecat

Setting environment variable for CGI

alephnull opened this issue · 3 comments

I am attempting to get merecat server git-http-backend over CGI. I need to set an environment variable, GIT_PROJECT_ROOT. I attempted setting up an override:

$ cat /lib/systemd/system/merecat.service.d/10-git.conf
[Service]
EnvironmentFile=/var/www/git.alephnull.site/env
$ cat /var/www/git.alephnull.site/env
GIT_PROJECT_ROOT=/srv/repos
GIT_HTTP_EXPORT_ALL=1

This seems to have set the environment vars correctly:

$  sudo cat /proc/$(pgrep merecat)/environ | tr '\0' '\n'
LANG=en_IN
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
INVOCATION_ID=12fd140812c6464aa486e89c7b5cf93e
JOURNAL_STREAM=9:1042993
GIT_PROJECT_ROOT=/srv/repos
GIT_HTTP_EXPORT_ALL=1

However, going to http://git.alephnull.site/cgi-bin/printenv does not show me those variables.

Hi! Merecat scrubs the environment before forking off CGI children, because of security reasons, so unfortunately you cannot set CGI env. variables like that. We could consider adding Apache SetEnv style support, but there's nothing there atm.

(Btw, I blogged a while back about how to set up cgit with merecat, here -> https://troglobit.com/2018/03/cgit-with-merecat-httpd/ maybe it helps.)

I tried a wrapper around the binary to set the env vars. It tdidn't work but I think it should. I;m not sure what I'm doing wrong though.

% cat ghb.cgi 
#!/bin/sh

export GIT_PROJECT_ROOT=/srv/repos
export GIT_HTTP_EXPORT_ALL=1

env GIT_PROJECT_ROOT=/srv/repos  GIT_HTTP_EXPORT_ALL=1 /usr/lib/git-core/git-http-backend

Yup, a wrapper like that should work.

FYI, I've planned to add Apache SetEnv-style support to Merecat. Not there yet though.