Skip to content

Commit 445f59f

Browse files
committed
fix: run the web image unprivileged
SonarCloud raised docker:S6471 on the new stage: nginx:alpine starts its master process as root. The php-fpm stage next to it deliberately does not, so this was an inconsistency introduced by the same commit that added the stage, not a pre-existing trade-off worth accepting. nginxinc/nginx-unprivileged runs as uid 101 throughout. A port below 1024 needs a capability it does not have, so the server block, EXPOSE, the healthcheck, the compose port mapping and the README example move to 8080. The pid file already lived in /tmp, so nothing else had to change. Verified on the built image: id reports uid=101(nginx), every nginx process runs as nginx, and the two containers together still answer 200 with the real login form while nginx serves /favicon.ico as image/x-icon. Signed-off-by: Sebastian Mendel <github@sebastianmendel.de>
1 parent 76aa071 commit 445f59f

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ CMD ["php-fpm", "--nodaemonize"]
190190
# uses, so the static assets and the PHP that renders around them always
191191
# come from one build. That is also why the two images MUST be deployed at
192192
# the same tag: mixing them is mixing two phpMyAdmin versions.
193-
FROM nginx:1.29-alpine AS web
193+
# The unprivileged variant rather than nginx:alpine: the stock image runs
194+
# its master process as root, which the php-fpm stage above deliberately
195+
# does not, and SonarCloud flags it as docker:S6471. This one runs as uid
196+
# 101 throughout, which is why the server block listens on 8080.
197+
FROM nginxinc/nginx-unprivileged:1.29-alpine AS web
194198

195199
ARG PMA_VERSION=5.2.3
196200
ARG BUILD_DATE
@@ -217,7 +221,7 @@ COPY config/nginx/snippets/ /etc/nginx/snippets/
217221
# rather than a build-time decision.
218222
ENV PMA_FPM_UPSTREAM=app:9000
219223

220-
EXPOSE 80
224+
EXPOSE 8080
221225

222226
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
223-
CMD ["/bin/sh", "-c", "wget -q -O /dev/null http://127.0.0.1/ || exit 1"]
227+
CMD ["/bin/sh", "-c", "wget -q -O /dev/null http://127.0.0.1:8080/ || exit 1"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PMA_HOST=your-db-host docker compose up -d app-assets app web
5050
| Image | What it is |
5151
|---|---|
5252
| `ghcr.io/netresearch/phpmyadmin-php-fpm` | php-fpm on 9000, serves no HTTP |
53-
| `ghcr.io/netresearch/phpmyadmin-nginx` | nginx on 80 with the configuration and the document root baked in |
53+
| `ghcr.io/netresearch/phpmyadmin-nginx` | nginx on 8080 with the configuration and the document root baked in, running as an unprivileged user |
5454

5555
**Deploy both at the same tag.** They share the document root, which is copied
5656
from one build stage into both, so mixing tags means running two phpMyAdmin
@@ -70,7 +70,7 @@ services:
7070
environment:
7171
PMA_FPM_UPSTREAM: pma-fpm:9000
7272
ports:
73-
- "8080:80"
73+
- "8080:8080"
7474
```
7575
7676
## Using only the php-fpm image

compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ services:
9494
environment:
9595
PMA_FPM_UPSTREAM: ${PMA_FPM_UPSTREAM:-app:9000}
9696
ports:
97-
- "${PMA_HTTP_PORT:-8080}:80"
97+
- "${PMA_HTTP_PORT:-8080}:8080"
9898
volumes:
9999
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
100100
- ./config/nginx/templates:/etc/nginx/templates:ro
101101
- ./config/nginx/snippets:/etc/nginx/snippets:ro
102102
- pma-html:/var/www/html:ro
103103
healthcheck:
104-
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1/"]
104+
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/"]
105105
interval: 30s
106106
timeout: 5s
107107
retries: 3

config/nginx/templates/default.conf.template

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
# passed through envsubst, which only replaces variables that are actually set
77
# in the environment — nginx's own $uri, $document_root and friends survive.
88
server {
9-
listen 80;
10-
listen [::]:80;
9+
# 8080, not 80: the image runs as an unprivileged user and a
10+
# port below 1024 needs a capability it deliberately does not have.
11+
listen 8080;
12+
listen [::]:8080;
1113
server_name _;
1214

1315
root /var/www/html;

0 commit comments

Comments
 (0)