Skip to content

Commit 896a084

Browse files
author
SUSE Update Bot
committed
Test build for #3167
1 parent 7e9a46b commit 896a084

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

nginx-image/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ COPY --from=target / /target
2525

2626
RUN set -euo pipefail; \
2727
export PERMCTL_ALLOW_INSECURE_MODE_IF_NO_PROC=1; \
28-
zypper -n --installroot /target --gpg-auto-import-keys install --no-recommends curl gawk nginx findutils envsubst
28+
zypper -n --installroot /target --gpg-auto-import-keys install --no-recommends curl gawk nginx findutils envsubst sed grep
2929
# sanity check that the version from the tag is equal to the version of nginx that we expect
3030
RUN set -euo pipefail; \
3131
[ "$(rpm --root /target -q --qf '%{version}' nginx | \
@@ -69,5 +69,5 @@ COPY [1-3]0-*.sh /docker-entrypoint.d/
6969
COPY docker-entrypoint.sh /usr/local/bin
7070
COPY index.html /srv/www/htdocs/
7171
RUN set -euo pipefail; chmod +x /docker-entrypoint.d/*.sh /usr/local/bin/docker-entrypoint.sh
72-
RUN set -euo pipefail; install -d -o nginx -g nginx -m 750 /var/log/nginx; ln -sf /dev/stdout /var/log/nginx/access.log; ln -sf /dev/stderr /var/log/nginx/error.log
72+
RUN set -euo pipefail; install -d -o nginx -g nginx -m 750 /var/log/nginx; install -d /var/cache/nginx /var/run/nginx; ln -sf /dev/stdout /var/log/nginx/access.log; ln -sf /dev/stderr /var/log/nginx/error.log; chown -R nginx:nginx /var/cache/nginx; chown -R nginx:nginx /etc/nginx; chown -R nginx:nginx /var/run/nginx; install -d -o nginx -g nginx /tmp/client_temp /tmp/proxy_temp /tmp/fastcgi_temp /tmp/uwsgi_temp /tmp/scgi_temp; chown -R nginx:nginx /tmp; chmod -R g+w /var/cache/nginx /var/log/nginx /etc/nginx /var/run/nginx /tmp
7373
STOPSIGNAL SIGQUIT

nginx-image/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ The template above is then rendered to `/etc/nginx/conf.d/default.conf` as follo
4141
```nginx
4242
listen 80;
4343
```
44+
## Running nginx as a non-root user
45+
To run the image as a less privileged user using the `nginx` user, do the following:
46+
```ShellSession
47+
$ podman run -it --user nginx --rm -p 8080:8080 -v /path/to/html/:/srv/www/htdocs/:Z -v $PWD/nginx.conf:/etc/nginx/nginx.conf:Z registry.opensuse.org/opensuse/nginx:1.29
48+
```
49+
**Note:** When running as the `nginx` user the default port is 8080.
4450

4551
## Environment variables
4652

nginx-image/docker-entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,23 @@ if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
4444
fi
4545
fi
4646

47+
CURRENT_UID=$(id -u)
48+
if [ "$CURRENT_UID" -gt "0" ]; then
49+
# Running as Unprivileged User
50+
entrypoint_log "$0: Running as unprivileged user (UID: $CURRENT_UID). Configuring for unprivileged mode (Port 8080)."
51+
52+
# Remove the 'user' directive
53+
sed -i '/^user/d' /etc/nginx/nginx.conf
54+
entrypoint_log "$0: Removed 'user' directive for unprivileged worker."
55+
56+
# Ensure PID path is set to /var/run/nginx.pid
57+
sed -i 's,^#\?\s*pid\s\+.*;$,pid /var/run/nginx/nginx.pid;,' /etc/nginx/nginx.conf
58+
sed -i 's/listen \(.*\)80;/listen \18080;/' /etc/nginx/conf.d/default.conf 2>/dev/null || \
59+
sed -i 's/listen \(.*\)80;/listen \18080;/' /etc/nginx/nginx.conf 2>/dev/null || true
60+
entrypoint_log "$0: Listening on port 8080."
61+
fi
62+
63+
# modify temp paths
64+
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
65+
4766
exec "$@"

0 commit comments

Comments
 (0)