From 0d515aa3bfc890d4dd183e29f779c3d99a400f92 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Sun, 29 Nov 2026 02:54:27 +0100 Subject: [PATCH] Validate privately staged MCGUI prerequisite by reviewed hash and identity --- DuneMenus/docs/FLEET-INSTALL.md | 5 ++++- tools/install-plugin-fleet.py | 31 ++++++++++++++++++++++++--- tools/test_plugin_fleet_install.py | 34 ++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/DuneMenus/docs/FLEET-INSTALL.md b/DuneMenus/docs/FLEET-INSTALL.md index 2a92932f..aaa4a4ee 100644 --- a/DuneMenus/docs/FLEET-INSTALL.md +++ b/DuneMenus/docs/FLEET-INSTALL.md @@ -1,6 +1,6 @@ # Verified plugin fleet installation -Use only the installer and JARs emitted together by canonical plugin CI. This installer is for existing servers, not bootstrap provisioning. It never discovers or guesses server paths, assigns plugins to a server, removes unrelated backends, deploys website files, or installs private third-party dependencies. +Use only the installer and JARs emitted together by canonical plugin CI. This installer is for existing servers, not bootstrap provisioning. It never discovers or guesses server paths, assigns plugins to a server, removes unrelated backends, deploys website files, or downloads third-party dependencies. The coordinator supplies an independently verified inventory JSON. Each `servers` entry requires `id`, absolute `root`, existing `serviceUnit`, and an explicit list of artifact filenames from `release-manifest.json`. Do not populate these from historical example paths. DuneMenus requires JARVIS, DunerealmsGUI and the existing MCGUI runtime; DuneNPC is retained. @@ -9,3 +9,6 @@ First run a read-only plan with `--artifacts`, `--inventory`, and `--expected-so All artifacts, descriptors, installed-file snapshots and backups are verified. Services must be fully stopped before JAR replacement; active services restart afterward, previously stopped services remain stopped. Old filenames are replaced by actual plugin identity. On an installation/start failure, original bytes and filenames are restored after verifying the service is stopped, and a rollback receipt is retained. A rollback that cannot stop the service halts without replacing active JARs. A multi-server failure may leave earlier servers installed; inspect each receipt. An `installed-service-active` receipt proves file installation and systemd state only. It does not prove Minecraft finished loading or an NPC interaction worked. Verify server logs, enabled versions, resource-pack publication/configuration, actual GUI/NPC actions and retained progression separately before reporting rollout complete. Resource-pack hosting/configuration is not changed by this JAR installer. + + +A missing existing MCGUI runtime may be staged privately by the authorised coordinator. Inventory `privatePrerequisites.MCGUI` requires an absolute `path` and the reviewed SHA-256 `69a454291cc27c36cdbc680bfbde245a90a3913de53cc1591c502a5a49124300`; the server entry must explicitly list `prerequisites: ["MCGUI"]`. The installer verifies plugin name MCGUI, version0.8.6 and main ai.resourcepack.ui.MCGUIPlugin before including those privately staged bytes. They are never added to the public source/release artifact. Unknown private prerequisites or different bytes/identities fail planning. The private runtime's installation and rollback follow the same stopped-service, backup and checksum path as first-party JARs. diff --git a/tools/install-plugin-fleet.py b/tools/install-plugin-fleet.py index d9b7aa3a..a67d9003 100644 --- a/tools/install-plugin-fleet.py +++ b/tools/install-plugin-fleet.py @@ -15,6 +15,13 @@ import tempfile import zipfile +PRIVATE_PREREQUISITES = { + 'MCGUI': {'sha256': '69a454291cc27c36cdbc680bfbde245a90a3913de53cc1591c502a5a49124300', + 'name': 'MCGUI', 'version': '0.8.6', 'main': 'ai.resourcepack.ui.MCGUIPlugin', + 'filename': 'MCGUI-0.8.6.jar'} +} + + def digest(path): return hashlib.sha256(Path(path).read_bytes()).hexdigest() @@ -52,6 +59,19 @@ def plan(artifacts, inventory, expected_source): raise ValueError('Unapproved or duplicate plugin identity: ' + actual['name']) names.add(actual['name'].casefold()) files[name] = dict(entry, source=str(path)) + prerequisites = {} + for key, item in inventory.get('privatePrerequisites', {}).items(): + if key not in PRIVATE_PREREQUISITES: + raise ValueError('Private prerequisite has no reviewed identity/hash: ' + key) + expected = PRIVATE_PREREQUISITES[key] + path = Path(item['path']) + if not path.is_absolute() or path.is_symlink() or not path.is_file(): + raise ValueError('Private prerequisite path must identify an existing regular file') + if digest(path) != expected['sha256'] or item.get('sha256') != expected['sha256']: + raise ValueError('Private prerequisite differs from reviewed bytes: ' + key) + if identity(path) != {field: expected[field] for field in ('name', 'version', 'main')}: + raise ValueError('Private prerequisite identity differs: ' + key) + prerequisites[key] = dict(expected, source=str(path.resolve()), privatePrerequisite=True) servers, ids, roots, units = [], set(), set(), set() for server in inventory['servers']: sid, unit = server['id'], server['serviceUnit'] @@ -69,7 +89,11 @@ def plan(artifacts, inventory, expected_source): selected = server['artifacts'] if not selected or len(set(selected)) != len(selected) or any(name not in files for name in selected): raise ValueError('Server requires an explicit valid artifact list') - wanted = {files[name]['name'].casefold() for name in selected} + selected_prerequisites = server.get('prerequisites', []) + if len(set(selected_prerequisites)) != len(selected_prerequisites) or any(key not in prerequisites for key in selected_prerequisites): + raise ValueError('Server private prerequisites must be explicitly provided and reviewed') + chosen = [files[name] for name in selected] + [prerequisites[key] for key in selected_prerequisites] + wanted = {entry['name'].casefold() for entry in chosen} previous = [] existing_identities = set() for old in plugins.glob('*.jar'): @@ -86,11 +110,12 @@ def plan(artifacts, inventory, expected_source): raise ValueError('DuneMenus requires preserved JARVIS, DunerealmsGUI and the existing MCGUI runtime') # Never overwrite a differently named plugin that happens to occupy a release filename. old_names = {row['filename'] for row in previous} - for name in selected: + for entry in chosen: + name = entry['filename'] if (plugins / name).exists() and name not in old_names: raise ValueError('Artifact filename collides with another plugin: ' + name) servers.append({'id': sid, 'root': str(root), 'serviceUnit': unit, - 'artifacts': [files[name] for name in selected], 'previous': previous}) + 'artifacts': chosen, 'previous': previous}) ids.add(sid); roots.add(root); units.add(unit) if not servers: raise ValueError('Explicit fleet inventory is empty') diff --git a/tools/test_plugin_fleet_install.py b/tools/test_plugin_fleet_install.py index 669fe40a..e80f105f 100644 --- a/tools/test_plugin_fleet_install.py +++ b/tools/test_plugin_fleet_install.py @@ -4,6 +4,7 @@ from pathlib import Path import subprocess import tempfile import unittest +from unittest.mock import patch import zipfile spec = importlib.util.spec_from_file_location('installer', Path(__file__).with_name('install-plugin-fleet.py')) @@ -12,9 +13,9 @@ spec.loader.exec_module(installer) SOURCE = 'a' * 40 -def jar(path, name, version='1'): +def jar(path, name, version='1', main='example.Main'): with zipfile.ZipFile(path, 'w') as archive: - archive.writestr('plugin.yml', f'name: {name}\nversion: {version}\nmain: example.Main\n') + archive.writestr('plugin.yml', f'name: {name}\nversion: {version}\nmain: {main}\n') class Service: @@ -103,6 +104,35 @@ class FleetInstallerTests(unittest.TestCase): with self.assertRaises(ValueError): self.deployment() + def test_private_runtime_is_hash_pinned_and_installed_without_public_artifact(self): + runtime = self.base / 'private-mcgui.jar' + jar(runtime, 'MCGUI', '0.8.6', 'ai.resourcepack.ui.MCGUIPlugin') + sha = installer.digest(runtime) + self.inventory['privatePrerequisites'] = {'MCGUI': {'path': str(runtime.resolve()), 'sha256': sha}} + self.inventory['servers'][0]['prerequisites'] = ['MCGUI'] + with self.assertRaises(ValueError): + self.deployment() + reviewed = dict(installer.PRIVATE_PREREQUISITES['MCGUI'], sha256=sha) + with patch.dict(installer.PRIVATE_PREREQUISITES, {'MCGUI': reviewed}): + deployment = self.deployment() + installer.apply(deployment, self.base / 'backups', Service()) + self.assertEqual((self.plugins / 'MCGUI-0.8.6.jar').read_bytes(), runtime.read_bytes()) + self.assertFalse((self.artifacts / 'MCGUI-0.8.6.jar').exists()) + self.assertTrue((self.plugins / 'DuneNPC.jar').exists()) + + def test_unknown_or_identity_mismatched_private_runtime_is_rejected(self): + runtime = self.base / 'private-mcgui.jar' + jar(runtime, 'DifferentPlugin', '0.8.6') + sha = installer.digest(runtime) + self.inventory['privatePrerequisites'] = {'MCGUI': {'path': str(runtime.resolve()), 'sha256': sha}} + reviewed = dict(installer.PRIVATE_PREREQUISITES['MCGUI'], sha256=sha) + with patch.dict(installer.PRIVATE_PREREQUISITES, {'MCGUI': reviewed}): + with self.assertRaises(ValueError): + self.deployment() + self.inventory['privatePrerequisites'] = {'Unknown': {'path': str(runtime.resolve()), 'sha256': sha}} + with self.assertRaises(ValueError): + self.deployment() + def test_transitional_service_is_rejected_before_any_stop_or_write(self): service = Service() def transitional(*args):