diff --git a/tools/install-plugin-fleet.py b/tools/install-plugin-fleet.py index 622e009a..2913fcce 100644 --- a/tools/install-plugin-fleet.py +++ b/tools/install-plugin-fleet.py @@ -52,14 +52,33 @@ def identity(path): return result +DUNECHEST_PLANETS = {'arrakis', 'caladan', 'giedi_prime', 'kaitain', 'sigma_draconis_iv'} +DUNECHEST_FLEET_JAR = '0c56c56e03310572e0fc1f603d4fd23230456c64ab9d2892f3a0849fb349a1ae' +DUNECHEST_PLANET_PREDECESSOR = 'a1cd67aeea65d4a9dc98b75b1466fd54a120213e3eef31582c9492d546e484c2' + + +def verify_dunechest_fleet_target(sid, root, unit, incoming, installed): + expected_root = Path('/opt/dunerealms/lobby') if sid == 'lobby' else Path('/opt/dunerealms/servers') / sid + if sid not in DUNECHEST_PLANETS | {'lobby'} or root != expected_root or unit != f'dune-{sid}.service': + raise ValueError('DuneChest fleet release requires an exact reviewed server root and unit') + if incoming != DUNECHEST_FLEET_JAR: + raise ValueError('Fleet release must install the exact DuneChest JAR tested on Ordos') + allowed = {None, incoming} if sid == 'lobby' else {incoming} + if sid in DUNECHEST_PLANETS - {'sigma_draconis_iv'}: + allowed.add(DUNECHEST_PLANET_PREDECESSOR) + if installed not in allowed: + raise ValueError('Unexpected DuneChest fleet predecessor') + + def plan(artifacts, inventory, expected_source): mode=inventory.get('mode') - if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest'}: + if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest'}: raise ValueError('An explicit supported rollout mode is required') pillager=mode=='pillager-preserve-economy' crysknife=mode=='arrakis-crysknife' navigator=mode=='navigator' - dunechest=mode=='planet-dunechest' + fleet_dunechest=mode=='fleet-dunechest' + dunechest=mode=='planet-dunechest' or fleet_dunechest artifacts = Path(artifacts).resolve(strict=True) manifest = json.loads((artifacts / 'release-manifest.json').read_text()) if not re.fullmatch(r'[0-9a-f]{40}', expected_source) or manifest.get('sourceCommit') != expected_source: @@ -101,6 +120,8 @@ def plan(artifacts, inventory, expected_source): verify_public_menu(inventory['menuPack']['url'], menu) if (pillager or crysknife or navigator or dunechest) and not(menu and menu.get('unified')): raise ValueError('This rollout requires its verified unified item/skin pack') + if fleet_dunechest and menu['sha256'] != '17510232dac90b9ac383470748d416b9560d28fc26121d3ecce7f30d6a4ebb12': + raise ValueError('Fleet release must use the exact resource pack tested on Ordos') if navigator: from plugin_navigator_transition import verify_module as verify_navigator, verify_jarvis as verify_navigator_jarvis transition=json.loads((artifacts/'navigator-transition.json').read_text()) @@ -145,10 +166,11 @@ def plan(artifacts, inventory, expected_source): expected={'dunemenus','dunerealmsgui'} | ({'jarvistranslator'} if sid in planets else set()) if sid not in planets|{'lobby'} or root!=target or unit!=f'dune-{sid}.service' or wanted!=expected or selected_prerequisites: raise ValueError('Navigator rollout requires its reviewed server root, unit and plugin selection') - if dunechest and ( + if dunechest and (wanted!={'dunechest'} or selected_prerequisites): + raise ValueError('DuneChest rollout allows only the DuneChest artifact') + if dunechest and not fleet_dunechest and ( sid not in {'arrakis','caladan','giedi_prime','kaitain','sigma_draconis_iv'} or root!=Path('/opt/dunerealms/servers')/sid or unit!=f'dune-{sid}.service' - or wanted!={'dunechest'} or selected_prerequisites ): raise ValueError('DuneChest rollout requires an exact planet root and only the DuneChest artifact') if pillager: @@ -279,7 +301,9 @@ def plan(artifacts, inventory, expected_source): chosen[0]['sha256'], 'bd80ff028e58b24e4ee023827d9fa6dca3ae857dc867a27caca5ef399544ec85', } - if installed is not None and digest(installed) not in approved_dunechest: + if fleet_dunechest: + verify_dunechest_fleet_target(sid, root, unit, chosen[0]['sha256'], digest(installed) if installed else None) + elif installed is not None and digest(installed) not in approved_dunechest: raise ValueError('Existing DuneChest differs from the approved release or predecessor') replaced={entry['filename'] for entry in previous} retained=[{'filename':path.name,'sha256':digest(path),'metadata':metadata(path)} diff --git a/tools/test_plugin_fleet_install.py b/tools/test_plugin_fleet_install.py index ed903e6b..3a7676d5 100644 --- a/tools/test_plugin_fleet_install.py +++ b/tools/test_plugin_fleet_install.py @@ -58,6 +58,26 @@ class FleetInstallerTests(unittest.TestCase): def deployment(self): return installer.plan(self.artifacts, self.inventory, SOURCE) + def test_dunechest_fleet_requires_exact_lobby_and_planet_predecessors(self): + check = installer.verify_dunechest_fleet_target + incoming = installer.DUNECHEST_FLEET_JAR + predecessor = installer.DUNECHEST_PLANET_PREDECESSOR + lobby = Path('/opt/dunerealms/lobby') + arrakis = Path('/opt/dunerealms/servers/arrakis') + sigma = Path('/opt/dunerealms/servers/sigma_draconis_iv') + check('lobby', lobby, 'dune-lobby.service', incoming, None) + check('arrakis', arrakis, 'dune-arrakis.service', incoming, predecessor) + check('sigma_draconis_iv', sigma, 'dune-sigma_draconis_iv.service', incoming, incoming) + for target in ( + ('lobby', arrakis, 'dune-lobby.service', incoming, None), + ('lobby', lobby, 'dune-lobby.service', incoming, predecessor), + ('arrakis', arrakis, 'dune-arrakis.service', incoming, None), + ('sigma_draconis_iv', sigma, 'dune-sigma_draconis_iv.service', incoming, predecessor), + ('arrakis', arrakis, 'dune-arrakis.service', predecessor, predecessor), + ): + with self.subTest(target=target), self.assertRaises(ValueError): + check(*target) + def test_planning_is_read_only_and_requires_exact_source_and_hash(self): before = {p.name: p.read_bytes() for p in self.plugins.iterdir()} self.deployment()