Skip to content

Add WORDPRESS_VCS_CHECKOUT to keep WordPress auto-updates off - #20

Merged
michaelaguiar merged 3 commits into
mainfrom
feat/wordpress-vcs-checkout-env
Nov 26, 2026
Merged

michaelaguiar merged 3 commits into
mainfrom
feat/wordpress-vcs-checkout-env

Conversation

@michaelaguiar

@michaelaguiar michaelaguiar commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Needed by aliasproject/alios ALI-2082.

What

A new opt-in variable, WORDPRESS_VCS_CHECKOUT, for every frankenphp image. Unset by default; the exact value 1 turns it on.

  • The base php/8.{2,3,4,5}/frankenphp/Dockerfile now ships /usr/local/share/php-prepend/wordpress-vcs-checkout.php (root-owned, 644, in a root-owned 755 directory, so read-only to appuser) and sets it as PHP's auto_prepend_file in $PHP_INI_DIR/php.ini, replacing that file's existing auto_prepend_file = line in place (or appending one if there isn't one). dev, wordpress and wordpress-dev are built FROM the base, so they inherit it. A WordPress site on the base image (framework not flagged) is covered too.
  • When WORDPRESS_VCS_CHECKOUT=1 (and getenv exists), the file appends ['function' => '__return_true', 'accepted_args' => 1] to $GLOBALS['wp_filter']['automatic_updates_is_vcs_checkout'][10]. WordPress 4.7+ turns pre-seeded $wp_filter entries into hooks (WP_Hook::build_preinitialized_hooks), so WP_Automatic_Updater::is_vcs_checkout() returns true for every context and background auto-updates of core, plugins, themes and translations stay off, exactly as with a .git in the site folder. With any other value, or unset, the file does nothing.
  • If getenv is in PHP_DISABLE_FUNCTIONS, the file can't read the variable and does nothing (no fatal).
  • It's in php.ini, not a conf.d file, because PHP reads conf.d after php.ini. A derived image that sets its own auto_prepend_file (a Wordfence WAF, say) wins whether it edits that php.ini line, appends its own line or adds any conf.d file (000-waf.ini and wordfence.ini both tested). php.ini is root-owned and read-only to appuser; appuser (group 0) can write conf.d, as before this PR, so it can override the directive there like any other PHP setting.
  • The build fails if php.ini is missing, if the upstream image ever sets an auto_prepend_file (instead of silently replacing it), if php.ini doesn't end up with exactly one auto_prepend_file line, or if PHP doesn't then report the prepend file. It then runs a real script under both frankenphp php-cli and php with the variable =1, =true and unset, and fails unless only 1 seeds the filter.
  • docker-configure (all four versions): when PHP_OPEN_BASEDIR is set, it appends :/usr/local/share/php-prepend/. Without this, every request with PHP_OPEN_BASEDIR set would return 500 ("Failed opening required …wordpress-vcs-checkout.php"), whether or not the variable was set.
  • php/8.4/cli/Dockerfile.wordpress carries the same file, php.ini change and build check, so WP-CLI in a separate CLI container behaves the same. WP-CLI run with docker exec in a frankenphp container is already covered by the frankenphp image.
  • .github/scripts/smoke-test.sh: for every frankenphp variant, checks the prepend file exists, the filter isn't seeded with the variable unset, and boots three more containers: =1, =1 with PHP_OPEN_BASEDIR=/app:/tmp, and =1 with PHP_DISABLE_FUNCTIONS=getenv (each must serve the app; the first two must seed the filter, the last must not). For a cli image that has the prepend file, checks it both ways; a docker run that fails fails the check rather than reading as "no file" (CI doesn't build cli-wordpress, so that part runs only by hand).
  • README: new "Auto-updates on sites deployed from git" subsection under WordPress hardening.

The PHP file is a COPY heredoc in each Dockerfile rather than a separate file, so editing it changes the Dockerfile itself. Every Dockerfile that uses one starts with # syntax=docker/dockerfile:1.

Why

WordPress skips background auto-updates when it finds a .git at or above the code it would update. Alios deploys WordPress sites from git with the site folder bind-mounted at /app, and is moving .git out of that folder (ALI-2082). Without this, those sites would start auto-updating core and rewriting git-deployed code. Manual updates (wp-admin, wp core update) aren't affected: only WP_Automatic_Updater and Site Health read this filter.

CI rebuilds

A change to php/X/frankenphp/Dockerfile or docker-configure already triggers every frankenphp job for that version in build-and-push.yml: build-frankenphp-base, then build-frankenphp-dependent (dev, wordpress) and build-frankenphp-wordpress-dev, whose conditions include the base files. So merging this rebuilds all 16 frankenphp images. php/8.4/cli/Dockerfile.wordpress isn't built by the workflow.

Testing

Built locally from this branch: 8.4-frankenphp, 8.4-frankenphp-dev, 8.4-frankenphp-wordpress and 8.4-frankenphp-wordpress-dev (each variant built against the local base), 8.4-cli and 8.4-cli-wordpress. WordPress 7.1.5 (with the SQLite drop-in, installed with WP-CLI) mounted at /app, SERVER_ROOT=/app, and a page that loads wp-load.php and prints the values, requested over HTTP:

Image / env apply_filters(…, false, ABSPATH) is_vcs_checkout(ABSPATH) is_vcs_checkout(WP_PLUGIN_DIR)
base, unset false false false
base, =1 true true true
base, =true false false false
base, PHP_OPEN_BASEDIR=/app:/tmp, =1 true true true
base, PHP_DISABLE_FUNCTIONS=getenv, =1 false false false
wordpress, unset false false false
wordpress, =1 true true true
wordpress, =true false false false
wordpress, PHP_OPEN_BASEDIR=/app:/tmp, unset false false false
wordpress, PHP_OPEN_BASEDIR=/app:/tmp, =1 true true true
wordpress, PHP_DISABLE_FUNCTIONS=getenv,exec,…, =1 false false false
wordpress-dev, unset false false false
wordpress-dev, =1 true true true
dev, =1 true true true
derived from wordpress, edits the auto_prepend_file line in php.ini, unset / =1 false / false false / false false / false
derived, appends an auto_prepend_file line to php.ini, unset / =1 false / false false / false false / false
derived, adds conf.d/000-waf.ini, unset / =1 false / false false / false false / false
derived, adds conf.d/wordfence.ini, unset / =1 false / false false / false false / false
base, WP-CLI eval via docker exec, unset false false n/a
base, WP-CLI eval via docker exec, =1 true true n/a
cli-wordpress via wp eval, unset false false n/a
cli-wordpress via wp eval, =1 true true n/a
cli-wordpress via wp eval, =true false false n/a

Every request returned 200 and the home page rendered. A plain non-WordPress PHP file served normally in each case; it sees $wp_filter (one entry) only with =1, and in all four derived images the Wordfence-style prepend was the active auto_prepend_file (over HTTP and for php run with docker exec) and ran, and ours didn't. php run with docker exec in every frankenphp container reports the same auto_prepend_file as the web request. On the CLI image, a plain script with getenv disabled and =1 runs normally.

Also checked:

  • appuser can't write to the prepend file or create files in its directory.
  • A copy of the base Dockerfile whose prepend file seeds the filter for any value fails the build with ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter (frankenphp php-cli).
  • .github/scripts/smoke-test.sh passes for base, dev, wordpress, wordpress-dev, and cli (on both 8.4-cli and 8.4-cli-wordpress). With docker shimmed so the CLI file check's docker run exits 125, the cli smoke test now fails (the WORDPRESS_VCS_CHECKOUT file check did not run).
  • The block added to the 8.2, 8.3 and 8.5 base Dockerfiles and their docker-configure changes are identical to 8.4; only 8.4 was built locally.

Notes

  • php/8.4/cli/Dockerfile.wordpress isn't built by build-and-push.yml, so no published CLI image carries this yet. Whatever builds the WP-CLI image for sites needs to rebuild from this Dockerfile to get it. The published images cover web requests, and WP-Cron when a web request runs it.
  • With the variable set, non-WordPress PHP sees a global $wp_filter array with one entry. That only matters to code that uses a global of that name.
  • An image that sets open_basedir other than through PHP_OPEN_BASEDIR has to add /usr/local/share/php-prepend/ itself (README says so).
  • Dockerfile.dev and Dockerfile.wordpress-dev get it by inheritance and need no change. Keeping it there matches production: it stays off unless the variable is set, and dev clears PHP_DISABLE_FUNCTIONS, so getenv is available.

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.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 1 (head 103bfe1)

The code-review skill ran at high. No P1. Pre-seeding matches WordPress 7.1.5's build_preinitialized_hooks; there's no output or notice on PHP 8.2–8.5; the open_basedir append and the heredoc COPY are sound in CI.

Fixing:

  • P2, getenv disabled: a site with getenv in PHP_DISABLE_FUNCTIONS fatals on every request. Fix: function_exists('getenv') && getenv('WORDPRESS_VCS_CHECKOUT') === '1'.
  • P2, a derived image's auto_prepend_file is silently overridden: wordpress-vcs-checkout.ini sorts after files like wordfence.ini, so it wins. Fix: name it 00-wordpress-vcs-checkout.ini, so any later conf.d file overrides it, and keep the README sentence accurate.
  • Coverage: ship the prepend file and ini in the base frankenphp images (8.2–8.5), not only -wordpress, so a WordPress site on the base image (framework not flagged) is covered too. It stays opt-in and does nothing when the variable is unset. The WordPress variants inherit it; remove the duplicate blocks from them.
  • P3, local build on a stale base: the guard fails the build if the base's docker-configure lacks the prepend-directory handling. This is moot once it all lives in the base image; just make sure it's consistent.
  • P3, build checks never run the file: run a real script with WORDPRESS_VCS_CHECKOUT=1 at build time and assert the filter is seeded, and that nothing is seeded when the variable is unset.
  • P3, README: say the published images cover web requests and WP-Cron run by web requests. The cli Dockerfile.wordpress has it but isn't published by CI. Replace "never affects non-WordPress code" with the accurate wording (only a global $wp_filter with one entry when the variable is set).
  • P3, CI: extend smoke-test.sh to check the variable both ways, and once with PHP_OPEN_BASEDIR set.

Declined:

  • open_basedir set other than through PHP_OPEN_BASEDIR: custom images only, and Alios never sets it. One README line covers it.

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.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 2 (head 7dd6c2c)

The code-review skill ran at high. No P1. All round-1 items are in. Checked for non-WordPress apps:

  • the per-request cost is negligible (opcache, no stat);
  • profiler extensions don't use auto_prepend_file, so they're unaffected;
  • in Octane worker mode the prepend runs once per worker boot, with no effect while the variable is unset;
  • the arm64 build check is safe.

Fixing:

  • P2, a derived image's php.ini prepend is overridden: conf.d loads after php.ini, so 00-wordpress-vcs-checkout.ini beats auto_prepend_file set in a derived image's php.ini (for example, a Wordfence WAF). Fix: drop the conf.d file and set the directive in $PHP_INI_DIR/php.ini itself, replacing its existing auto_prepend_file = line in place (or appending if there isn't one). A derived image that edits that line, appends its own, or adds any conf.d file then wins. Check php.ini exists in every image (frankenphp and cli). Test both php.ini and conf.d overrides.
  • P3, the CLI smoke check never runs in CI and skips silently: make a docker run failure fail the check, rather than reading it as "no file".
  • P3, the cli/Dockerfile.wordpress RUN mixes ;, && and ||: chain it like the frankenphp version, so the right error is reported.
  • P3, README on WP-CLI: wp run with docker exec in a frankenphp container is covered. Only a separate CLI container needs cli/Dockerfile.wordpress. Also correct the php.ini sentence.
  • P3, heredoc without a syntax line: add # syntax=docker/dockerfile:1 to every Dockerfile using COPY <<.
  • Comment wording: "root-owned" overstates it, because appuser (group 0) can write conf.d (true before this PR too). Word it accurately.

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 <<heredoc starts with
  "# syntax=docker/dockerfile:1".
- Comments no longer call the setup root-owned as a whole: the prepend
  file and php.ini are, but appuser (group 0) can write conf.d.
- README: WP-CLI run with docker exec in a frankenphp container is
  covered; only a separate CLI container needs cli/Dockerfile.wordpress.
  The override sentence now describes php.ini and conf.d.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review loop finished (2 rounds plus a final read of the round-2 diff; no P1). Local 8.4 builds of base, dev, wordpress, wordpress-dev, cli and cli-wordpress pass their build checks and smoke-test.sh. 8.2, 8.3 and 8.5 carry the identical block; their build checks first run in CI on merge.

Merge and publish this before deploying aliasproject/alios#242 (ALI-2082). Merging rebuilds all 16 frankenphp images.

@michaelaguiar
michaelaguiar marked this pull request as ready for review November 25, 2026 22:42
@michaelaguiar
michaelaguiar merged commit 5019fae into main Nov 26, 2026
2 checks passed
@michaelaguiar
michaelaguiar deleted the feat/wordpress-vcs-checkout-env branch November 26, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant