fix(827): harden pinned launcher validation
This commit is contained in:
@@ -292,11 +292,17 @@ def resolve_gated_wi_root() -> Path:
|
||||
try:
|
||||
if not gated_root.is_dir():
|
||||
raise RuntimeError("D4 precondition: GATED_WI_ROOT is not a directory")
|
||||
is_worktree = subprocess.check_output(
|
||||
["git", "-C", str(gated_root), "rev-parse", "--is-inside-work-tree"],
|
||||
text=True,
|
||||
).strip()
|
||||
head = subprocess.check_output(
|
||||
["git", "-C", str(gated_root), "rev-parse", "HEAD"], text=True
|
||||
).strip()
|
||||
except (OSError, subprocess.CalledProcessError) as error:
|
||||
raise RuntimeError("D4 precondition: GATED_WI_ROOT is not a git worktree") from error
|
||||
if is_worktree != "true":
|
||||
raise RuntimeError("D4 precondition: GATED_WI_ROOT is not a git worktree")
|
||||
if head != GATED_WI_HEAD:
|
||||
raise RuntimeError(f"D4 precondition: gated WI head mismatch: {head}")
|
||||
return gated_root
|
||||
@@ -353,23 +359,21 @@ def gated_launcher_precondition(
|
||||
except UnicodeDecodeError as error:
|
||||
raise RuntimeError("D4 precondition: pinned launcher is not UTF-8") from error
|
||||
|
||||
register = launcher_source.find('"action": "register_anchor"')
|
||||
initialize = launcher_source.find("initialize_runtime_generation(generation_file, generation)")
|
||||
execute = launcher_source.find("execute(command[0], command, environment)")
|
||||
fixture_socket = launcher_source.find('source_environment["MOSAIC_LEASE_BROKER_SOCKET"]')
|
||||
fixture_state = launcher_source.find('socket_path.parent / f"generation-{session_id}.state"')
|
||||
exported_state = launcher_source.find('environment["MOSAIC_LEASE_GENERATION_FILE"]')
|
||||
generation_api = (
|
||||
# The exact launcher digest above is the trust anchor. These marker checks
|
||||
# are diagnostic belt-and-suspenders only, never a substitute for the pin.
|
||||
behavior_markers = (
|
||||
'"action": "register_anchor"',
|
||||
"initialize_runtime_generation(generation_file, generation)",
|
||||
"execute(command[0], command, environment)",
|
||||
'source_environment["MOSAIC_LEASE_BROKER_SOCKET"]',
|
||||
'socket_path.parent / f"generation-{session_id}.state"',
|
||||
'environment["MOSAIC_LEASE_GENERATION_FILE"]',
|
||||
)
|
||||
if not all(marker in launcher_source for marker in behavior_markers) or not (
|
||||
"def read_runtime_generation" in generation_source
|
||||
and "def bump_runtime_generation" in generation_source
|
||||
)
|
||||
if (
|
||||
min(register, initialize, execute, fixture_socket, fixture_state, exported_state) < 0
|
||||
or register >= initialize
|
||||
or initialize >= execute
|
||||
or not generation_api
|
||||
):
|
||||
raise RuntimeError("D4 precondition: launcher is not file-generation fixture-bound")
|
||||
raise RuntimeError("D4 precondition: pinned launcher lacks file-generation markers")
|
||||
|
||||
fixture_launcher_dir = root / "pinned-lease-broker"
|
||||
fixture_launcher_dir.mkdir(mode=0o700)
|
||||
|
||||
Reference in New Issue
Block a user