Skip to content

Commit

Permalink
Merge pull request #97 from macbre/docker/run-as-non-root
Browse files Browse the repository at this point in the history
 Run as non root by default
  • Loading branch information
macbre authored Dec 19, 2022
2 parents 8336e81 + 3bb43e8 commit d9abd74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ jobs:
run: |
docker images | head -n3
- name: Are we running as non-root?
run: |
docker run --rm -t macbre/nginx whoami | grep nginx
- name: Run nginx -V and njs -v
run: |
docker run -t macbre/nginx nginx -V | sed 's/\-\-/\n\t--/g' | tee
docker run --rm -t macbre/nginx nginx -V | sed 's/\-\-/\n\t--/g' | tee
echo "njs v$(docker run -t macbre/nginx njs -v)"
- name: Serve a static asset
Expand Down
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ COPY --from=base /usr/sbin/njs /usr/sbin/njs

# hadolint ignore=SC2046
RUN \
addgroup -S nginx \
&& adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx \
addgroup --gid 101 -S nginx \
&& adduser --uid 100 -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx \
&& apk add --no-cache --virtual .nginx-rundeps tzdata $(cat /tmp/runDeps.txt) \
&& rm /tmp/runDeps.txt \
&& ln -s /usr/lib/nginx/modules /etc/nginx/modules \
Expand All @@ -241,8 +241,13 @@ RUN njs -v
# test the configuration
RUN nginx -V; nginx -t

EXPOSE 80 443
EXPOSE 8080 8443

STOPSIGNAL SIGTERM

# prepare to switching to non-root - update file permissions
RUN chown --verbose nginx:nginx \
/var/run/nginx.pid

USER nginx
CMD ["nginx", "-g", "daemon off;"]
2 changes: 0 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# http://nginx.org/en/docs/ngx_core_module.html#load_module
include /etc/nginx/main.d/*.conf;


user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
Expand Down

0 comments on commit d9abd74

Please sign in to comment.