Closed diefans closed 3 years ago
What would be the expected behaviour? Nginx explicitly clears the environment before starting any subprocess. see http://nginx.org/en/docs/ngx_core_module.html#env if you need any of them preserved
I am wondering, since the first call of New
has everything in the environment (contradicting your statement)... which made me fall into some kind of trap.
Basically I want to be able to setup the plugin e.g. to log to a certain file instead of the kong log - so there are global aspects of plugin config which should not be tweaked via kong config entites. For docker deployments it is the normal way to provide those settings via environment vars.
the first call of
New
has everything in the environment (contradicting your statement)
that happens during initialization, before starting the server itself, and via a completely different mechanism. I'd very much like to eliminate that step, but it's required so we can have the schema before parsing the configuration files. Note that it's currently a separate process invocation, so if you want to pass any information from that step to the actual processing instance you'll need to persist it externally. And, of course, there's no guarantee that it will happen always.
Basically I want to be able to setup the plugin e.g. to log to a certain file instead of the kong log - so there are global aspects of plugin config which should not be tweaked via kong config entites.
The ideal way to do it depends a lot on the infrastructure, platform and scale. Among the options would be to preprocess the YAML files, use a database to store that data, use the Kong API to change settings, a real Control Plane (via hybrid mode), etc.
There is a way to pass env vars:
nginx_main_env = LOG_PATH=/foobar.log
But here I can only inject one nginx env directive, a second one overrideds the first one.
closing this because it's not a planned feature to preserve and pass arbitrary environment variables.
...not a planned feature to preserve and pass arbitrary environment variables
are you saying, that nginx_main_env
is implemented by accident and the fact that it is usable for just one env var is pure collateral damage caused by this accident?
related issues:
all suggested using KONG_NGINX_MAIN_ENV
but passing multiple environment variable via KONG_NGINX_MAIN_ENV
is hacky (it's pretty much an injection because I can pass any nginx directive into that).
can we have better support for passing multiple environment variables to workers and plugins ? or should I create a separated ticket ?
Summary
os.Environ()
is empty on subsequent plugin startsSteps To Reproduce
Additional Details & Logs
Logs after start:
Logs after request: