Repository navigation
[3.0] Improves file integrity checks in installer and upgrader - #9679
Sesquipedalian merged 6 commits into
Conversation
d288f76 to
04ba7a7
Compare
04ba7a7 to
e8214f3
Compare
|
I like where this is going — the existence spot-check has never been worth much, and a real manifest is the right replacement. A few findings from reading it and exercising the parts that can be run today. First, a framing note that explains why the rest of this is a list rather than a nit or two: as submitted, none of this code can execute. 1. Blocker — the structure check fatals
The short-circuit makes it unavoidable: as soon as So the first release that ships a 2. The debug message can never be shownBoth tools set Two consequences:
Moving the read into the constructor is right; it needs to land after 3. The manifest leaves out 19 files that we ship
Two more faults in the same filter:
4. The release workflow can't commit the manifest
Related: 5. Smaller things
6. One more pending PR is affected#9120 looks fine to me — its But #9681 ("Add PHP version constraint to composer.json") adds That takes out both 7. Tests
A fixture-manifest test over |
This is intentional. During development, we don't want to have to maintain the manifest. Instead, when a reviewer wants to test anything related to the installer or upgrader, then the reviewer can run ./other/update_manifest.php on demand before starting the install or upgrade process. This is similar to how a reviewer must first copy ./other/install.php or ./other/upgrade.php before beginning the install or upgrade process. Still, to help ease that process for automated systems, 384c79e adds some code to .docker/php/entrypoint.sh that will automatically generate manifest.json if it is missing.
Fixed in bf7e63e.
Fixed in bbd4c7a.
Fixed in adadb9f. Also worth noting that
Fixed in 3a4d375, with a followup in b1e4da1.
Fixed in adadb9f.
Fixed in 1eb36b0.
Fixed in bd72844.
Fixed in 4af75cd.
Fixes in adadb9f.
Added in 4af75cd. |
|
Thanks — I went back over all of it, and this time built a real manifest rather than reading the code: cloned the branch, ran The fixes hold up. Baseline behaviour on a pristine tree: That is the design doing exactly what it says, and the cost is not worth worrying about — ~70 ms for 2000 files. Four things still to fix, and one thing I hadn't thought to look at the first time. 1. CI is red — the new test can't run
The docblock on the provider already says 2. The
|
No. If the admin asks for debug info, they get debug info. That means a list of all the missing files. |
Excellent idea. This has now been implemented. All other issues have now been addressed. |
|
I took this further than reading the diff: I stood up an isolated stack on the branch, restored a real SMF 2.1.7 forum into it, uploaded 3.0 over the top and ran The good news first, because it is most of the story. The checks work. A clean tree installs; deleting Everything below is what is still wrong. 1. A real 2.1 → 3.0 upgrade is blocked at step 1This is the one I would hold the PR for. On a genuine 2.1.7 forum with the 3.0 package uploaded over it: The culprits: Both are the 2.1 stubs, and they are still 2.1's because those two directories hold the forum's own data — member uploads and avatars — so they survive an upgrade upload when every other directory is replaced. The two versions are not close: // 2.1 attachments/index.php
if (file_exists(dirname(dirname(__FILE__)) . '/Settings.php'))
{
require(dirname(dirname(__FILE__)) . '/Settings.php');
header('location: ' . $boardurl);
}// 3.0 stub
if (file_exists(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'index.php')) {
include dirname(__DIR__) . DIRECTORY_SEPARATOR . 'index.php';
}and the manifest gives both an MD5. I confirmed the diagnosis by copying the 3.0 stub over those two files and changing nothing else — the same run then went all the way through: Ten checksummed entries sit in directories a live forum owns: 2.
|
The upgrade packages that Simple Machines builds and provides on its website include fresh copies of the index.php and .htaccess files within the attachments, custom_avatar, avatars, Packages, and Smileys directories. Therefore, uploading the entire upgrade package will replace those files on the live forum. If those files fail the checksum test, that means the forum's administrator did not upload the complete package, and the solution is to upload the files that they left out.
Fixed in 8c2b24b.
Fixed in fd43552.
Fixed in fd43552.
Fixed in f773487.
SMF does not support moving ./Themes to a custom location. Therefore, producing failures in this situation is correct.
Fixed in ab0f02a.
Fixed in f773487.
Fixed in 26247cb.
This is not a concern. There are no symlinks in the SMF repository, and no pull request adding one will ever be approved. It is worth noting that Git treats symlinks as opaque files (meaning, using
Fixed in fd43552. |
|
Re-ran everything against Verified fixedEach one checked by running it, not by reading the diff:
Withdrawing the upgrade-block findingYou're right and I'll drop it. I couldn't verify package contents independently — the download site is behind Cloudflare and there's no packaging script in the repo — and you're the one who builds them. I did check the one thing that could still have bitten: whether SMF's own Also taking your point on symlinks — git storing them opaquely plus the dirty-tree guard does close that off. And Themes is your call; I'll note only that Newly covered, all passingThese were the parts with no coverage at all, so they seemed worth exercising before the PR lands. Version sectioning — the actual novel idea here, and in my earlier upgrade run both sections passed trivially, so it proved nothing. Deleting a file that exists only in the 2.1 section: Consulted on a major upgrade, invisible to a patch upgrade and to a fresh install. Exactly as designed. A relocated PostgreSQL. A real 2.1.7 baseline restored into a Postgres stack (0 errors on load), 3.0 uploaded over it, Afterwards: (Two unrelated things showed up in that log and I'll leave them out of this PR: 2.1-era rows still in Still open1. The entrypoint crash loop is only half fixed. The filename is right now, but php -f "$BOARD_DIR/other/update_manifest.php" 2>/dev/nullAny non-zero exit aborts the script before 2. A A truncated upload through a proxy leaves an error page as readily as a half-written file. The detection is right; only the contents leaking first is the problem, and an 3. $this->debug = isset($_REQUEST['debug']);That's the same One for a different PR
Line 50 reads This is pre-existing on release-3.0 (it arrived with 8173ba6, and this PR touches the file with a single line), so it isn't yours to fix here. I mention it only because this PR makes that script the sole way a manifest is ever produced, and passing an explicit version is exactly what you'd do when tagging a milestone. Say the word and I'll open it separately. |
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
3ba55bc to
1011d21
Compare
|
All issues have been addressed, and I have rebased to clean up the commit history. The fatal error in prepare_release.php has also been fixed, so no need for a separate PR. |
Until now, the installer and upgrader have only checked for the existence of certain files as their way of verifying that the package was uploaded successfully. But that is not very reliable.
This PR adds code to generate a complete manifest of all of SMF's files, which is stored in ./Sources/Maintenance/manifest.php. Then the installer and upgrader check the manifest to make sure all the required files are present.
Structure of manifest.php
The content of manifest.php looks like this:
At the top level, the array keys are version numbers and the values are lists of files.
Within each version's list of files, each key is the relative path of a file that must exist, and each value is either a checksum or else a boolean
true.The
truevalue means that the file (or directory, as the case may be) must exist, but that it is allowed to have arbitrary content. The reason to usetruefor a file is to ensure that the installer and upgrader won't choke if, for example, the admin has replaced the default smiley images or customized the content of agreement.txt, etc. The other situation wheretrueis used is when we want to check for the existence of a directory inside ./vendor. In that situation, we don't control the content of the directory, so we just check that the directory itself exists and move on.If the value is a checksum, then the content of the file may be validated using that checksum (see below for details).
How the manifest is used
Both the installer and the upgrader use the manifest to verify that all expected files exist and, optionally, that they have the expected content.
Installer
The installer will walk through the list of files for the version being installed (e.g. the files in the
3.0list when installing SMF 3.0).For each file in the list, the installer will check whether it exists. Moreover, if the manifest provided a checksum for that file, then that checksum will be used to verify that the content of that file is as expected.
Upgrader
The upgrader will walk through not only the
3.0list of files, but also the list of files for whatever version the upgrader is starting from and the lists of files for any intervening versions as well. For example, if upgrading from SMF 2.1.8 to SMF 3.0.1, the upgrader will walk through both the3.0list of files and the2.1list of files.Like the installer, the upgrader will check whether each file exists. However, whether the upgrader uses the checksum to validate the file content is complicated:
Special handling during active development
During active development, our files are changing all the time. In order to avoid driving us all insane while developing, two forms of special handling are built into the process that checks the manifest:
You may have already noticed that this PR does not actually include a manifest.php file. This is intentional. My plan is that we will only generate and commit a manifest as part of tagging a completed milestone version in Git. Then the very next commit will remove the manifest.php file again. Since that same commit will also involve changing the version number to the next '*-dev' version (see #9674), this will ensure that the second form of special handling kicks back in so that we don't need to continually update the manifest while working on the rest of code.
Compatibility with other pending pull requests
Generally speaking, this change won't affect anything else. The one relevant pending pull request is #9120, which adds migration steps, etc., for upgrading from SMF 1.1, SMF 1.0, and YaBB SE. But even when #9120 has been merged, all that will actually change is that the manifest will contain additional sections listing the files required to perform an upgrade from those earlier versions.