-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
How to read env in plugin #7083
Comments
Hi @Asilent, This is expected behavior; in order to be able to read an environment variable from Lua code, you need to specify it in the Nginx In your case, you can achieve that by setting the following Kong configuration as an environment variable: Closing this, but feel free to reopen if needed. Happy Konging! 🦍 |
Alternatively you can read the variable when the plugin code loads, since that is executed in the master process where variables are still available |
Can I reopen this issue? |
@Asilent you did not specify them as inidcated by @gszr . This is the format: export KONG_NGINX_MAIN_ENV=env_name The name consists of 2 parts;
So you need to specify 2 environment variables for each variable you need
So you need to specify: export KONG_NGINX_MAIN_ENV=HTTP_SSO_ENDPOINT
export HTTP_SSO_ENDPOINT=http://sso.my
export KONG_NGINX_MAIN_ENV=PROXY_SSO_ENDPOINT
export PROXY_SSO_ENDPOINT=http://sso.my Now there is a problem, because the second export "KONG_NGINX_MAIN_ENV=HTTP_SSO_ENDPOINT;env PROXY_SSO_ENDPOINT"
export HTTP_SSO_ENDPOINT=http://sso.my
export PROXY_SSO_ENDPOINT=http://sso.my If you check the generated config file, you'll see that Kong injects this line:
which is a valid nginx config, but now contains both variables. You should now be able to access those variables from your plugin code. |
if I run on k8s, how to write this env KONG_NGINX_MAIN_ENV? |
I use
docker run -e "env_name=xxx" kong:2.4.0-ubuntu
to export env into container. Then I hope to get it by using os.getenv("env_name") in lua plugin. But it doesn't work and responds with nil.The text was updated successfully, but these errors were encountered: