From 46b6e576f80e03f2f0b8678e466f2aab775e8fad Mon Sep 17 00:00:00 2001 From: ma-04 <120931948+ma-04@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:27:30 +0600 Subject: [PATCH 1/2] fix(php,ols): give WP-CLI and Composer a writable home for any uid wp-cli prints "Failed to create directory '/.wp-cli/cache/'" when the php container runs as the host uid (no passwd entry, HOME=/) or when the OLS container is recreated (/var/www is root-owned). - php: create /home/www-data/.wp-cli and .composer world-writable, set HOME=/home/www-data so any compose `user:` finds them. - openlitespeed: create and chown /var/www/.wp-cli/cache and .composer on every start, right after the www-data uid remap. - builder: drop root's /home/www-data/.npm left by the global npm install; with HOME inherited from the php image it was root-owned and broke npm for non-root users. - structure tests: assert HOME, mode 1777 and the entrypoint lines. Refs flywp/flywp-app#455 --- builder/Dockerfile | 2 +- ols-structure-test.yaml | 5 +++++ openlitespeed/entrypoint.sh | 5 +++++ php-structure-test.yaml | 15 +++++++++++++++ php/Dockerfile | 8 ++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/builder/Dockerfile b/builder/Dockerfile index aa3bbf7..705af4a 100644 --- a/builder/Dockerfile +++ b/builder/Dockerfile @@ -26,7 +26,7 @@ USER root RUN apk add --no-cache nodejs npm \ && npm install -g --force yarn pnpm \ && npm cache clean --force \ - && rm -rf /var/cache/apk/* /root/.npm + && rm -rf /var/cache/apk/* /root/.npm /home/www-data/.npm # Plain tool image: drop the inherited php-fpm entrypoint so the image just runs # the command it is given (composer / npm / bash -c '...'). diff --git a/ols-structure-test.yaml b/ols-structure-test.yaml index 0cd25b0..bbca324 100644 --- a/ols-structure-test.yaml +++ b/ols-structure-test.yaml @@ -65,3 +65,8 @@ commandTests: command: "php" args: ["-r", "echo ini_get('session.upload_progress.enabled') ? 'upload_progress=on' : 'upload_progress=off';"] expectedOutput: ["upload_progress=off"] + +fileContentTests: + - name: "Entrypoint creates the WP-CLI and Composer home dirs on every start" + path: "/entrypoint.sh" + expectedContents: ["mkdir -p /var/www/.wp-cli/cache /var/www/.composer", "chown -R www-data:www-data /var/www/.wp-cli /var/www/.composer"] diff --git a/openlitespeed/entrypoint.sh b/openlitespeed/entrypoint.sh index c1d0eae..f61b950 100644 --- a/openlitespeed/entrypoint.sh +++ b/openlitespeed/entrypoint.sh @@ -19,6 +19,11 @@ echo "setting GID to $PGID and UID to $PUID" groupmod -g $PGID www-data usermod -u $PUID www-data +# Home dirs for WP-CLI and Composer, healed on every start (also after a recreate) +# Never fatal: a failure here must not stop OpenLiteSpeed from starting (set -e). +mkdir -p /var/www/.wp-cli/cache /var/www/.composer || echo "Warning: could not create the WP-CLI and Composer home dirs" +chown -R www-data:www-data /var/www/.wp-cli /var/www/.composer || echo "Warning: could not chown the WP-CLI and Composer home dirs" + # Ensure correct permissions chown -R www-data:www-data /var/www/html chown www-data:www-data /var/lib/php/sessions diff --git a/php-structure-test.yaml b/php-structure-test.yaml index 0498b04..3e5b56a 100644 --- a/php-structure-test.yaml +++ b/php-structure-test.yaml @@ -105,11 +105,26 @@ commandTests: args: ["-version"] expectedOutput: ["ImageMagick"] + - name: "HOME is world-writable (compose runs the image as any host uid)" + command: "stat" + args: ["-c", "%a", "/home/www-data"] + expectedOutput: ["1777"] + + - name: "WP-CLI home dir is writable" + command: "sh" + args: ["-c", "test -w \"$HOME/.wp-cli\" && echo wpcli-home-writable"] + expectedOutput: ["wpcli-home-writable"] + - name: "Session upload progress is disabled (CVE-2026-109619)" command: "php" args: ["-r", "echo ini_get('session.upload_progress.enabled') ? 'upload_progress=on' : 'upload_progress=off';"] expectedOutput: ["upload_progress=off"] +metadataTest: + envVars: + - key: "HOME" + value: "/home/www-data" + fileContentTests: - name: "FPM pool locks session upload progress off" path: "/usr/local/etc/php-fpm.d/zz-security.conf" diff --git a/php/Dockerfile b/php/Dockerfile index 6517aa2..3478c55 100644 --- a/php/Dockerfile +++ b/php/Dockerfile @@ -123,6 +123,14 @@ RUN chmod +x /usr/local/bin/docker-entrypoint.sh # Set pager for WP-CLI ENV PAGER=less +# Home for WP-CLI and Composer, usable by any uid. Compose runs this image as the +# host user (user: uid:gid), which has no passwd entry, so HOME would be / and +# WP-CLI could not create its cache or find the bundled packages. +RUN mkdir -p /home/www-data/.wp-cli /home/www-data/.composer \ + && chmod 1777 /home/www-data \ + && chmod -R a+rwX /home/www-data/.wp-cli /home/www-data/.composer +ENV HOME=/home/www-data + # Volume and User settings VOLUME /var/www/html From 82aeb0892d2b5c4ea184c9bc5042da9f01c66e00 Mon Sep 17 00:00:00 2001 From: ma-04 <120931948+ma-04@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:03:21 +0600 Subject: [PATCH 2/2] chore: trim comments --- openlitespeed/entrypoint.sh | 3 +-- php/Dockerfile | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/openlitespeed/entrypoint.sh b/openlitespeed/entrypoint.sh index f61b950..011537f 100644 --- a/openlitespeed/entrypoint.sh +++ b/openlitespeed/entrypoint.sh @@ -19,8 +19,7 @@ echo "setting GID to $PGID and UID to $PUID" groupmod -g $PGID www-data usermod -u $PUID www-data -# Home dirs for WP-CLI and Composer, healed on every start (also after a recreate) -# Never fatal: a failure here must not stop OpenLiteSpeed from starting (set -e). +# Home dirs for WP-CLI and Composer mkdir -p /var/www/.wp-cli/cache /var/www/.composer || echo "Warning: could not create the WP-CLI and Composer home dirs" chown -R www-data:www-data /var/www/.wp-cli /var/www/.composer || echo "Warning: could not chown the WP-CLI and Composer home dirs" diff --git a/php/Dockerfile b/php/Dockerfile index 3478c55..ead5ce5 100644 --- a/php/Dockerfile +++ b/php/Dockerfile @@ -123,9 +123,7 @@ RUN chmod +x /usr/local/bin/docker-entrypoint.sh # Set pager for WP-CLI ENV PAGER=less -# Home for WP-CLI and Composer, usable by any uid. Compose runs this image as the -# host user (user: uid:gid), which has no passwd entry, so HOME would be / and -# WP-CLI could not create its cache or find the bundled packages. +# Writable home for WP-CLI and Composer, for any uid RUN mkdir -p /home/www-data/.wp-cli /home/www-data/.composer \ && chmod 1777 /home/www-data \ && chmod -R a+rwX /home/www-data/.wp-cli /home/www-data/.composer