Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting environment variable for CGI #16

Open
alephnull opened this issue Mar 2, 2020 · 3 comments
Open

Setting environment variable for CGI #16

alephnull opened this issue Mar 2, 2020 · 3 comments

Comments

@alephnull
Copy link
Contributor

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.

@troglobit
Copy link
Owner

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.)

@alephnull
Copy link
Contributor Author

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

@troglobit
Copy link
Owner

Yup, a wrapper like that should work.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants