From 103bfe1e59b09916daf34c6ba7bdc4ad0db17f99 Mon Sep 17 00:00:00 2001 From: Michael Aguiar Date: Wed, 25 Nov 2026 15:13:31 -0700 Subject: [PATCH 1/3] Add WORDPRESS_VCS_CHECKOUT to keep WordPress auto-updates off WordPress skips background auto-updates when it finds a .git (or .svn, .hg, .bzr) at or above the code it would update. A deploy that keeps the repository outside the served folder loses that, and WordPress starts rewriting git-deployed code. The WordPress images (frankenphp 8.2-8.5, so wordpress-dev too, and php/8.4/cli/Dockerfile.wordpress) now set auto_prepend_file to a root-owned file in /usr/local/share/php-prepend. When WORDPRESS_VCS_CHECKOUT is exactly "1" it pre-seeds the automatic_updates_is_vcs_checkout filter with __return_true; otherwise it does nothing. The build fails if the base already sets an auto_prepend_file, and docker-configure adds the prepend directory to PHP_OPEN_BASEDIR when that is set, since PHP refuses every request whose prepend file is outside open_basedir. --- README.md | 10 ++++++ php/8.2/frankenphp/Dockerfile.wordpress | 43 +++++++++++++++++++++++++ php/8.2/frankenphp/docker-configure | 9 +++++- php/8.3/frankenphp/Dockerfile.wordpress | 43 +++++++++++++++++++++++++ php/8.3/frankenphp/docker-configure | 9 +++++- php/8.4/cli/Dockerfile.wordpress | 40 +++++++++++++++++++++++ php/8.4/frankenphp/Dockerfile.wordpress | 43 +++++++++++++++++++++++++ php/8.4/frankenphp/docker-configure | 9 +++++- php/8.5/frankenphp/Dockerfile.wordpress | 43 +++++++++++++++++++++++++ php/8.5/frankenphp/docker-configure | 9 +++++- 10 files changed, 254 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index be1bd80..13ec159 100644 --- a/README.md +++ b/README.md @@ -74,3 +74,13 @@ The `frankenphp:wordpress` variant renders a Caddy hardening snippet at containe All of the above are overridable via environment variables if a site needs different values. The `wordpress` variant also ships defaults for the [static asset caching](#static-asset-caching) snippet covering both the Bedrock (`/app/...`, `/wp/...`) and stock (`/wp-content/...`, `/wp-includes/...`) layouts, including cache-plugin output and Avada's compiled `fusion-styles` / `fusion-scripts` directories. + +### Auto-updates on sites deployed from git + +WordPress skips its background auto-updates (core, plugins, themes and translations) when it finds a `.git`, `.svn`, `.hg` or `.bzr` directory at or above the code it would update, so code deployed from a repository isn't rewritten underneath it. A deploy that keeps the repository outside the folder mounted at `/app` loses that, and WordPress starts updating itself. Set `WORDPRESS_VCS_CHECKOUT=1` to keep it off: + +```sh +docker run -e WORDPRESS_VCS_CHECKOUT=1 ghcr.io/aliasproject/php:8.4-frankenphp-wordpress +``` + +It is unset by default, and only the exact value `1` turns it on. The `wordpress` and `wordpress-dev` variants, and an image built from `php/8.4/cli/Dockerfile.wordpress` (so WP-CLI cron runs behave the same), set PHP's `auto_prepend_file` to `/usr/local/share/php-prepend/wordpress-vcs-checkout.php`, a root-owned file that adds `__return_true` to WordPress's `automatic_updates_is_vcs_checkout` filter before WordPress loads (WordPress 4.7 or newer). With the variable unset the file does nothing, and it never affects non-WordPress code. Manual updates from wp-admin or `wp core update` still work. A derived image that sets its own `auto_prepend_file` replaces this one. When `PHP_OPEN_BASEDIR` is set, the frankenphp images add `/usr/local/share/php-prepend/` to it, because PHP refuses every request whose prepend file it can't open. diff --git a/php/8.2/frankenphp/Dockerfile.wordpress b/php/8.2/frankenphp/Dockerfile.wordpress index aeecaab..58cdd57 100644 --- a/php/8.2/frankenphp/Dockerfile.wordpress +++ b/php/8.2/frankenphp/Dockerfile.wordpress @@ -101,4 +101,47 @@ ENV PHP_OPCACHE_MEMORY=256 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \ PHP_OPCACHE_REVALIDATE_FREQ=60 +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# auto_prepend_file runs before every PHP script in the image, WordPress or +# not, so the file only touches $GLOBALS['wp_filter'] and only when the +# variable is "1". It lives outside /app and conf.d, root-owned and read-only +# to appuser. Every frankenphp Dockerfile.wordpress and +# php/8.4/cli/Dockerfile.wordpress carry this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the base ever sets +# one, rather than silently replacing it (chain to it from the file above if +# that happens), and fail if PHP doesn't pick up the new setting. +RUN for bin in "frankenphp php-cli" php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: base image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ + for bin in "frankenphp php-cli" php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ + { echo "ERROR: auto_prepend_file not picked up ($bin)" >&2; exit 1; }; \ + done + USER appuser diff --git a/php/8.2/frankenphp/docker-configure b/php/8.2/frankenphp/docker-configure index 407d255..9ed3725 100644 --- a/php/8.2/frankenphp/docker-configure +++ b/php/8.2/frankenphp/docker-configure @@ -44,7 +44,14 @@ CADDY_SITE_D=/config/caddy/site.d fi if [ -n "${PHP_OPEN_BASEDIR}" ]; then - echo "open_basedir = ${PHP_OPEN_BASEDIR}" + # Dockerfile.wordpress keeps an auto_prepend_file here. PHP refuses + # to run any script whose prepend file is outside open_basedir, so + # let it in. The directory is root-owned and holds only that file. + if [ -d /usr/local/share/php-prepend ]; then + echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" + else + echo "open_basedir = ${PHP_OPEN_BASEDIR}" + fi fi } > "${PHP_INI_DIR}/conf.d/app.ini" diff --git a/php/8.3/frankenphp/Dockerfile.wordpress b/php/8.3/frankenphp/Dockerfile.wordpress index e812ed6..ab4a7b0 100644 --- a/php/8.3/frankenphp/Dockerfile.wordpress +++ b/php/8.3/frankenphp/Dockerfile.wordpress @@ -101,4 +101,47 @@ ENV PHP_OPCACHE_MEMORY=256 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \ PHP_OPCACHE_REVALIDATE_FREQ=60 +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# auto_prepend_file runs before every PHP script in the image, WordPress or +# not, so the file only touches $GLOBALS['wp_filter'] and only when the +# variable is "1". It lives outside /app and conf.d, root-owned and read-only +# to appuser. Every frankenphp Dockerfile.wordpress and +# php/8.4/cli/Dockerfile.wordpress carry this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the base ever sets +# one, rather than silently replacing it (chain to it from the file above if +# that happens), and fail if PHP doesn't pick up the new setting. +RUN for bin in "frankenphp php-cli" php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: base image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ + for bin in "frankenphp php-cli" php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ + { echo "ERROR: auto_prepend_file not picked up ($bin)" >&2; exit 1; }; \ + done + USER appuser diff --git a/php/8.3/frankenphp/docker-configure b/php/8.3/frankenphp/docker-configure index 407d255..9ed3725 100644 --- a/php/8.3/frankenphp/docker-configure +++ b/php/8.3/frankenphp/docker-configure @@ -44,7 +44,14 @@ CADDY_SITE_D=/config/caddy/site.d fi if [ -n "${PHP_OPEN_BASEDIR}" ]; then - echo "open_basedir = ${PHP_OPEN_BASEDIR}" + # Dockerfile.wordpress keeps an auto_prepend_file here. PHP refuses + # to run any script whose prepend file is outside open_basedir, so + # let it in. The directory is root-owned and holds only that file. + if [ -d /usr/local/share/php-prepend ]; then + echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" + else + echo "open_basedir = ${PHP_OPEN_BASEDIR}" + fi fi } > "${PHP_INI_DIR}/conf.d/app.ini" diff --git a/php/8.4/cli/Dockerfile.wordpress b/php/8.4/cli/Dockerfile.wordpress index 2287bf7..35404ce 100644 --- a/php/8.4/cli/Dockerfile.wordpress +++ b/php/8.4/cli/Dockerfile.wordpress @@ -34,4 +34,44 @@ RUN install-php-extensions \ imagick \ soap +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# auto_prepend_file runs before every PHP script in the image, WordPress or +# not, so the file only touches $GLOBALS['wp_filter'] and only when the +# variable is "1". WP-CLI runs (cron among them) can trigger auto-updates +# too, so the CLI image needs it as well as the web one. It lives outside +# /app and conf.d, root-owned and read-only to appuser. Every frankenphp +# Dockerfile.wordpress carries this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the base ever sets +# one, rather than silently replacing it (chain to it from the file above if +# that happens), and fail if PHP doesn't pick up the new setting. +RUN php -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: base image already sets auto_prepend_file" >&2; exit 1; } && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ + test "$(php -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ + { echo "ERROR: auto_prepend_file not picked up" >&2; exit 1; } + USER appuser diff --git a/php/8.4/frankenphp/Dockerfile.wordpress b/php/8.4/frankenphp/Dockerfile.wordpress index 3026031..55b0c0a 100644 --- a/php/8.4/frankenphp/Dockerfile.wordpress +++ b/php/8.4/frankenphp/Dockerfile.wordpress @@ -101,4 +101,47 @@ ENV PHP_OPCACHE_MEMORY=256 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \ PHP_OPCACHE_REVALIDATE_FREQ=60 +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# auto_prepend_file runs before every PHP script in the image, WordPress or +# not, so the file only touches $GLOBALS['wp_filter'] and only when the +# variable is "1". It lives outside /app and conf.d, root-owned and read-only +# to appuser. Every frankenphp Dockerfile.wordpress and +# php/8.4/cli/Dockerfile.wordpress carry this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the base ever sets +# one, rather than silently replacing it (chain to it from the file above if +# that happens), and fail if PHP doesn't pick up the new setting. +RUN for bin in "frankenphp php-cli" php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: base image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ + for bin in "frankenphp php-cli" php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ + { echo "ERROR: auto_prepend_file not picked up ($bin)" >&2; exit 1; }; \ + done + USER appuser diff --git a/php/8.4/frankenphp/docker-configure b/php/8.4/frankenphp/docker-configure index 407d255..9ed3725 100644 --- a/php/8.4/frankenphp/docker-configure +++ b/php/8.4/frankenphp/docker-configure @@ -44,7 +44,14 @@ CADDY_SITE_D=/config/caddy/site.d fi if [ -n "${PHP_OPEN_BASEDIR}" ]; then - echo "open_basedir = ${PHP_OPEN_BASEDIR}" + # Dockerfile.wordpress keeps an auto_prepend_file here. PHP refuses + # to run any script whose prepend file is outside open_basedir, so + # let it in. The directory is root-owned and holds only that file. + if [ -d /usr/local/share/php-prepend ]; then + echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" + else + echo "open_basedir = ${PHP_OPEN_BASEDIR}" + fi fi } > "${PHP_INI_DIR}/conf.d/app.ini" diff --git a/php/8.5/frankenphp/Dockerfile.wordpress b/php/8.5/frankenphp/Dockerfile.wordpress index 320cb5a..e5b4a6b 100644 --- a/php/8.5/frankenphp/Dockerfile.wordpress +++ b/php/8.5/frankenphp/Dockerfile.wordpress @@ -101,4 +101,47 @@ ENV PHP_OPCACHE_MEMORY=256 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \ PHP_OPCACHE_REVALIDATE_FREQ=60 +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# auto_prepend_file runs before every PHP script in the image, WordPress or +# not, so the file only touches $GLOBALS['wp_filter'] and only when the +# variable is "1". It lives outside /app and conf.d, root-owned and read-only +# to appuser. Every frankenphp Dockerfile.wordpress and +# php/8.4/cli/Dockerfile.wordpress carry this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the base ever sets +# one, rather than silently replacing it (chain to it from the file above if +# that happens), and fail if PHP doesn't pick up the new setting. +RUN for bin in "frankenphp php-cli" php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: base image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ + for bin in "frankenphp php-cli" php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ + { echo "ERROR: auto_prepend_file not picked up ($bin)" >&2; exit 1; }; \ + done + USER appuser diff --git a/php/8.5/frankenphp/docker-configure b/php/8.5/frankenphp/docker-configure index 407d255..9ed3725 100644 --- a/php/8.5/frankenphp/docker-configure +++ b/php/8.5/frankenphp/docker-configure @@ -44,7 +44,14 @@ CADDY_SITE_D=/config/caddy/site.d fi if [ -n "${PHP_OPEN_BASEDIR}" ]; then - echo "open_basedir = ${PHP_OPEN_BASEDIR}" + # Dockerfile.wordpress keeps an auto_prepend_file here. PHP refuses + # to run any script whose prepend file is outside open_basedir, so + # let it in. The directory is root-owned and holds only that file. + if [ -d /usr/local/share/php-prepend ]; then + echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" + else + echo "open_basedir = ${PHP_OPEN_BASEDIR}" + fi fi } > "${PHP_INI_DIR}/conf.d/app.ini" From 7dd6c2cfc6f41421cb72b6289787dd517f431fc2 Mon Sep 17 00:00:00 2001 From: Michael Aguiar Date: Wed, 25 Nov 2026 15:27:19 -0700 Subject: [PATCH 2/3] Move WORDPRESS_VCS_CHECKOUT into the base frankenphp images The prepend file, its root-owned directory and the ini now live in the base php/8.{2,3,4,5}/frankenphp/Dockerfile, so a WordPress site on the base image is covered too, and dev, wordpress and wordpress-dev inherit them. The duplicate blocks in each Dockerfile.wordpress are gone. - The prepend file checks function_exists('getenv') first, so a site with getenv in PHP_DISABLE_FUNCTIONS no longer fatals on every request (the variable just has no effect there). - The ini is now conf.d/00-wordpress-vcs-checkout.ini, so a later conf.d file that sets its own auto_prepend_file (a Wordfence wordfence.ini, say) wins instead of being silently overridden. - docker-configure always adds /usr/local/share/php-prepend/ to PHP_OPEN_BASEDIR, since every frankenphp image now has it. - The build runs a real script with WORDPRESS_VCS_CHECKOUT=1, =true and unset, and fails unless only "1" seeds the filter. - smoke-test.sh checks the variable unset and set, set with PHP_OPEN_BASEDIR, and set with getenv disabled (frankenphp variants), and both ways on a CLI image that carries the file. - php/8.4/cli/Dockerfile.wordpress gets the same fixes. - README: says which images and runs are covered (web requests and WP-Cron run by them; WP-CLI needs the CLI image CI doesn't publish), and what the file does to non-WordPress code. --- .github/scripts/smoke-test.sh | 102 ++++++++++++++++++------ README.md | 4 +- php/8.2/frankenphp/Dockerfile | 59 ++++++++++++++ php/8.2/frankenphp/Dockerfile.wordpress | 43 ---------- php/8.2/frankenphp/docker-configure | 13 ++- php/8.3/frankenphp/Dockerfile | 59 ++++++++++++++ php/8.3/frankenphp/Dockerfile.wordpress | 43 ---------- php/8.3/frankenphp/docker-configure | 13 ++- php/8.4/cli/Dockerfile.wordpress | 44 ++++++---- php/8.4/frankenphp/Dockerfile | 59 ++++++++++++++ php/8.4/frankenphp/Dockerfile.wordpress | 43 ---------- php/8.4/frankenphp/docker-configure | 13 ++- php/8.5/frankenphp/Dockerfile | 59 ++++++++++++++ php/8.5/frankenphp/Dockerfile.wordpress | 43 ---------- php/8.5/frankenphp/docker-configure | 13 ++- 15 files changed, 367 insertions(+), 243 deletions(-) diff --git a/.github/scripts/smoke-test.sh b/.github/scripts/smoke-test.sh index 53ed2f4..9e8b0ed 100755 --- a/.github/scripts/smoke-test.sh +++ b/.github/scripts/smoke-test.sh @@ -54,14 +54,28 @@ if [ "$variant" = cli ]; then check_php "$version" "$loaded" uid=$(docker run --rm "$image" id -u) || fail "id did not run" [ "$uid" != 0 ] || fail "runs as root" + # Only cli/Dockerfile.wordpress carries the WORDPRESS_VCS_CHECKOUT prepend + # file (see the frankenphp checks below). + if docker run --rm "$image" test -f /usr/local/share/php-prepend/wordpress-vcs-checkout.php; then + seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' + check='echo " /tmp/vcs.php && php /tmp/vcs.php' + out=$(docker run --rm "$image" sh -c "$check") || fail "vcs check did not run" + [ "$out" = none ] || fail "WORDPRESS_VCS_CHECKOUT unset, but the filter was seeded: $out" + out=$(docker run --rm -e WORDPRESS_VCS_CHECKOUT=1 "$image" sh -c "$check") || fail "vcs check did not run" + [ "$out" = "$seeded" ] || fail "WORDPRESS_VCS_CHECKOUT=1 did not seed the filter: $out" + fi echo "ok: $image (PHP $version, uid $uid)" exit 0 fi fixture=$(mktemp -d) name="smoke-$$" +containers=() cleanup() { - docker rm -f "$name" >/dev/null 2>&1 || true + local c + for c in "${containers[@]}"; do + docker rm -f "$c" >/dev/null 2>&1 || true + done rm -rf "$fixture" } trap cleanup EXIT @@ -80,31 +94,44 @@ echo "VERSION=", PHP_VERSION, "\n"; echo "SAPI=", php_sapi_name(), "\n"; echo "EXTENSIONS=", implode(' ', get_loaded_extensions()), "\n"; PHP +# What the WORDPRESS_VCS_CHECKOUT prepend file did to this request. +cat > "$fixture/public/vcs.php" <<'PHP' +/dev/null - -health=starting -for _ in $(seq 1 60); do - state=$(docker inspect -f '{{.State.Status}}' "$name") - if [ "$state" != running ]; then - docker logs "$name" >&2 || true - fail "container is '$state', not running" +# Boots the image as container $1 (extra docker run arguments after it) with +# the fixture at /app, waits for it to be healthy and sets $port. +boot() { + local cname=$1 state health=starting + shift + containers+=("$cname") + # Short health interval: the image's own HEALTHCHECK (30s) would make the + # wait below much longer than it needs to be. + docker run -d --name "$cname" -p 127.0.0.1::80 -v "$fixture:/app:ro" \ + --health-interval 2s --health-timeout 5s --health-retries 5 --health-start-period 30s \ + "$@" "$image" >/dev/null + + for _ in $(seq 1 60); do + state=$(docker inspect -f '{{.State.Status}}' "$cname") + if [ "$state" != running ]; then + docker logs "$cname" >&2 || true + fail "container is '$state', not running (${*:-no extra arguments})" + fi + health=$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$cname") + [ "$health" = healthy ] && break + sleep 2 + done + if [ "$health" != healthy ]; then + docker logs "$cname" >&2 || true + fail "not healthy after 120s (health: $health; ${*:-no extra arguments})" fi - health=$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$name") - [ "$health" = healthy ] && break - sleep 2 -done -if [ "$health" != healthy ]; then - docker logs "$name" >&2 || true - fail "not healthy after 120s (health: $health)" -fi -port=$(docker port "$name" 80/tcp | head -n1 | sed 's/.*://') + port=$(docker port "$cname" 80/tcp | head -n1 | sed 's/.*://') +} + +boot "$name" body=$(curl -fsS --max-time 10 "http://127.0.0.1:$port/") \ || fail "GET / did not return 2xx" @@ -144,4 +171,33 @@ docker exec "$name" test -s /usr/local/etc/php/conf.d/app.ini \ # Composer is baked into every frankenphp image. docker exec "$name" composer --version >/dev/null 2>&1 || fail "composer is not runnable" -echo "ok: $image (PHP $version, uid $uid, healthy)" +# WORDPRESS_VCS_CHECKOUT (see the frankenphp Dockerfile). Unset, the prepend +# file does nothing; the exact value 1 seeds WordPress's +# automatic_updates_is_vcs_checkout filter; with PHP_OPEN_BASEDIR set, +# docker-configure lets the prepend file in, or every request would fail; +# with getenv disabled the file must not fatal. +seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' +docker exec "$name" test -f /usr/local/share/php-prepend/wordpress-vcs-checkout.php \ + || fail "the WORDPRESS_VCS_CHECKOUT prepend file is missing" +body=$(curl -fsS --max-time 10 "http://127.0.0.1:$port/vcs.php") \ + || fail "GET /vcs.php did not return 2xx" +[ "$body" = none ] || fail "WORDPRESS_VCS_CHECKOUT unset, but the filter was seeded: $body" +docker rm -f "$name" >/dev/null + +vcs_case() { # expected, then extra docker run arguments + local expected=$1 cname="$name-vcs-${#containers[@]}" + shift + boot "$cname" "$@" + body=$(curl -fsS --max-time 10 "http://127.0.0.1:$port/vcs.php") \ + || fail "GET /vcs.php did not return 2xx ($*)" + [ "$body" = "$expected" ] || fail "GET /vcs.php returned '$body', expected '$expected' ($*)" + body=$(curl -fsS --max-time 10 "http://127.0.0.1:$port/") \ + || fail "GET / did not return 2xx ($*)" + printf '%s\n' "$body" | grep -q '^VERSION=' || fail "GET / did not run the app ($*)" + docker rm -f "$cname" >/dev/null +} +vcs_case "$seeded" -e WORDPRESS_VCS_CHECKOUT=1 +vcs_case "$seeded" -e WORDPRESS_VCS_CHECKOUT=1 -e PHP_OPEN_BASEDIR=/app:/tmp +vcs_case none -e WORDPRESS_VCS_CHECKOUT=1 -e PHP_DISABLE_FUNCTIONS=getenv + +echo "ok: $image (PHP $version, uid $uid, healthy, WORDPRESS_VCS_CHECKOUT)" diff --git a/README.md b/README.md index 13ec159..3aeaacc 100644 --- a/README.md +++ b/README.md @@ -83,4 +83,6 @@ WordPress skips its background auto-updates (core, plugins, themes and translati docker run -e WORDPRESS_VCS_CHECKOUT=1 ghcr.io/aliasproject/php:8.4-frankenphp-wordpress ``` -It is unset by default, and only the exact value `1` turns it on. The `wordpress` and `wordpress-dev` variants, and an image built from `php/8.4/cli/Dockerfile.wordpress` (so WP-CLI cron runs behave the same), set PHP's `auto_prepend_file` to `/usr/local/share/php-prepend/wordpress-vcs-checkout.php`, a root-owned file that adds `__return_true` to WordPress's `automatic_updates_is_vcs_checkout` filter before WordPress loads (WordPress 4.7 or newer). With the variable unset the file does nothing, and it never affects non-WordPress code. Manual updates from wp-admin or `wp core update` still work. A derived image that sets its own `auto_prepend_file` replaces this one. When `PHP_OPEN_BASEDIR` is set, the frankenphp images add `/usr/local/share/php-prepend/` to it, because PHP refuses every request whose prepend file it can't open. +It is unset by default, and only the exact value `1` turns it on. Every frankenphp image (base, `dev`, `wordpress` and `wordpress-dev`, so a WordPress site on the base image is covered too) sets PHP's `auto_prepend_file` to `/usr/local/share/php-prepend/wordpress-vcs-checkout.php`, through `conf.d/00-wordpress-vcs-checkout.ini`. The file is root-owned, and adds `__return_true` to WordPress's `automatic_updates_is_vcs_checkout` filter before WordPress loads (WordPress 4.7 or newer). That covers web requests, and WP-Cron when a web request runs it. WP-CLI runs (a system cron calling `wp cron event run`, for example) need the CLI image built from `php/8.4/cli/Dockerfile.wordpress`, which carries the same file; CI doesn't build or publish that image. + +With the variable unset the file does nothing. With it set, the only effect on code that isn't WordPress is a global `$wp_filter` array with that one entry. Manual updates from wp-admin or `wp core update` still work. If `getenv` is in `PHP_DISABLE_FUNCTIONS`, the file can't read the variable and does nothing. A derived image that adds its own `auto_prepend_file` (a Wordfence `conf.d/wordfence.ini`, say) replaces this one: PHP reads `conf.d` in name order, so the later file wins. When `PHP_OPEN_BASEDIR` is set, the frankenphp images add `/usr/local/share/php-prepend/` to it, because PHP refuses every request whose prepend file it can't open. An image that sets `open_basedir` some other way (its own `conf.d` file) has to add that directory itself. diff --git a/php/8.2/frankenphp/Dockerfile b/php/8.2/frankenphp/Dockerfile index b8f0f14..6f6390e 100644 --- a/php/8.2/frankenphp/Dockerfile +++ b/php/8.2/frankenphp/Dockerfile @@ -128,6 +128,65 @@ COPY --chmod=755 docker-configure /usr/local/bin/docker-configure # source is deployed without its own Dockerfile. COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# It lives here rather than in Dockerfile.wordpress so a WordPress site on +# this image (framework not flagged) is covered too; every variant inherits +# it. auto_prepend_file runs before every PHP script, WordPress or not, so +# the file only touches $GLOBALS['wp_filter'] and only when the variable is +# "1". If getenv is in PHP_DISABLE_FUNCTIONS it can't read the variable and +# does nothing. It lives outside /app and conf.d, root-owned and read-only +# to appuser; docker-configure adds its directory to PHP_OPEN_BASEDIR. The +# ini is named 00-* so any later conf.d file (a derived image's +# wordfence.ini, say) that sets its own auto_prepend_file wins. +# php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress +# carry this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the upstream image +# ever sets one, rather than silently replacing it (chain to it from the file +# above if that happens). Then run a real script both ways: the filter is +# seeded only with the exact value "1". +RUN for bin in "frankenphp php-cli" php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + echo ' /tmp/vcs-check.php && \ + seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ + for bin in "frankenphp php-cli" php; do \ + test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ + test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter ($bin)" >&2; exit 1; }; \ + test "$(env -u WORDPRESS_VCS_CHECKOUT $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: unset WORDPRESS_VCS_CHECKOUT seeded the filter ($bin)" >&2; exit 1; }; \ + done && \ + rm /tmp/vcs-check.php + EXPOSE 80 443 443/udp HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ diff --git a/php/8.2/frankenphp/Dockerfile.wordpress b/php/8.2/frankenphp/Dockerfile.wordpress index 58cdd57..aeecaab 100644 --- a/php/8.2/frankenphp/Dockerfile.wordpress +++ b/php/8.2/frankenphp/Dockerfile.wordpress @@ -101,47 +101,4 @@ ENV PHP_OPCACHE_MEMORY=256 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \ PHP_OPCACHE_REVALIDATE_FREQ=60 -# --------------------------------------------------------------------------- -# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) -# -# WordPress skips background auto-updates (core, plugins, themes, -# translations) when it finds a .git, .svn, .hg or .bzr directory at or above -# the code it would update, so files deployed from a repository aren't -# rewritten underneath it. A deploy that keeps the repository outside the -# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend -# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with -# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded -# $wp_filter entries into real hooks. Any other value, or unset, does nothing. -# -# auto_prepend_file runs before every PHP script in the image, WordPress or -# not, so the file only touches $GLOBALS['wp_filter'] and only when the -# variable is "1". It lives outside /app and conf.d, root-owned and read-only -# to appuser. Every frankenphp Dockerfile.wordpress and -# php/8.4/cli/Dockerfile.wordpress carry this same block; keep them in sync. -# --------------------------------------------------------------------------- -COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php - '__return_true', - 'accepted_args' => 1, - ]; -} -PHP - -# There is only one auto_prepend_file. Fail the build if the base ever sets -# one, rather than silently replacing it (chain to it from the file above if -# that happens), and fail if PHP doesn't pick up the new setting. -RUN for bin in "frankenphp php-cli" php; do \ - $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ - { echo "ERROR: base image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ - done && \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ - for bin in "frankenphp php-cli" php; do \ - test "$($bin -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ - { echo "ERROR: auto_prepend_file not picked up ($bin)" >&2; exit 1; }; \ - done - USER appuser diff --git a/php/8.2/frankenphp/docker-configure b/php/8.2/frankenphp/docker-configure index 9ed3725..bb793ee 100644 --- a/php/8.2/frankenphp/docker-configure +++ b/php/8.2/frankenphp/docker-configure @@ -44,14 +44,11 @@ CADDY_SITE_D=/config/caddy/site.d fi if [ -n "${PHP_OPEN_BASEDIR}" ]; then - # Dockerfile.wordpress keeps an auto_prepend_file here. PHP refuses - # to run any script whose prepend file is outside open_basedir, so - # let it in. The directory is root-owned and holds only that file. - if [ -d /usr/local/share/php-prepend ]; then - echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" - else - echo "open_basedir = ${PHP_OPEN_BASEDIR}" - fi + # The Dockerfile keeps the WORDPRESS_VCS_CHECKOUT auto_prepend_file + # here. PHP refuses to run any script whose prepend file is outside + # open_basedir, so let it in. The directory is root-owned and holds + # only that file. + echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" fi } > "${PHP_INI_DIR}/conf.d/app.ini" diff --git a/php/8.3/frankenphp/Dockerfile b/php/8.3/frankenphp/Dockerfile index 2f3b782..ab492b7 100644 --- a/php/8.3/frankenphp/Dockerfile +++ b/php/8.3/frankenphp/Dockerfile @@ -128,6 +128,65 @@ COPY --chmod=755 docker-configure /usr/local/bin/docker-configure # source is deployed without its own Dockerfile. COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# It lives here rather than in Dockerfile.wordpress so a WordPress site on +# this image (framework not flagged) is covered too; every variant inherits +# it. auto_prepend_file runs before every PHP script, WordPress or not, so +# the file only touches $GLOBALS['wp_filter'] and only when the variable is +# "1". If getenv is in PHP_DISABLE_FUNCTIONS it can't read the variable and +# does nothing. It lives outside /app and conf.d, root-owned and read-only +# to appuser; docker-configure adds its directory to PHP_OPEN_BASEDIR. The +# ini is named 00-* so any later conf.d file (a derived image's +# wordfence.ini, say) that sets its own auto_prepend_file wins. +# php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress +# carry this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the upstream image +# ever sets one, rather than silently replacing it (chain to it from the file +# above if that happens). Then run a real script both ways: the filter is +# seeded only with the exact value "1". +RUN for bin in "frankenphp php-cli" php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + echo ' /tmp/vcs-check.php && \ + seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ + for bin in "frankenphp php-cli" php; do \ + test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ + test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter ($bin)" >&2; exit 1; }; \ + test "$(env -u WORDPRESS_VCS_CHECKOUT $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: unset WORDPRESS_VCS_CHECKOUT seeded the filter ($bin)" >&2; exit 1; }; \ + done && \ + rm /tmp/vcs-check.php + EXPOSE 80 443 443/udp HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ diff --git a/php/8.3/frankenphp/Dockerfile.wordpress b/php/8.3/frankenphp/Dockerfile.wordpress index ab4a7b0..e812ed6 100644 --- a/php/8.3/frankenphp/Dockerfile.wordpress +++ b/php/8.3/frankenphp/Dockerfile.wordpress @@ -101,47 +101,4 @@ ENV PHP_OPCACHE_MEMORY=256 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \ PHP_OPCACHE_REVALIDATE_FREQ=60 -# --------------------------------------------------------------------------- -# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) -# -# WordPress skips background auto-updates (core, plugins, themes, -# translations) when it finds a .git, .svn, .hg or .bzr directory at or above -# the code it would update, so files deployed from a repository aren't -# rewritten underneath it. A deploy that keeps the repository outside the -# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend -# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with -# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded -# $wp_filter entries into real hooks. Any other value, or unset, does nothing. -# -# auto_prepend_file runs before every PHP script in the image, WordPress or -# not, so the file only touches $GLOBALS['wp_filter'] and only when the -# variable is "1". It lives outside /app and conf.d, root-owned and read-only -# to appuser. Every frankenphp Dockerfile.wordpress and -# php/8.4/cli/Dockerfile.wordpress carry this same block; keep them in sync. -# --------------------------------------------------------------------------- -COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php - '__return_true', - 'accepted_args' => 1, - ]; -} -PHP - -# There is only one auto_prepend_file. Fail the build if the base ever sets -# one, rather than silently replacing it (chain to it from the file above if -# that happens), and fail if PHP doesn't pick up the new setting. -RUN for bin in "frankenphp php-cli" php; do \ - $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ - { echo "ERROR: base image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ - done && \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ - for bin in "frankenphp php-cli" php; do \ - test "$($bin -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ - { echo "ERROR: auto_prepend_file not picked up ($bin)" >&2; exit 1; }; \ - done - USER appuser diff --git a/php/8.3/frankenphp/docker-configure b/php/8.3/frankenphp/docker-configure index 9ed3725..bb793ee 100644 --- a/php/8.3/frankenphp/docker-configure +++ b/php/8.3/frankenphp/docker-configure @@ -44,14 +44,11 @@ CADDY_SITE_D=/config/caddy/site.d fi if [ -n "${PHP_OPEN_BASEDIR}" ]; then - # Dockerfile.wordpress keeps an auto_prepend_file here. PHP refuses - # to run any script whose prepend file is outside open_basedir, so - # let it in. The directory is root-owned and holds only that file. - if [ -d /usr/local/share/php-prepend ]; then - echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" - else - echo "open_basedir = ${PHP_OPEN_BASEDIR}" - fi + # The Dockerfile keeps the WORDPRESS_VCS_CHECKOUT auto_prepend_file + # here. PHP refuses to run any script whose prepend file is outside + # open_basedir, so let it in. The directory is root-owned and holds + # only that file. + echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" fi } > "${PHP_INI_DIR}/conf.d/app.ini" diff --git a/php/8.4/cli/Dockerfile.wordpress b/php/8.4/cli/Dockerfile.wordpress index 35404ce..e2a5830 100644 --- a/php/8.4/cli/Dockerfile.wordpress +++ b/php/8.4/cli/Dockerfile.wordpress @@ -46,17 +46,22 @@ RUN install-php-extensions \ # __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded # $wp_filter entries into real hooks. Any other value, or unset, does nothing. # -# auto_prepend_file runs before every PHP script in the image, WordPress or -# not, so the file only touches $GLOBALS['wp_filter'] and only when the -# variable is "1". WP-CLI runs (cron among them) can trigger auto-updates -# too, so the CLI image needs it as well as the web one. It lives outside -# /app and conf.d, root-owned and read-only to appuser. Every frankenphp -# Dockerfile.wordpress carries this same block; keep them in sync. +# WP-CLI runs (cron among them) can trigger auto-updates too, so the CLI +# image needs it as well as the web one. auto_prepend_file runs before every +# PHP script, WordPress or not, so the file only touches $GLOBALS['wp_filter'] +# and only when the variable is "1". If getenv is disabled it can't read the +# variable and does nothing. It lives outside /app and conf.d, root-owned and +# read-only to appuser. The ini is named 00-* so any later conf.d file (a +# derived image's wordfence.ini, say) that sets its own auto_prepend_file +# wins. This image isn't built by build-and-push.yml. +# php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress +# carry this same block; keep them in sync. # --------------------------------------------------------------------------- COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php '__return_true', 'accepted_args' => 1, @@ -64,14 +69,23 @@ if (getenv('WORDPRESS_VCS_CHECKOUT') === '1') { } PHP -# There is only one auto_prepend_file. Fail the build if the base ever sets -# one, rather than silently replacing it (chain to it from the file above if -# that happens), and fail if PHP doesn't pick up the new setting. +# There is only one auto_prepend_file. Fail the build if the upstream image +# ever sets one, rather than silently replacing it (chain to it from the file +# above if that happens). Then run a real script both ways: the filter is +# seeded only with the exact value "1". RUN php -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ - { echo "ERROR: base image already sets auto_prepend_file" >&2; exit 1; } && \ + { echo "ERROR: upstream image already sets auto_prepend_file" >&2; exit 1; }; \ echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ - test "$(php -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ - { echo "ERROR: auto_prepend_file not picked up" >&2; exit 1; } + > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + echo ' /tmp/vcs-check.php && \ + seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ + test "$(WORDPRESS_VCS_CHECKOUT=1 php /tmp/vcs-check.php)" = "$seeded" || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter" >&2; exit 1; }; \ + test "$(WORDPRESS_VCS_CHECKOUT=true php /tmp/vcs-check.php)" = none || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter" >&2; exit 1; }; \ + test "$(env -u WORDPRESS_VCS_CHECKOUT php /tmp/vcs-check.php)" = none || \ + { echo "ERROR: unset WORDPRESS_VCS_CHECKOUT seeded the filter" >&2; exit 1; }; \ + rm /tmp/vcs-check.php USER appuser diff --git a/php/8.4/frankenphp/Dockerfile b/php/8.4/frankenphp/Dockerfile index ba01b51..0f49313 100644 --- a/php/8.4/frankenphp/Dockerfile +++ b/php/8.4/frankenphp/Dockerfile @@ -133,6 +133,65 @@ COPY --chmod=755 docker-configure /usr/local/bin/docker-configure # source is deployed without its own Dockerfile. COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# It lives here rather than in Dockerfile.wordpress so a WordPress site on +# this image (framework not flagged) is covered too; every variant inherits +# it. auto_prepend_file runs before every PHP script, WordPress or not, so +# the file only touches $GLOBALS['wp_filter'] and only when the variable is +# "1". If getenv is in PHP_DISABLE_FUNCTIONS it can't read the variable and +# does nothing. It lives outside /app and conf.d, root-owned and read-only +# to appuser; docker-configure adds its directory to PHP_OPEN_BASEDIR. The +# ini is named 00-* so any later conf.d file (a derived image's +# wordfence.ini, say) that sets its own auto_prepend_file wins. +# php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress +# carry this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the upstream image +# ever sets one, rather than silently replacing it (chain to it from the file +# above if that happens). Then run a real script both ways: the filter is +# seeded only with the exact value "1". +RUN for bin in "frankenphp php-cli" php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + echo ' /tmp/vcs-check.php && \ + seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ + for bin in "frankenphp php-cli" php; do \ + test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ + test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter ($bin)" >&2; exit 1; }; \ + test "$(env -u WORDPRESS_VCS_CHECKOUT $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: unset WORDPRESS_VCS_CHECKOUT seeded the filter ($bin)" >&2; exit 1; }; \ + done && \ + rm /tmp/vcs-check.php + EXPOSE 80 443 443/udp HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ diff --git a/php/8.4/frankenphp/Dockerfile.wordpress b/php/8.4/frankenphp/Dockerfile.wordpress index 55b0c0a..3026031 100644 --- a/php/8.4/frankenphp/Dockerfile.wordpress +++ b/php/8.4/frankenphp/Dockerfile.wordpress @@ -101,47 +101,4 @@ ENV PHP_OPCACHE_MEMORY=256 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \ PHP_OPCACHE_REVALIDATE_FREQ=60 -# --------------------------------------------------------------------------- -# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) -# -# WordPress skips background auto-updates (core, plugins, themes, -# translations) when it finds a .git, .svn, .hg or .bzr directory at or above -# the code it would update, so files deployed from a repository aren't -# rewritten underneath it. A deploy that keeps the repository outside the -# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend -# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with -# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded -# $wp_filter entries into real hooks. Any other value, or unset, does nothing. -# -# auto_prepend_file runs before every PHP script in the image, WordPress or -# not, so the file only touches $GLOBALS['wp_filter'] and only when the -# variable is "1". It lives outside /app and conf.d, root-owned and read-only -# to appuser. Every frankenphp Dockerfile.wordpress and -# php/8.4/cli/Dockerfile.wordpress carry this same block; keep them in sync. -# --------------------------------------------------------------------------- -COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php - '__return_true', - 'accepted_args' => 1, - ]; -} -PHP - -# There is only one auto_prepend_file. Fail the build if the base ever sets -# one, rather than silently replacing it (chain to it from the file above if -# that happens), and fail if PHP doesn't pick up the new setting. -RUN for bin in "frankenphp php-cli" php; do \ - $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ - { echo "ERROR: base image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ - done && \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ - for bin in "frankenphp php-cli" php; do \ - test "$($bin -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ - { echo "ERROR: auto_prepend_file not picked up ($bin)" >&2; exit 1; }; \ - done - USER appuser diff --git a/php/8.4/frankenphp/docker-configure b/php/8.4/frankenphp/docker-configure index 9ed3725..bb793ee 100644 --- a/php/8.4/frankenphp/docker-configure +++ b/php/8.4/frankenphp/docker-configure @@ -44,14 +44,11 @@ CADDY_SITE_D=/config/caddy/site.d fi if [ -n "${PHP_OPEN_BASEDIR}" ]; then - # Dockerfile.wordpress keeps an auto_prepend_file here. PHP refuses - # to run any script whose prepend file is outside open_basedir, so - # let it in. The directory is root-owned and holds only that file. - if [ -d /usr/local/share/php-prepend ]; then - echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" - else - echo "open_basedir = ${PHP_OPEN_BASEDIR}" - fi + # The Dockerfile keeps the WORDPRESS_VCS_CHECKOUT auto_prepend_file + # here. PHP refuses to run any script whose prepend file is outside + # open_basedir, so let it in. The directory is root-owned and holds + # only that file. + echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" fi } > "${PHP_INI_DIR}/conf.d/app.ini" diff --git a/php/8.5/frankenphp/Dockerfile b/php/8.5/frankenphp/Dockerfile index 0105920..c04d72c 100644 --- a/php/8.5/frankenphp/Dockerfile +++ b/php/8.5/frankenphp/Dockerfile @@ -128,6 +128,65 @@ COPY --chmod=755 docker-configure /usr/local/bin/docker-configure # source is deployed without its own Dockerfile. COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer +# --------------------------------------------------------------------------- +# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) +# +# WordPress skips background auto-updates (core, plugins, themes, +# translations) when it finds a .git, .svn, .hg or .bzr directory at or above +# the code it would update, so files deployed from a repository aren't +# rewritten underneath it. A deploy that keeps the repository outside the +# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend +# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with +# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded +# $wp_filter entries into real hooks. Any other value, or unset, does nothing. +# +# It lives here rather than in Dockerfile.wordpress so a WordPress site on +# this image (framework not flagged) is covered too; every variant inherits +# it. auto_prepend_file runs before every PHP script, WordPress or not, so +# the file only touches $GLOBALS['wp_filter'] and only when the variable is +# "1". If getenv is in PHP_DISABLE_FUNCTIONS it can't read the variable and +# does nothing. It lives outside /app and conf.d, root-owned and read-only +# to appuser; docker-configure adds its directory to PHP_OPEN_BASEDIR. The +# ini is named 00-* so any later conf.d file (a derived image's +# wordfence.ini, say) that sets its own auto_prepend_file wins. +# php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress +# carry this same block; keep them in sync. +# --------------------------------------------------------------------------- +COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php + '__return_true', + 'accepted_args' => 1, + ]; +} +PHP + +# There is only one auto_prepend_file. Fail the build if the upstream image +# ever sets one, rather than silently replacing it (chain to it from the file +# above if that happens). Then run a real script both ways: the filter is +# seeded only with the exact value "1". +RUN for bin in "frankenphp php-cli" php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ + > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + echo ' /tmp/vcs-check.php && \ + seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ + for bin in "frankenphp php-cli" php; do \ + test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ + test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter ($bin)" >&2; exit 1; }; \ + test "$(env -u WORDPRESS_VCS_CHECKOUT $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: unset WORDPRESS_VCS_CHECKOUT seeded the filter ($bin)" >&2; exit 1; }; \ + done && \ + rm /tmp/vcs-check.php + EXPOSE 80 443 443/udp HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ diff --git a/php/8.5/frankenphp/Dockerfile.wordpress b/php/8.5/frankenphp/Dockerfile.wordpress index e5b4a6b..320cb5a 100644 --- a/php/8.5/frankenphp/Dockerfile.wordpress +++ b/php/8.5/frankenphp/Dockerfile.wordpress @@ -101,47 +101,4 @@ ENV PHP_OPCACHE_MEMORY=256 \ PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \ PHP_OPCACHE_REVALIDATE_FREQ=60 -# --------------------------------------------------------------------------- -# WORDPRESS_VCS_CHECKOUT (opt-in, unset by default) -# -# WordPress skips background auto-updates (core, plugins, themes, -# translations) when it finds a .git, .svn, .hg or .bzr directory at or above -# the code it would update, so files deployed from a repository aren't -# rewritten underneath it. A deploy that keeps the repository outside the -# served folder loses that. WORDPRESS_VCS_CHECKOUT=1 restores it: the prepend -# file below seeds WordPress's automatic_updates_is_vcs_checkout filter with -# __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded -# $wp_filter entries into real hooks. Any other value, or unset, does nothing. -# -# auto_prepend_file runs before every PHP script in the image, WordPress or -# not, so the file only touches $GLOBALS['wp_filter'] and only when the -# variable is "1". It lives outside /app and conf.d, root-owned and read-only -# to appuser. Every frankenphp Dockerfile.wordpress and -# php/8.4/cli/Dockerfile.wordpress carry this same block; keep them in sync. -# --------------------------------------------------------------------------- -COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php - '__return_true', - 'accepted_args' => 1, - ]; -} -PHP - -# There is only one auto_prepend_file. Fail the build if the base ever sets -# one, rather than silently replacing it (chain to it from the file above if -# that happens), and fail if PHP doesn't pick up the new setting. -RUN for bin in "frankenphp php-cli" php; do \ - $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ - { echo "ERROR: base image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ - done && \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/wordpress-vcs-checkout.ini" && \ - for bin in "frankenphp php-cli" php; do \ - test "$($bin -r 'echo ini_get("auto_prepend_file");')" = /usr/local/share/php-prepend/wordpress-vcs-checkout.php || \ - { echo "ERROR: auto_prepend_file not picked up ($bin)" >&2; exit 1; }; \ - done - USER appuser diff --git a/php/8.5/frankenphp/docker-configure b/php/8.5/frankenphp/docker-configure index 9ed3725..bb793ee 100644 --- a/php/8.5/frankenphp/docker-configure +++ b/php/8.5/frankenphp/docker-configure @@ -44,14 +44,11 @@ CADDY_SITE_D=/config/caddy/site.d fi if [ -n "${PHP_OPEN_BASEDIR}" ]; then - # Dockerfile.wordpress keeps an auto_prepend_file here. PHP refuses - # to run any script whose prepend file is outside open_basedir, so - # let it in. The directory is root-owned and holds only that file. - if [ -d /usr/local/share/php-prepend ]; then - echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" - else - echo "open_basedir = ${PHP_OPEN_BASEDIR}" - fi + # The Dockerfile keeps the WORDPRESS_VCS_CHECKOUT auto_prepend_file + # here. PHP refuses to run any script whose prepend file is outside + # open_basedir, so let it in. The directory is root-owned and holds + # only that file. + echo "open_basedir = ${PHP_OPEN_BASEDIR}:/usr/local/share/php-prepend/" fi } > "${PHP_INI_DIR}/conf.d/app.ini" From f89a603865313ca40ae63b72f550923c7f943839 Mon Sep 17 00:00:00 2001 From: Michael Aguiar Date: Wed, 25 Nov 2026 15:41:54 -0700 Subject: [PATCH 3/3] Set WORDPRESS_VCS_CHECKOUT's auto_prepend_file in php.ini PHP reads conf.d after php.ini, so conf.d/00-wordpress-vcs-checkout.ini beat an auto_prepend_file that a derived image set in php.ini (a Wordfence WAF, for example). The directive now replaces the existing "auto_prepend_file =" line in $PHP_INI_DIR/php.ini (or is appended if there isn't one), and the conf.d file is gone. A derived image that edits that line, appends its own or adds any conf.d file now wins. - The build fails if php.ini is missing, if it doesn't end up with exactly one auto_prepend_file line, or if PHP doesn't report the prepend file afterwards (frankenphp php-cli and php; php in the cli image). - cli/Dockerfile.wordpress: the RUN is chained with && like the frankenphp version, so a failure reports the right error. - smoke-test.sh: in the cli check, a docker run that fails now fails the check instead of reading as "no file". CI doesn't build cli-wordpress, so that part only runs by hand. - Every Dockerfile that uses COPY < php wp-cli.phar cron event run`, for example; the images don't ship WP-CLI itself). Only WP-CLI in a separate CLI container needs the image built from `php/8.4/cli/Dockerfile.wordpress`, which carries the same file; CI doesn't build or publish that image. -With the variable unset the file does nothing. With it set, the only effect on code that isn't WordPress is a global `$wp_filter` array with that one entry. Manual updates from wp-admin or `wp core update` still work. If `getenv` is in `PHP_DISABLE_FUNCTIONS`, the file can't read the variable and does nothing. A derived image that adds its own `auto_prepend_file` (a Wordfence `conf.d/wordfence.ini`, say) replaces this one: PHP reads `conf.d` in name order, so the later file wins. When `PHP_OPEN_BASEDIR` is set, the frankenphp images add `/usr/local/share/php-prepend/` to it, because PHP refuses every request whose prepend file it can't open. An image that sets `open_basedir` some other way (its own `conf.d` file) has to add that directory itself. +With the variable unset the file does nothing. With it set, the only effect on code that isn't WordPress is a global `$wp_filter` array with that one entry. Manual updates from wp-admin or `wp core update` still work. If `getenv` is in `PHP_DISABLE_FUNCTIONS`, the file can't read the variable and does nothing. A derived image that sets its own `auto_prepend_file` (a Wordfence WAF, say) replaces this one, whether it edits the `auto_prepend_file` line in `php.ini`, appends its own line there or adds any `conf.d` file: PHP reads `conf.d` after `php.ini`, and the last setting wins. When `PHP_OPEN_BASEDIR` is set, the frankenphp images add `/usr/local/share/php-prepend/` to it, because PHP refuses every request whose prepend file it can't open. An image that sets `open_basedir` some other way (its own `conf.d` file) has to add that directory itself. diff --git a/php/8.2/frankenphp/Dockerfile b/php/8.2/frankenphp/Dockerfile index 6f6390e..1856d97 100644 --- a/php/8.2/frankenphp/Dockerfile +++ b/php/8.2/frankenphp/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 ARG FRANKENPHP_VERSION=1.14.0 ARG PHP_VERSION=8.2 FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine @@ -145,17 +146,24 @@ COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer # it. auto_prepend_file runs before every PHP script, WordPress or not, so # the file only touches $GLOBALS['wp_filter'] and only when the variable is # "1". If getenv is in PHP_DISABLE_FUNCTIONS it can't read the variable and -# does nothing. It lives outside /app and conf.d, root-owned and read-only -# to appuser; docker-configure adds its directory to PHP_OPEN_BASEDIR. The -# ini is named 00-* so any later conf.d file (a derived image's -# wordfence.ini, say) that sets its own auto_prepend_file wins. +# does nothing. It lives outside /app, and docker-configure adds its +# directory to PHP_OPEN_BASEDIR. +# +# The directive goes in php.ini itself, replacing its "auto_prepend_file =" +# line in place, not in a conf.d file: PHP reads conf.d after php.ini, so a +# derived image that sets its own auto_prepend_file (a Wordfence WAF, say), +# by editing that line, appending one or adding any conf.d file, wins. The +# prepend file and php.ini are root-owned and read-only to appuser. appuser +# (group 0) can write conf.d, so it can override this directive there, as it +# can any other PHP setting. +# # php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress # carry this same block; keep them in sync. # --------------------------------------------------------------------------- COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php '__return_true', @@ -164,20 +172,31 @@ if (function_exists('getenv') && getenv('WORDPRESS_VCS_CHECKOUT') === '1') { } PHP -# There is only one auto_prepend_file. Fail the build if the upstream image -# ever sets one, rather than silently replacing it (chain to it from the file -# above if that happens). Then run a real script both ways: the filter is -# seeded only with the exact value "1". -RUN for bin in "frankenphp php-cli" php; do \ +# There is only one auto_prepend_file. Fail the build if php.ini is missing or +# the upstream image already sets one, rather than silently replacing it +# (chain to it from the file above if that happens). Then set it in php.ini +# and run a real script both ways: the filter is seeded only with the exact +# value "1". +RUN ini="$PHP_INI_DIR/php.ini" && \ + prepend=/usr/local/share/php-prepend/wordpress-vcs-checkout.php && \ + { test -f "$ini" || { echo "ERROR: $ini is missing" >&2; exit 1; }; } && \ + for bin in "frankenphp php-cli" php; do \ $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ done && \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + if grep -q '^auto_prepend_file[[:space:]]*=' "$ini"; then \ + sed -i "s|^auto_prepend_file[[:space:]]*=.*|auto_prepend_file = $prepend|" "$ini"; \ + else \ + printf '\nauto_prepend_file = %s\n' "$prepend" >> "$ini"; \ + fi && \ + { test "$(grep -c '^auto_prepend_file[[:space:]]*=' "$ini")" = 1 || \ + { echo "ERROR: $ini should have exactly one auto_prepend_file line" >&2; exit 1; }; } && \ echo ' /tmp/vcs-check.php && \ seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ for bin in "frankenphp php-cli" php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = "$prepend" || \ + { echo "ERROR: auto_prepend_file is not $prepend ($bin)" >&2; exit 1; }; \ test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \ diff --git a/php/8.3/frankenphp/Dockerfile b/php/8.3/frankenphp/Dockerfile index ab492b7..838af00 100644 --- a/php/8.3/frankenphp/Dockerfile +++ b/php/8.3/frankenphp/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 ARG FRANKENPHP_VERSION=1.14.0 ARG PHP_VERSION=8.3 FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine @@ -145,17 +146,24 @@ COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer # it. auto_prepend_file runs before every PHP script, WordPress or not, so # the file only touches $GLOBALS['wp_filter'] and only when the variable is # "1". If getenv is in PHP_DISABLE_FUNCTIONS it can't read the variable and -# does nothing. It lives outside /app and conf.d, root-owned and read-only -# to appuser; docker-configure adds its directory to PHP_OPEN_BASEDIR. The -# ini is named 00-* so any later conf.d file (a derived image's -# wordfence.ini, say) that sets its own auto_prepend_file wins. +# does nothing. It lives outside /app, and docker-configure adds its +# directory to PHP_OPEN_BASEDIR. +# +# The directive goes in php.ini itself, replacing its "auto_prepend_file =" +# line in place, not in a conf.d file: PHP reads conf.d after php.ini, so a +# derived image that sets its own auto_prepend_file (a Wordfence WAF, say), +# by editing that line, appending one or adding any conf.d file, wins. The +# prepend file and php.ini are root-owned and read-only to appuser. appuser +# (group 0) can write conf.d, so it can override this directive there, as it +# can any other PHP setting. +# # php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress # carry this same block; keep them in sync. # --------------------------------------------------------------------------- COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php '__return_true', @@ -164,20 +172,31 @@ if (function_exists('getenv') && getenv('WORDPRESS_VCS_CHECKOUT') === '1') { } PHP -# There is only one auto_prepend_file. Fail the build if the upstream image -# ever sets one, rather than silently replacing it (chain to it from the file -# above if that happens). Then run a real script both ways: the filter is -# seeded only with the exact value "1". -RUN for bin in "frankenphp php-cli" php; do \ +# There is only one auto_prepend_file. Fail the build if php.ini is missing or +# the upstream image already sets one, rather than silently replacing it +# (chain to it from the file above if that happens). Then set it in php.ini +# and run a real script both ways: the filter is seeded only with the exact +# value "1". +RUN ini="$PHP_INI_DIR/php.ini" && \ + prepend=/usr/local/share/php-prepend/wordpress-vcs-checkout.php && \ + { test -f "$ini" || { echo "ERROR: $ini is missing" >&2; exit 1; }; } && \ + for bin in "frankenphp php-cli" php; do \ $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ done && \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + if grep -q '^auto_prepend_file[[:space:]]*=' "$ini"; then \ + sed -i "s|^auto_prepend_file[[:space:]]*=.*|auto_prepend_file = $prepend|" "$ini"; \ + else \ + printf '\nauto_prepend_file = %s\n' "$prepend" >> "$ini"; \ + fi && \ + { test "$(grep -c '^auto_prepend_file[[:space:]]*=' "$ini")" = 1 || \ + { echo "ERROR: $ini should have exactly one auto_prepend_file line" >&2; exit 1; }; } && \ echo ' /tmp/vcs-check.php && \ seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ for bin in "frankenphp php-cli" php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = "$prepend" || \ + { echo "ERROR: auto_prepend_file is not $prepend ($bin)" >&2; exit 1; }; \ test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \ diff --git a/php/8.4/cli/Dockerfile.wordpress b/php/8.4/cli/Dockerfile.wordpress index e2a5830..f587a76 100644 --- a/php/8.4/cli/Dockerfile.wordpress +++ b/php/8.4/cli/Dockerfile.wordpress @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 FROM ghcr.io/aliasproject/php:8.4-cli LABEL maintainer="Michael Aguiar " @@ -46,21 +47,29 @@ RUN install-php-extensions \ # __return_true before WordPress loads, and WordPress (4.7+) turns pre-seeded # $wp_filter entries into real hooks. Any other value, or unset, does nothing. # -# WP-CLI runs (cron among them) can trigger auto-updates too, so the CLI -# image needs it as well as the web one. auto_prepend_file runs before every -# PHP script, WordPress or not, so the file only touches $GLOBALS['wp_filter'] -# and only when the variable is "1". If getenv is disabled it can't read the -# variable and does nothing. It lives outside /app and conf.d, root-owned and -# read-only to appuser. The ini is named 00-* so any later conf.d file (a -# derived image's wordfence.ini, say) that sets its own auto_prepend_file -# wins. This image isn't built by build-and-push.yml. +# WP-CLI runs (cron among them) can trigger auto-updates too, so a separate +# CLI container running wp needs it as well as the web one (wp run with +# docker exec in a frankenphp container already has it). auto_prepend_file +# runs before every PHP script, WordPress or not, so the file only touches +# $GLOBALS['wp_filter'] and only when the variable is "1". If getenv is +# disabled it can't read the variable and does nothing. It lives outside +# /app. This image isn't built by build-and-push.yml. +# +# The directive goes in php.ini itself, replacing its "auto_prepend_file =" +# line in place, not in a conf.d file: PHP reads conf.d after php.ini, so a +# derived image that sets its own auto_prepend_file (a Wordfence WAF, say), +# by editing that line, appending one or adding any conf.d file, wins. The +# prepend file and php.ini are root-owned and read-only to appuser. appuser +# (group 0) can write conf.d, so it can override this directive there, as it +# can any other PHP setting. +# # php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress # carry this same block; keep them in sync. # --------------------------------------------------------------------------- COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php '__return_true', @@ -69,23 +78,38 @@ if (function_exists('getenv') && getenv('WORDPRESS_VCS_CHECKOUT') === '1') { } PHP -# There is only one auto_prepend_file. Fail the build if the upstream image -# ever sets one, rather than silently replacing it (chain to it from the file -# above if that happens). Then run a real script both ways: the filter is -# seeded only with the exact value "1". -RUN php -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ - { echo "ERROR: upstream image already sets auto_prepend_file" >&2; exit 1; }; \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ +# There is only one auto_prepend_file. Fail the build if php.ini is missing or +# the upstream image already sets one, rather than silently replacing it +# (chain to it from the file above if that happens). Then set it in php.ini +# and run a real script both ways: the filter is seeded only with the exact +# value "1". +RUN ini="$PHP_INI_DIR/php.ini" && \ + prepend=/usr/local/share/php-prepend/wordpress-vcs-checkout.php && \ + { test -f "$ini" || { echo "ERROR: $ini is missing" >&2; exit 1; }; } && \ + for bin in php; do \ + $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ + { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ + done && \ + if grep -q '^auto_prepend_file[[:space:]]*=' "$ini"; then \ + sed -i "s|^auto_prepend_file[[:space:]]*=.*|auto_prepend_file = $prepend|" "$ini"; \ + else \ + printf '\nauto_prepend_file = %s\n' "$prepend" >> "$ini"; \ + fi && \ + { test "$(grep -c '^auto_prepend_file[[:space:]]*=' "$ini")" = 1 || \ + { echo "ERROR: $ini should have exactly one auto_prepend_file line" >&2; exit 1; }; } && \ echo ' /tmp/vcs-check.php && \ seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ - test "$(WORDPRESS_VCS_CHECKOUT=1 php /tmp/vcs-check.php)" = "$seeded" || \ - { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter" >&2; exit 1; }; \ - test "$(WORDPRESS_VCS_CHECKOUT=true php /tmp/vcs-check.php)" = none || \ - { echo "ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter" >&2; exit 1; }; \ - test "$(env -u WORDPRESS_VCS_CHECKOUT php /tmp/vcs-check.php)" = none || \ - { echo "ERROR: unset WORDPRESS_VCS_CHECKOUT seeded the filter" >&2; exit 1; }; \ + for bin in php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = "$prepend" || \ + { echo "ERROR: auto_prepend_file is not $prepend ($bin)" >&2; exit 1; }; \ + test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ + test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter ($bin)" >&2; exit 1; }; \ + test "$(env -u WORDPRESS_VCS_CHECKOUT $bin /tmp/vcs-check.php)" = none || \ + { echo "ERROR: unset WORDPRESS_VCS_CHECKOUT seeded the filter ($bin)" >&2; exit 1; }; \ + done && \ rm /tmp/vcs-check.php USER appuser diff --git a/php/8.4/frankenphp/Dockerfile b/php/8.4/frankenphp/Dockerfile index 0f49313..f21b673 100644 --- a/php/8.4/frankenphp/Dockerfile +++ b/php/8.4/frankenphp/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 ARG FRANKENPHP_VERSION=1.14.0 ARG PHP_VERSION=8.4 FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine @@ -150,17 +151,24 @@ COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer # it. auto_prepend_file runs before every PHP script, WordPress or not, so # the file only touches $GLOBALS['wp_filter'] and only when the variable is # "1". If getenv is in PHP_DISABLE_FUNCTIONS it can't read the variable and -# does nothing. It lives outside /app and conf.d, root-owned and read-only -# to appuser; docker-configure adds its directory to PHP_OPEN_BASEDIR. The -# ini is named 00-* so any later conf.d file (a derived image's -# wordfence.ini, say) that sets its own auto_prepend_file wins. +# does nothing. It lives outside /app, and docker-configure adds its +# directory to PHP_OPEN_BASEDIR. +# +# The directive goes in php.ini itself, replacing its "auto_prepend_file =" +# line in place, not in a conf.d file: PHP reads conf.d after php.ini, so a +# derived image that sets its own auto_prepend_file (a Wordfence WAF, say), +# by editing that line, appending one or adding any conf.d file, wins. The +# prepend file and php.ini are root-owned and read-only to appuser. appuser +# (group 0) can write conf.d, so it can override this directive there, as it +# can any other PHP setting. +# # php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress # carry this same block; keep them in sync. # --------------------------------------------------------------------------- COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php '__return_true', @@ -169,20 +177,31 @@ if (function_exists('getenv') && getenv('WORDPRESS_VCS_CHECKOUT') === '1') { } PHP -# There is only one auto_prepend_file. Fail the build if the upstream image -# ever sets one, rather than silently replacing it (chain to it from the file -# above if that happens). Then run a real script both ways: the filter is -# seeded only with the exact value "1". -RUN for bin in "frankenphp php-cli" php; do \ +# There is only one auto_prepend_file. Fail the build if php.ini is missing or +# the upstream image already sets one, rather than silently replacing it +# (chain to it from the file above if that happens). Then set it in php.ini +# and run a real script both ways: the filter is seeded only with the exact +# value "1". +RUN ini="$PHP_INI_DIR/php.ini" && \ + prepend=/usr/local/share/php-prepend/wordpress-vcs-checkout.php && \ + { test -f "$ini" || { echo "ERROR: $ini is missing" >&2; exit 1; }; } && \ + for bin in "frankenphp php-cli" php; do \ $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ done && \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + if grep -q '^auto_prepend_file[[:space:]]*=' "$ini"; then \ + sed -i "s|^auto_prepend_file[[:space:]]*=.*|auto_prepend_file = $prepend|" "$ini"; \ + else \ + printf '\nauto_prepend_file = %s\n' "$prepend" >> "$ini"; \ + fi && \ + { test "$(grep -c '^auto_prepend_file[[:space:]]*=' "$ini")" = 1 || \ + { echo "ERROR: $ini should have exactly one auto_prepend_file line" >&2; exit 1; }; } && \ echo ' /tmp/vcs-check.php && \ seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ for bin in "frankenphp php-cli" php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = "$prepend" || \ + { echo "ERROR: auto_prepend_file is not $prepend ($bin)" >&2; exit 1; }; \ test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \ diff --git a/php/8.5/frankenphp/Dockerfile b/php/8.5/frankenphp/Dockerfile index c04d72c..d059963 100644 --- a/php/8.5/frankenphp/Dockerfile +++ b/php/8.5/frankenphp/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 ARG FRANKENPHP_VERSION=1.14.0 ARG PHP_VERSION=8.5 FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine @@ -145,17 +146,24 @@ COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer # it. auto_prepend_file runs before every PHP script, WordPress or not, so # the file only touches $GLOBALS['wp_filter'] and only when the variable is # "1". If getenv is in PHP_DISABLE_FUNCTIONS it can't read the variable and -# does nothing. It lives outside /app and conf.d, root-owned and read-only -# to appuser; docker-configure adds its directory to PHP_OPEN_BASEDIR. The -# ini is named 00-* so any later conf.d file (a derived image's -# wordfence.ini, say) that sets its own auto_prepend_file wins. +# does nothing. It lives outside /app, and docker-configure adds its +# directory to PHP_OPEN_BASEDIR. +# +# The directive goes in php.ini itself, replacing its "auto_prepend_file =" +# line in place, not in a conf.d file: PHP reads conf.d after php.ini, so a +# derived image that sets its own auto_prepend_file (a Wordfence WAF, say), +# by editing that line, appending one or adding any conf.d file, wins. The +# prepend file and php.ini are root-owned and read-only to appuser. appuser +# (group 0) can write conf.d, so it can override this directive there, as it +# can any other PHP setting. +# # php/8.{2,3,4,5}/frankenphp/Dockerfile and php/8.4/cli/Dockerfile.wordpress # carry this same block; keep them in sync. # --------------------------------------------------------------------------- COPY <<'PHP' /usr/local/share/php-prepend/wordpress-vcs-checkout.php '__return_true', @@ -164,20 +172,31 @@ if (function_exists('getenv') && getenv('WORDPRESS_VCS_CHECKOUT') === '1') { } PHP -# There is only one auto_prepend_file. Fail the build if the upstream image -# ever sets one, rather than silently replacing it (chain to it from the file -# above if that happens). Then run a real script both ways: the filter is -# seeded only with the exact value "1". -RUN for bin in "frankenphp php-cli" php; do \ +# There is only one auto_prepend_file. Fail the build if php.ini is missing or +# the upstream image already sets one, rather than silently replacing it +# (chain to it from the file above if that happens). Then set it in php.ini +# and run a real script both ways: the filter is seeded only with the exact +# value "1". +RUN ini="$PHP_INI_DIR/php.ini" && \ + prepend=/usr/local/share/php-prepend/wordpress-vcs-checkout.php && \ + { test -f "$ini" || { echo "ERROR: $ini is missing" >&2; exit 1; }; } && \ + for bin in "frankenphp php-cli" php; do \ $bin -r 'exit(ini_get("auto_prepend_file") === "" ? 0 : 1);' || \ { echo "ERROR: upstream image already sets auto_prepend_file ($bin)" >&2; exit 1; }; \ done && \ - echo 'auto_prepend_file = /usr/local/share/php-prepend/wordpress-vcs-checkout.php' \ - > "$PHP_INI_DIR/conf.d/00-wordpress-vcs-checkout.ini" && \ + if grep -q '^auto_prepend_file[[:space:]]*=' "$ini"; then \ + sed -i "s|^auto_prepend_file[[:space:]]*=.*|auto_prepend_file = $prepend|" "$ini"; \ + else \ + printf '\nauto_prepend_file = %s\n' "$prepend" >> "$ini"; \ + fi && \ + { test "$(grep -c '^auto_prepend_file[[:space:]]*=' "$ini")" = 1 || \ + { echo "ERROR: $ini should have exactly one auto_prepend_file line" >&2; exit 1; }; } && \ echo ' /tmp/vcs-check.php && \ seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}' && \ for bin in "frankenphp php-cli" php; do \ + test "$($bin -r 'echo ini_get("auto_prepend_file");')" = "$prepend" || \ + { echo "ERROR: auto_prepend_file is not $prepend ($bin)" >&2; exit 1; }; \ test "$(WORDPRESS_VCS_CHECKOUT=1 $bin /tmp/vcs-check.php)" = "$seeded" || \ { echo "ERROR: WORDPRESS_VCS_CHECKOUT=1 did not seed the filter ($bin)" >&2; exit 1; }; \ test "$(WORDPRESS_VCS_CHECKOUT=true $bin /tmp/vcs-check.php)" = none || \