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..011537f 100644 --- a/openlitespeed/entrypoint.sh +++ b/openlitespeed/entrypoint.sh @@ -19,6 +19,10 @@ 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 +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..ead5ce5 100644 --- a/php/Dockerfile +++ b/php/Dockerfile @@ -123,6 +123,12 @@ RUN chmod +x /usr/local/bin/docker-entrypoint.sh # Set pager for WP-CLI ENV PAGER=less +# 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 +ENV HOME=/home/www-data + # Volume and User settings VOLUME /var/www/html