Repository navigation
Add WORDPRESS_VCS_CHECKOUT to keep WordPress auto-updates off - #20
Merged
Merged
Conversation
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.
Member
Author
Review round 1 (head 103bfe1)The code-review skill ran at high. No P1. Pre-seeding matches WordPress 7.1.5's Fixing:
Declined:
|
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.
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:
Fixing:
|
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Needed by aliasproject/alios ALI-2082.
What
A new opt-in variable,
WORDPRESS_VCS_CHECKOUT, for every frankenphp image. Unset by default; the exact value1turns it on.php/8.{2,3,4,5}/frankenphp/Dockerfilenow ships/usr/local/share/php-prepend/wordpress-vcs-checkout.php(root-owned, 644, in a root-owned 755 directory, so read-only toappuser) and sets it as PHP'sauto_prepend_filein$PHP_INI_DIR/php.ini, replacing that file's existingauto_prepend_file =line in place (or appending one if there isn't one).dev,wordpressandwordpress-devare builtFROMthe base, so they inherit it. A WordPress site on the base image (framework not flagged) is covered too.WORDPRESS_VCS_CHECKOUT=1(andgetenvexists), 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_filterentries into hooks (WP_Hook::build_preinitialized_hooks), soWP_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.gitin the site folder. With any other value, or unset, the file does nothing.getenvis inPHP_DISABLE_FUNCTIONS, the file can't read the variable and does nothing (no fatal).php.ini, not aconf.dfile, because PHP readsconf.dafterphp.ini. A derived image that sets its ownauto_prepend_file(a Wordfence WAF, say) wins whether it edits thatphp.iniline, appends its own line or adds anyconf.dfile (000-waf.iniandwordfence.iniboth tested).php.iniis root-owned and read-only toappuser;appuser(group 0) can writeconf.d, as before this PR, so it can override the directive there like any other PHP setting.php.iniis missing, if the upstream image ever sets anauto_prepend_file(instead of silently replacing it), ifphp.inidoesn't end up with exactly oneauto_prepend_fileline, or if PHP doesn't then report the prepend file. It then runs a real script under bothfrankenphp php-cliandphpwith the variable=1,=trueand unset, and fails unless only1seeds the filter.docker-configure(all four versions): whenPHP_OPEN_BASEDIRis set, it appends:/usr/local/share/php-prepend/. Without this, every request withPHP_OPEN_BASEDIRset would return 500 ("Failed opening required …wordpress-vcs-checkout.php"), whether or not the variable was set.php/8.4/cli/Dockerfile.wordpresscarries the same file,php.inichange and build check, so WP-CLI in a separate CLI container behaves the same. WP-CLI run withdocker execin 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,=1withPHP_OPEN_BASEDIR=/app:/tmp, and=1withPHP_DISABLE_FUNCTIONS=getenv(each must serve the app; the first two must seed the filter, the last must not). For acliimage that has the prepend file, checks it both ways; adocker runthat fails fails the check rather than reading as "no file" (CI doesn't buildcli-wordpress, so that part runs only by hand).The PHP file is a
COPYheredoc 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
.gitat or above the code it would update. Alios deploys WordPress sites from git with the site folder bind-mounted at/app, and is moving.gitout 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: onlyWP_Automatic_Updaterand Site Health read this filter.CI rebuilds
A change to
php/X/frankenphp/Dockerfileordocker-configurealready triggers every frankenphp job for that version inbuild-and-push.yml:build-frankenphp-base, thenbuild-frankenphp-dependent(dev,wordpress) andbuild-frankenphp-wordpress-dev, whose conditions include the base files. So merging this rebuilds all 16 frankenphp images.php/8.4/cli/Dockerfile.wordpressisn't built by the workflow.Testing
Built locally from this branch:
8.4-frankenphp,8.4-frankenphp-dev,8.4-frankenphp-wordpressand8.4-frankenphp-wordpress-dev(each variant built against the local base),8.4-cliand8.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 loadswp-load.phpand prints the values, requested over HTTP:apply_filters(…, false, ABSPATH)is_vcs_checkout(ABSPATH)is_vcs_checkout(WP_PLUGIN_DIR)=1=truePHP_OPEN_BASEDIR=/app:/tmp,=1PHP_DISABLE_FUNCTIONS=getenv,=1=1=truePHP_OPEN_BASEDIR=/app:/tmp, unsetPHP_OPEN_BASEDIR=/app:/tmp,=1PHP_DISABLE_FUNCTIONS=getenv,exec,…,=1=1=1auto_prepend_fileline inphp.ini, unset /=1auto_prepend_fileline tophp.ini, unset /=1conf.d/000-waf.ini, unset /=1conf.d/wordfence.ini, unset /=1evalviadocker exec, unsetevalviadocker exec,=1wp eval, unsetwp eval,=1wp eval,=trueEvery 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 activeauto_prepend_file(over HTTP and forphprun withdocker exec) and ran, and ours didn't.phprun withdocker execin every frankenphp container reports the sameauto_prepend_fileas the web request. On the CLI image, a plain script withgetenvdisabled and=1runs normally.Also checked:
appusercan't write to the prepend file or create files in its directory.ERROR: WORDPRESS_VCS_CHECKOUT=true seeded the filter (frankenphp php-cli)..github/scripts/smoke-test.shpasses forbase,dev,wordpress,wordpress-dev, andcli(on both8.4-cliand8.4-cli-wordpress). Withdockershimmed so the CLI file check'sdocker runexits 125, theclismoke test now fails (the WORDPRESS_VCS_CHECKOUT file check did not run).docker-configurechanges are identical to 8.4; only 8.4 was built locally.Notes
php/8.4/cli/Dockerfile.wordpressisn't built bybuild-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.$wp_filterarray with one entry. That only matters to code that uses a global of that name.open_basedirother than throughPHP_OPEN_BASEDIRhas to add/usr/local/share/php-prepend/itself (README says so).Dockerfile.devandDockerfile.wordpress-devget it by inheritance and need no change. Keeping it there matches production: it stays off unless the variable is set, and dev clearsPHP_DISABLE_FUNCTIONS, sogetenvis available.