-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(unprivileged): run unprivileged nginx to support arbitrarily assigned user ID #3033
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
Conversation
|
Hi @marius-boden-sva, Thank you for the PR! I'll have some questions on the changes to fully understand what have been changed and why if that's OK. |
char0n
left a comment
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.
Hi @marius-boden-sva, thanks again for the PR. Can you please address questions I had in the code review of this PR. Thanks!
Dockerfile
Outdated
| @@ -1,4 +1,4 @@ | |||
| FROM nginx:1.21.6-alpine | |||
| FROM nginxinc/nginx-unprivileged:1.21.6-alpine | |||
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.
This is an official image, so we should be fine. The image difference from nginx is as follows:
- The default NGINX listen port is now 8080 instead of 80.
- The default NGINX user directive in /etc/nginx/nginx.conf has been removed.
- The default NGINX PID has been moved from /var/run/nginx.pid to /tmp/nginx.pid. *Change _temp_path variables to /tmp/.
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.
@marius-boden-sva I want to address specifically The default NGINX listen port is now 8080 instead of 80. Will this affect the end users; will this be a breaking change for them? I assume not because of https://github.com/swagger-api/swagger-editor/pull/3033/files#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L19 bug just asking to be sure.
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.
The default port has to be changed because ports below 1024 are privileged ports and require root privileges. For running the editor with docker only this results in changing the mapped port only (-p 80:80 will become -p 80:8080). Reminder: need to update the docs about that ;)
For end users running swagger editor e.g. with compose or in kubernetes this will be a breaking change as they need to adapt their ports.
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.
So it is going to be a breaking change. We have a version 5 comming up where we could possibly do this change.
| COPY ./docker-run.sh /usr/share/nginx/ | ||
|
|
||
|
|
||
| RUN chmod +x /usr/share/nginx/docker-run.sh && \ |
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.
Can you maybe elaborate why we're removing this chmod?
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.
we do not need this as the docker-run.sh script is already checked into git with -rwxr-xr-x permissions
| worker_processes 1; | ||
| worker_processes auto; | ||
|
|
||
| error_log /var/log/nginx/error.log notice; |
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.
Can you collaborate why changing the error_log?
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.
this ist just a merge of your your configuration an the one from the nginxinc/nginx-unprivileged:1.21.6-alpine image
| } | ||
|
|
||
| http { | ||
| proxy_temp_path /tmp/proxy_temp; |
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.
I assume these changes are all necessary to be able to run as a non root, unprivileged user, right?
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.
see my answer above. my thought was to change as little as possible and only integrate what's necessary to run swagger editor
| uwsgi_temp_path /tmp/uwsgi_temp; | ||
| scgi_temp_path /tmp/scgi_temp; | ||
|
|
||
| include /etc/nginx/conf.d/*.conf; |
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.
Why we're including the default config here?
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.
see my answer above
|
@marius-boden-sva would you mind sending this PR against Thanks! |
|
Superseded by #3705 |
Use unprivileged nginx to support arbitrarily assigned user ID to be able to run the image e.g. on Red Hat Openshift
Description
The dockerfile uses the
nginxinc/nginx-unprivilegedimage instead of the standardnginximage.Moreover the
nginx.conffile was extended for some configuration to locate nginx runtime data in the/tmpdirectory.This enables the container to run as a non-root user which is an improvement to the container security and enables running the container on distributions such as OpenShift by default.
Motivation and Context
The change is necessary as the previous version required nginx to run as root to be able to read/write so several default paths.
Fixes #2931
How Has This Been Tested?
Dependencies:
npm ciBuild:
npm buildDocker Build:
docker build -t swagger-editor-unprivileged .Docker Run:
docker run -p 8080:8080 -u 100000 swagger-editor-unprivilegedVisit in browser: http://localhost:8080
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests