Преглед изворни кода

fix: resume remote transfers without new users

root пре 3 месеци
родитељ
комит
9bfaf1a257

+ 2 - 1
ACTIVE_REMOTE_MIGRATION.yaml

@@ -66,7 +66,8 @@ package_baseline:
     - mutable_same_base_id
 remote_policy:
   host: edk2-uefi-lab
-  runtime_preference: rootless_podman_quadlet
+  runtime_preference: existing_ssh_user_podman_system_quadlet
+  user_creation: forbidden_by_user
   windows_root: C:\temp\prod2u-thermal
   wsl_shutdown_gate: remote_quick_and_roundtrip_pass
 focused_results:

+ 4 - 1
QUICK_PROGRESS.md

@@ -6,7 +6,7 @@
 - Phase: P0 PWM startup handoff only; TD, canonical repair, remote migration and WSL shutdown not started.
 - Required change: `boot_init_complete -> runtime_duty_ready`; preserve safe PTC0/FAN20 until one complete 32-channel runtime scan, then take over only on a phase boundary.
 - Required focused tests: generator check, lint, PWM unit, production Top POR/Boot three-period Cocotb, fan polarity and focused control.
-- Remote runtime policy: rootless Podman + Quadlet preferred; no remote write until SSH host identity is trusted.
+- Remote runtime policy: use the existing SSH user with Podman + system Quadlet; user creation is forbidden.
 - Hardware/COM/JTAG: NOT RUN; TTL pin unresolved/disabled.
 - P0 implemented: PWM holds safe carrier until `boot_init_complete` and a complete 32-channel runtime scan; takeover remains phase-boundary atomic.
 - PASS: Generator `--check`, closure check, Verilator lint, PWM unit, focused control Cocotb.
@@ -33,6 +33,9 @@
 - PASS: four clean repositories bundled to `C:\temp\prod2u-thermal\staging\bundles`; every bundle verify and SHA passed.
 - Remote TCP/22 is reachable but closes before presenting a host key; keyscan also closed, so no trusted fingerprint and no remote write.
 - Existing WSL OCI images lack Go/protoc and are not accepted; new locked build was stopped during a 32.5 kB/s apt layer and cache retained.
+- Remote identity confirmed at `192.168.2.119`, MAC `F4-96-34-0C-E1-C6`, ED25519 `SHA256:DyzsBVcHMdFmGiOb68fBC+WI8yuapcswo0JTXLEVdIk`.
+- A mistakenly created `prod2u` account was fully rolled back: user/group/home/linger/subids/processes/UID ownership absent; `/data/prod2u` restored to existing `root` ownership.
+- Remote transfer remains bounded by severe LAN loss; canonical sync scripts are being corrected to chunk/SHA/resume semantics before continuing.
 
 - Workspace: `/root/workspaces/thermal-system/cpld-temperature-control`
 - Branch: `dev`

+ 17 - 0
tests/unit/test_6400_canonical_packages.py

@@ -107,3 +107,20 @@ def test_fake_marker_cannot_satisfy_current(tmp_path: Path) -> None:
                             text=True, capture_output=True)
     assert result.returncode == 3
     assert "BASE_REQUIRED" in result.stdout
+
+
+def test_windows_remote_transfer_is_chunked_hashed_and_strict() -> None:
+    invoke = (canonical.ROOT / "tools/windows/invoke-remote.ps1").read_text()
+    upload = (canonical.ROOT / "tools/windows/sync-to-remote.ps1").read_text()
+    download = (canonical.ROOT / "tools/windows/sync-from-remote.ps1").read_text()
+    for script in (invoke, upload, download):
+        assert "StrictHostKeyChecking=yes" in script
+        assert "UserKnownHostsFile=" in script
+        assert "UserKnownHostsFile=/dev/null" not in script
+        assert "StrictHostKeyChecking=no" not in script
+    assert "ChunkBytes = 1048576" in upload
+    assert "sha256sum" in upload
+    assert ".partial" in upload
+    assert "parts-$wholeSha" in upload
+    assert "REMOTE_NETWORK_UNSTABLE" in upload
+    assert "ExpectedSha256" in download

+ 11 - 4
tools/windows/invoke-remote.ps1

@@ -1,12 +1,19 @@
-param([Parameter(ValueFromRemainingArguments=$true)][string[]]$Command)
+param(
+  [Parameter(ValueFromRemainingArguments=$true)][string[]]$Command,
+  [string]$KnownHosts = 'C:\temp\prod2u-thermal\receipts\known_hosts'
+)
 $ErrorActionPreference='Stop'
 $delays=2,5,10,20,30
-$knownHosts=Join-Path $HOME '.ssh\known_hosts'
+if(-not (Test-Path -LiteralPath $KnownHosts)){throw 'REMOTE_HOST_KEY_CONFIRMATION_REQUIRED'}
 for($i=0;$i -lt $delays.Count;$i++){
-  & ssh -o StrictHostKeyChecking=yes -o "UserKnownHostsFile=$knownHosts" `
+  $savedPreference=$ErrorActionPreference
+  $ErrorActionPreference='Continue'
+  & ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o "UserKnownHostsFile=$KnownHosts" `
     -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=4 `
     edk2-uefi-lab @Command
-  if($LASTEXITCODE -eq 0){exit 0}
+  $exitCode=$LASTEXITCODE
+  $ErrorActionPreference=$savedPreference
+  if($exitCode -eq 0){exit 0}
   if($i -eq 4){throw 'REMOTE_NETWORK_UNSTABLE'}
   Start-Sleep -Seconds $delays[$i]
 }

+ 26 - 6
tools/windows/sync-from-remote.ps1

@@ -1,8 +1,28 @@
-param([Parameter(Mandatory=$true)][string]$RemoteSource,[Parameter(Mandatory=$true)][string]$Destination)
+param(
+  [Parameter(Mandatory=$true)][string]$RemoteSource,
+  [Parameter(Mandatory=$true)][string]$Destination,
+  [Parameter(Mandatory=$true)][string]$ExpectedSha256,
+  [string]$KnownHosts = 'C:\temp\prod2u-thermal\receipts\known_hosts'
+)
 $ErrorActionPreference='Stop'
-$knownHosts=Join-Path $HOME '.ssh\known_hosts'
+if(-not (Test-Path -LiteralPath $KnownHosts -PathType Leaf)){throw 'REMOTE_HOST_KEY_CONFIRMATION_REQUIRED'}
 $partial="$Destination.partial"
-& scp -o StrictHostKeyChecking=yes -o "UserKnownHostsFile=$knownHosts" -o ConnectTimeout=10 `
-  "edk2-uefi-lab:$RemoteSource" $partial
-if($LASTEXITCODE -ne 0){throw 'REMOTE_NETWORK_UNSTABLE'}
-Move-Item -LiteralPath $partial -Destination $Destination -Force
+$delays=2,5,10,20,30
+$ssh=@('-o','BatchMode=yes','-o','StrictHostKeyChecking=yes','-o',"UserKnownHostsFile=$KnownHosts",'-o','ConnectTimeout=10','-o','ServerAliveInterval=15','-o','ServerAliveCountMax=4')
+for($i=0;$i -lt $delays.Count;$i++){
+  $savedPreference=$ErrorActionPreference
+  $ErrorActionPreference='Continue'
+  & scp @ssh "edk2-uefi-lab:$RemoteSource" $partial
+  $exitCode=$LASTEXITCODE
+  $ErrorActionPreference=$savedPreference
+  if($exitCode -eq 0){
+    $sha=(Get-FileHash -Algorithm SHA256 -LiteralPath $partial).Hash.ToLowerInvariant()
+    if($sha -eq $ExpectedSha256.ToLowerInvariant()){
+      Move-Item -LiteralPath $partial -Destination $Destination -Force
+      Write-Output "TRANSFER_PASS sha256=$sha local=$Destination"
+      exit 0
+    }
+  }
+  if($i -lt $delays.Count-1){Start-Sleep -Seconds $delays[$i]}
+}
+throw 'REMOTE_NETWORK_UNSTABLE'

+ 74 - 7
tools/windows/sync-to-remote.ps1

@@ -1,8 +1,75 @@
-param([Parameter(Mandatory=$true)][string]$Source,[Parameter(Mandatory=$true)][string]$RemotePartial)
+param(
+  [Parameter(Mandatory=$true)][string]$Source,
+  [Parameter(Mandatory=$true)][string]$RemotePartial,
+  [string]$KnownHosts = 'C:\temp\prod2u-thermal\receipts\known_hosts',
+  [ValidateRange(65536,419430400)][int]$ChunkBytes = 1048576
+)
 $ErrorActionPreference='Stop'
-$knownHosts=Join-Path $HOME '.ssh\known_hosts'
-& scp -o StrictHostKeyChecking=yes -o "UserKnownHostsFile=$knownHosts" -o ConnectTimeout=10 `
-  $Source "edk2-uefi-lab:$RemotePartial"
-if($LASTEXITCODE -ne 0){throw 'REMOTE_NETWORK_UNSTABLE'}
-$sha=(Get-FileHash -Algorithm SHA256 -LiteralPath $Source).Hash.ToLowerInvariant()
-& "$PSScriptRoot\invoke-remote.ps1" "test \`$(sha256sum '$RemotePartial' | cut -d' ' -f1) = '$sha' && mv '$RemotePartial' '$($RemotePartial -replace '\.partial$','')'"
+if(-not (Test-Path -LiteralPath $Source -PathType Leaf)){throw 'SOURCE_NOT_FOUND'}
+if(-not (Test-Path -LiteralPath $KnownHosts -PathType Leaf)){throw 'REMOTE_HOST_KEY_CONFIRMATION_REQUIRED'}
+if(-not $RemotePartial.EndsWith('.partial')){throw 'REMOTE_PARTIAL_SUFFIX_REQUIRED'}
+
+$delays=2,5,10,20,30
+$wholeSha=(Get-FileHash -Algorithm SHA256 -LiteralPath $Source).Hash.ToLowerInvariant()
+$final=$RemotePartial.Substring(0,$RemotePartial.Length-8)
+$remoteParts="$RemotePartial.parts-$wholeSha"
+$stage=Join-Path 'C:\temp\prod2u-thermal\staging' "transfer-$wholeSha"
+$ssh=@('-o','BatchMode=yes','-o','StrictHostKeyChecking=yes', '-o',"UserKnownHostsFile=$KnownHosts",'-o','ConnectTimeout=10','-o','ServerAliveInterval=15','-o','ServerAliveCountMax=4')
+
+function Invoke-RemoteChecked([string]$RemoteCommand){
+  $encoded=[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($RemoteCommand))
+  for($i=0;$i -lt $delays.Count;$i++){
+    $savedPreference=$ErrorActionPreference
+    $ErrorActionPreference='Continue'
+    $output=& ssh @ssh edk2-uefi-lab "echo $encoded | base64 -d | bash" 2>&1
+    $exitCode=$LASTEXITCODE
+    $ErrorActionPreference=$savedPreference
+    if($exitCode -eq 0){return $output}
+    if($i -eq $delays.Count-1){throw 'REMOTE_NETWORK_UNSTABLE'}
+    Start-Sleep -Seconds $delays[$i]
+  }
+}
+
+New-Item -ItemType Directory -Force -Path $stage | Out-Null
+try {
+  $input=[IO.File]::OpenRead((Resolve-Path -LiteralPath $Source))
+  try {
+    $buffer=New-Object byte[] $ChunkBytes
+    $index=0
+    while(($count=$input.Read($buffer,0,$buffer.Length)) -gt 0){
+      $name=('part-{0:D6}' -f $index)
+      $path=Join-Path $stage $name
+      $out=[IO.File]::Open($path,[IO.FileMode]::Create,[IO.FileAccess]::Write,[IO.FileShare]::None)
+      try {$out.Write($buffer,0,$count)} finally {$out.Dispose()}
+      $index++
+    }
+  } finally {$input.Dispose()}
+
+  Invoke-RemoteChecked "mkdir -p '$remoteParts'"
+  foreach($part in Get-ChildItem -LiteralPath $stage -File | Sort-Object Name){
+    $partSha=(Get-FileHash -Algorithm SHA256 -LiteralPath $part.FullName).Hash.ToLowerInvariant()
+    $remotePart="$remoteParts/$($part.Name)"
+    $present=Invoke-RemoteChecked "if test -f '$remotePart' && test \`$(sha256sum '$remotePart' | cut -d' ' -f1) = '$partSha'; then echo PRESENT; else echo MISSING; fi"
+    if($present -notcontains 'PRESENT'){
+      $sent=$false
+      for($i=0;$i -lt $delays.Count;$i++){
+        $savedPreference=$ErrorActionPreference
+        $ErrorActionPreference='Continue'
+        & scp @ssh $part.FullName "edk2-uefi-lab:$remotePart.partial"
+        $exitCode=$LASTEXITCODE
+        $ErrorActionPreference=$savedPreference
+        if($exitCode -eq 0){
+          $verified=Invoke-RemoteChecked "test \`$(sha256sum '$remotePart.partial' | cut -d' ' -f1) = '$partSha' && mv '$remotePart.partial' '$remotePart' && echo VERIFIED"
+          if($verified -contains 'VERIFIED'){$sent=$true;break}
+        }
+        if($i -lt $delays.Count-1){Start-Sleep -Seconds $delays[$i]}
+      }
+      if(-not $sent){throw 'REMOTE_NETWORK_UNSTABLE'}
+    }
+  }
+  $count=(Get-ChildItem -LiteralPath $stage -File).Count
+  Invoke-RemoteChecked "test \`$(find '$remoteParts' -maxdepth 1 -type f -name 'part-*' | wc -l) -eq $count && cat '$remoteParts'/part-* > '$RemotePartial' && test \`$(sha256sum '$RemotePartial' | cut -d' ' -f1) = '$wholeSha' && mv '$RemotePartial' '$final' && rm -rf '$remoteParts'"
+  Write-Output "TRANSFER_PASS sha256=$wholeSha remote=$final"
+} finally {
+  if(Test-Path -LiteralPath $stage){Remove-Item -LiteralPath $stage -Recurse -Force}
+}