Skip to content

Conversation

@rcmadhankumar
Copy link
Contributor

@rcmadhankumar rcmadhankumar commented Nov 17, 2025

Made necessary changes to the nginx image so that it can be simply run as non root by passing --user=nginx flag.

bci-pushman pushed a commit that referenced this pull request Nov 17, 2025
bci-pushman pushed a commit that referenced this pull request Nov 17, 2025
bci-pushman pushed a commit that referenced this pull request Nov 17, 2025
@github-actions
Copy link

github-actions bot commented Nov 17, 2025

Created a staging project on OBS for Tumbleweed: home:pushman:BCI:Staging:Tumbleweed:Tumbleweed-3167
Changes pushed to branch Tumbleweed-3167 as commit a989594add9a723babcea6d0897e044df9124a2d
Build succeeded ✅

Build Results

Repository images in home:pushman:BCI:Staging:Tumbleweed:Tumbleweed-3167 for x86_64: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository images in home:pushman:BCI:Staging:Tumbleweed:Tumbleweed-3167 for aarch64: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository containerfile in home:pushman:BCI:Staging:Tumbleweed:Tumbleweed-3167 for x86_64: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Repository containerfile in home:pushman:BCI:Staging:Tumbleweed:Tumbleweed-3167 for aarch64: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Build succeeded ✅

To run BCI-tests against this PR, use the following command:

OS_VERSION=tumbleweed TARGET=custom BASEURL=registry.opensuse.org/home/pushman/bci/staging/tumbleweed/tumbleweed-3167/ tox -- -n auto
The following images can be pulled from the staging project:
  • registry.opensuse.org/home/pushman/bci/staging/tumbleweed/tumbleweed-3167/containerfile/opensuse/nginx:latest

@github-actions
Copy link

github-actions bot commented Nov 17, 2025

Created a staging project on OBS for 7: home:pushman:BCI:Staging:SLE-15-SP7:7-3167
Changes pushed to branch 7-3167 as commit 44f4d53c178aa3dfbd19824f84fe15c5443ec821
Build succeeded ✅

Build Results

Repository images in home:pushman:BCI:Staging:SLE-15-SP7:7-3167 for x86_64: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository images in home:pushman:BCI:Staging:SLE-15-SP7:7-3167 for aarch64: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository images in home:pushman:BCI:Staging:SLE-15-SP7:7-3167 for s390x: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository images in home:pushman:BCI:Staging:SLE-15-SP7:7-3167 for ppc64le: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository containerfile in home:pushman:BCI:Staging:SLE-15-SP7:7-3167 for x86_64: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Repository containerfile in home:pushman:BCI:Staging:SLE-15-SP7:7-3167 for aarch64: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Repository containerfile in home:pushman:BCI:Staging:SLE-15-SP7:7-3167 for s390x: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Repository containerfile in home:pushman:BCI:Staging:SLE-15-SP7:7-3167 for ppc64le: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Build succeeded ✅

To run BCI-tests against this PR, use the following command:

OS_VERSION=15.7 TARGET=custom BASEURL=registry.opensuse.org/home/pushman/bci/staging/sle-15-sp7/7-3167/ tox -- -n auto
The following images can be pulled from the staging project:
  • registry.opensuse.org/home/pushman/bci/staging/sle-15-sp7/7-3167/containerfile/suse/nginx:latest

@github-actions
Copy link

github-actions bot commented Nov 17, 2025

Created a staging project on OBS for 16.0: home:pushman:BCI:Staging:16.0:16.0-3167
Changes pushed to branch 16.0-3167 as commit 9ff50151d9f4e6c4d1ff08095e4284321e2e4fa4
Build succeeded ✅

Build Results

Repository containerkiwi in home:pushman:BCI:Staging:16.0:16.0-3167 for x86_64: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository containerkiwi in home:pushman:BCI:Staging:16.0:16.0-3167 for aarch64: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository containerkiwi in home:pushman:BCI:Staging:16.0:16.0-3167 for s390x: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository containerkiwi in home:pushman:BCI:Staging:16.0:16.0-3167 for ppc64le: current state: published
Build results:

package name status build log
nginx-image ⛔ excluded live log

Repository containerfile in home:pushman:BCI:Staging:16.0:16.0-3167 for x86_64: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Repository containerfile in home:pushman:BCI:Staging:16.0:16.0-3167 for aarch64: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Repository containerfile in home:pushman:BCI:Staging:16.0:16.0-3167 for s390x: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Repository containerfile in home:pushman:BCI:Staging:16.0:16.0-3167 for ppc64le: current state: published
Build results:

package name status build log
nginx-image ✅ succeeded live log

Build succeeded ✅

To run BCI-tests against this PR, use the following command:

OS_VERSION=16.0 TARGET=custom BASEURL=registry.opensuse.org/home/pushman/bci/staging/16.0/16.0-3167/ tox -- -n auto
The following images can be pulled from the staging project:
  • registry.opensuse.org/home/pushman/bci/staging/16.0/16.0-3167/containerfile/suse/nginx:1.27

bci-pushman pushed a commit that referenced this pull request Nov 18, 2025
bci-pushman pushed a commit that referenced this pull request Nov 18, 2025
bci-pushman pushed a commit that referenced this pull request Nov 18, 2025
bci-pushman pushed a commit that referenced this pull request Nov 18, 2025
bci-pushman pushed a commit that referenced this pull request Nov 18, 2025
bci-pushman pushed a commit that referenced this pull request Nov 18, 2025
bci-pushman pushed a commit that referenced this pull request Nov 20, 2025
bci-pushman pushed a commit that referenced this pull request Nov 20, 2025
bci-pushman pushed a commit that referenced this pull request Nov 20, 2025
entrypoint_log "$0: Removed 'user' directive for unprivileged worker."

# Ensure PID path is set to /tmp/nginx.pid
sed -i 's,^#\?\s*pid\s\+.*;$,pid /tmp/nginx.pid;,' /etc/nginx/nginx.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we setting it to /tmp rather than a safe location like /run/nginx or /run ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are starting the nginx container as unprevileged user.
/run directory and /var/run directory is owned by root.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But nothing prevents you from having /run/nginx/nginx.pid , you can create the folder with the nginx user, which it seems you already do with chown -R nginx:nginx /var/run/.

I would also move this to be a default location, not just in case it is a non-root user. Since it would not make any difference if it is owned by nginx anyway.

Copy link
Contributor Author

@rcmadhankumar rcmadhankumar Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pid path is set to /var/run/nginx/nginx.pid

@dirkmueller
Copy link
Member

@rcmadhankumar can you please also include the (adjusted) readme update from #3071 ?

bci-pushman pushed a commit that referenced this pull request Dec 16, 2025
@rcmadhankumar
Copy link
Contributor Author

@rcmadhankumar can you please also include the (adjusted) readme update from #3071 ?

Added relevant readme update.

bci-pushman pushed a commit that referenced this pull request Dec 16, 2025
bci-pushman pushed a commit that referenced this pull request Dec 16, 2025
bci-pushman pushed a commit that referenced this pull request Dec 16, 2025
bci-pushman pushed a commit that referenced this pull request Dec 16, 2025
bci-pushman pushed a commit that referenced this pull request Dec 16, 2025
Copy link
Member

@alexandrevicenzi alexandrevicenzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we seding the user provided file as well (volume mount)? It does not make sense to change is such cases, only if it is the default config we ship, otherwise, we could potentially break the user config.

entrypoint_log "$0: Removed 'user' directive for unprivileged worker."

# Ensure PID path is set to /tmp/nginx.pid
sed -i 's,^#\?\s*pid\s\+.*;$,pid /tmp/nginx.pid;,' /etc/nginx/nginx.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But nothing prevents you from having /run/nginx/nginx.pid , you can create the folder with the nginx user, which it seems you already do with chown -R nginx:nginx /var/run/.

I would also move this to be a default location, not just in case it is a non-root user. Since it would not make any difference if it is owned by nginx anyway.

@rcmadhankumar rcmadhankumar force-pushed the unprevileged-nginx branch 2 times, most recently from 7d44601 to 5c92bea Compare January 23, 2026 09:51
bci-pushman pushed a commit that referenced this pull request Jan 23, 2026
bci-pushman pushed a commit that referenced this pull request Jan 23, 2026
bci-pushman pushed a commit that referenced this pull request Jan 23, 2026
bci-pushman pushed a commit that referenced this pull request Jan 23, 2026
@github-actions
Copy link

github-actions bot commented Jan 23, 2026

Created a staging project on OBS for 16.1: home:pushman:BCI:Staging:16.1:16.1-3167
Changes pushed to branch 16.1-3167 as commit 3854473f232ed96d72ec8298cef0c86ed7da4c3c

bci-pushman pushed a commit that referenced this pull request Jan 23, 2026
bci-pushman pushed a commit that referenced this pull request Jan 23, 2026
bci-pushman pushed a commit that referenced this pull request Jan 23, 2026
entrypoint_log "$0: Running as unprivileged user (UID: $CURRENT_UID). Configuring for unprivileged mode (Port 8080)."

# Remove the 'user' directive
sed -i '/^user/d' /etc/nginx/nginx.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should replace only if the user is root I think, otherwise it can override a user provided in the custom config. However we could also use NGINX_USER and the build-in template engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an unprevileged user i can't use the command user. so, the line is removed from the config file.
Updated the #comment accordingly.

fi

# modify temp paths
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use /tmp for all users, including root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is applicable to both non root and root users.
Just updated the comment and moved the code above if blocks.

entrypoint_log "$0: Removed 'user' directive for unprivileged worker."

# Ensure PID path is set to /var/run/nginx.pid
sed -i 's,^#\?\s*pid\s\+.*;$,pid /var/run/nginx/nginx.pid;,' /etc/nginx/nginx.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use /var for all users, including root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.


# Ensure PID path is set to /var/run/nginx.pid
sed -i 's,^#\?\s*pid\s\+.*;$,pid /var/run/nginx/nginx.pid;,' /etc/nginx/nginx.conf
sed -i 's/listen \(.*\)80;/listen \18080;/' /etc/nginx/conf.d/default.conf 2>/dev/null || \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use the built-in template functions to override the port. However the user would be required to set NGINX_PORT in case a non-root user is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, for a smoother user experience we can keep it as it is! wdyt?
(user can always forward the port 8080 to the port no they wish anyways)

bci-pushman pushed a commit that referenced this pull request Jan 28, 2026
bci-pushman pushed a commit that referenced this pull request Jan 28, 2026
bci-pushman pushed a commit that referenced this pull request Jan 28, 2026
bci-pushman pushed a commit that referenced this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants