Skip to content

Commit d9abd74

Browse files
authored
Merge pull request #97 from macbre/docker/run-as-non-root
Run as non root by default
2 parents 8336e81 + 3bb43e8 commit d9abd74

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.github/workflows/dockerimage.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ jobs:
5050
run: |
5151
docker images | head -n3
5252
53+
- name: Are we running as non-root?
54+
run: |
55+
docker run --rm -t macbre/nginx whoami | grep nginx
56+
5357
- name: Run nginx -V and njs -v
5458
run: |
55-
docker run -t macbre/nginx nginx -V | sed 's/\-\-/\n\t--/g' | tee
59+
docker run --rm -t macbre/nginx nginx -V | sed 's/\-\-/\n\t--/g' | tee
5660
echo "njs v$(docker run -t macbre/nginx njs -v)"
5761
5862
- name: Serve a static asset

Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ COPY --from=base /usr/sbin/njs /usr/sbin/njs
218218

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

244-
EXPOSE 80 443
244+
EXPOSE 8080 8443
245245

246246
STOPSIGNAL SIGTERM
247247

248+
# prepare to switching to non-root - update file permissions
249+
RUN chown --verbose nginx:nginx \
250+
/var/run/nginx.pid
251+
252+
USER nginx
248253
CMD ["nginx", "-g", "daemon off;"]

nginx.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# http://nginx.org/en/docs/ngx_core_module.html#load_module
66
include /etc/nginx/main.d/*.conf;
77

8-
9-
user nginx;
108
worker_processes 1;
119

1210
error_log /var/log/nginx/error.log warn;

0 commit comments

Comments
 (0)