-
Notifications
You must be signed in to change notification settings - Fork 198
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
Support for env var replacement #19
Conversation
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
@wtrocki Git is complaining about missing newline at the end of some modified files. Please add it. [test] |
Tests are failing due to missing
Also tests fail with:
To note: CI is configured, that only members of sclorg/ github organization can trigger tests. |
1842f38
to
1849d78
Compare
Everyone can run same tests as in CI by [test] |
@omron93 - Thanks for help on this one. I would try to fix and also extend tests now. |
@wtrocki You are welcomed. Thanks for this PR. |
@omron93 - Tests are passing now on my local machine. |
[test] |
@@ -9,9 +9,17 @@ if [ -d ./nginx-cfg ]; then | |||
echo "---> Copying nginx configuration files..." | |||
if [ "$(ls -A ./nginx-cfg/*.conf)" ]; then | |||
cp -v ./nginx-cfg/*.conf "${NGINX_CONFIGURATION_PATH}" | |||
chmod -Rf 777 ${NGINX_CONFIGURATION_PATH} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wtrocki Is 777 necessary? It is very open...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to change configuration in running container we would need to have write access to config for default user. Files are created by root user, so we can:
- Change file owner to default (risky as container can use different user)
- Make files writable by others by setting
666
👿 mask on file
Making files writable do not impose security risk. If attacker would get access to the container he can switch configuration to any file he wants and then send HUP signal to the nginx process to reload it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Change file owner to default (risky as container can use different user)
- Make files writable by others by setting 666 👿 mask on file
I am not sure, but I think GID remains the same. So some other images g+rw
is used to allow running with arbitrary user.
Anyway, it LGTM. But I am not experienced with nginx, so I would be happy someone else take a look to it too. |
Can one of the admins verify this patch? |
ping @notroj |
Any update on this? This feature will be really useful for this image. |
Sorry, that it took longer than I'd wish. We've worked on a similar feature in case of databases containers and mongodb was the first that included it: sclorg/mongodb-container#239 By that we also wanted to set the same approaches that will work fine when running the container by The main point is that the image has one or more known trigger points -- in this case it would be the point in "before launching nginx proxy", as you wrote (let's call it simply So, depending on whether the functionality is general enough, your Anyway, the bottom line is that I'd like to see this implemented similarly as in case of the mongodb container above.. |
IMO the approach above should also fix #20. |
@hhorak Great idea! Especially that you can use the same patterns for most of the scl images. Feel free to ping me on other containers PR for reviews. |
Motivation
Add init script support. This script would be executed before launching nginx proxy and would allow to modify nginx configuration. Script can be used to replace environment variables or setup additional elements in image. Some examples and test provided.
Notes
Nginx configuration can contain variables that start with dollar which makes difficult to replace all placeholders. Using
envreplace
is still possible but we would need to specify list of the environment variables as input. Alternative solution would be to use sed to replace some placeholders but this would reduce visibility and IMHO make this more complex than it should be.I wanted to make this solution generic enough to be used for various use cases. One of the most common use cases for this container is to use it as proxy. To proxy to backends using dns names , dns setup is required. Unfortunately nginx using internal dns resolver and cannot relay on resolv.conf file.
In example for init script I have added solution for this problem - reading values from resolv.conf and injecting them into script as environment variables. It may be reasonable to include resolver directive into global script.
Implementation for #18