forked from nginxinc/nginx-s3-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for unpriviledged non-root image container
Running container images with a non-root user provides additional security against vulnerabilities, and some containers orchestrators such as Openshift enforce this security policy making official regular nginx not compatible out of the box. These changes, based on 'nginxinc/docker-nginx-unprivileged', modify the parent image 'Dockerfile.oss' to allow nginx to execute with a non-root user. Signed-off-by: David Pascual <[email protected]>
- Loading branch information
1 parent
3052946
commit 8f406d2
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This container images makes the necessary modifications in the | ||
# inherited image (which could be OSS NGINX or NGINX Plus) in order | ||
# to allow running NGINX S3 Gateway as a non root user. | ||
# Steps are based on the official unpriviledged container: | ||
# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/Dockerfile-debian.template | ||
FROM nginx-s3-gateway | ||
|
||
# Implement changes required to run NGINX as an unprivileged user | ||
RUN sed -i "/^server {/a \ listen 8080;" /etc/nginx/templates/default.conf.template \ | ||
&& sed -i '/user nginx;/d' /etc/nginx/nginx.conf \ | ||
&& sed -i 's,/var/run/nginx.pid,/tmp/nginx.pid,' /etc/nginx/nginx.conf \ | ||
&& sed -i "/^http {/a \ proxy_temp_path /tmp/proxy_temp;\n client_body_temp_path /tmp/client_temp;\n fastcgi_temp_path /tmp/fastcgi_temp;\n uwsgi_temp_path /tmp/uwsgi_temp;\n scgi_temp_path /tmp/scgi_temp;\n" /etc/nginx/nginx.conf \ | ||
# Nginx user must own the cache and etc directory to write cache and tweak the nginx config | ||
&& chown -R nginx:0 /var/cache/nginx \ | ||
&& chmod -R g+w /var/cache/nginx \ | ||
&& chown -R nginx:0 /etc/nginx \ | ||
&& chmod -R g+w /etc/nginx | ||
|
||
EXPOSE 8080 | ||
|
||
USER nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters