Prepare the retained passive Windows echo build and time-profile successor
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -2,8 +2,12 @@
|
||||
#requires -RunAsAdministrator
|
||||
# Fixed console maintenance of the passive test guest. No queue, network, or script job.
|
||||
[CmdletBinding()]
|
||||
param([Parameter(Mandatory)][ValidateSet('Prepare','InstallPassive','Read','RestorePrevious')][string]$Mode)
|
||||
param(
|
||||
[Parameter(Mandatory)][ValidateSet('StageEchoInputs','Prepare','InstallPassive','Read','RestorePrevious')][string]$Mode,
|
||||
[switch]$EchoPassive
|
||||
)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if ($Mode -ceq 'StageEchoInputs' -and !$EchoPassive) { throw 'Staging applies only to the sealed passive successor' }
|
||||
$originalCase = 'ad9fd154-b2be-4f5d-9e17-65abb721ceaf'
|
||||
$originalHash = 'd8b4fd4fd9ca5310cc1591ce3c2ccae5bd72a2ade43b21a8187cfdfb960b3427'
|
||||
$bootstrap = 'C:\ProgramData\RustDiscoveryBootstrap'
|
||||
@@ -42,6 +46,103 @@ $locations = [ordered]@{agent=$agentBinary;settings=$settings;pin=$pin}
|
||||
$profileHash = '2b4a8a7080770304b80e2a665fa5f5ee1ebbd9182e7c80b184e75b114575b42b'
|
||||
$helperHash = '59675a3cbb3a5d213fc764f38379d6b81baaf9d47a7124470cc2767d4985763e'
|
||||
$configHash = '7c9f6f3642ef84337c3cd761d8a4788c4babe81522fdd987a3eb9b819bc8d851'
|
||||
$unitProof = Join-Path $boot 'profile-unit-fcec400-result.json'
|
||||
$unitHash = '48de474d842ebc87550ba2e27b66086e6aa573973f252f4b8e19ac7b12b75a63'
|
||||
$linuxProofHash = 'ee3a2c99651491a2fd876f1a3463919dc32d9509d9f9ef4eb73a36aa848bb56d'
|
||||
$agentBuildHash = 'a003dfa8cc2397a99933aceeb2d8dab51f883ab9cdf27876fbfc94a78873044c'
|
||||
$previousPublicationHash = '62a04be9c7d08d3687b51eacd6adbe290b91e16ba934d6b5bb531e8764a56cf5'
|
||||
$previousRevision = 1
|
||||
$platformArchive = Join-Path $oldFolder 'platform-provenance.json'
|
||||
$roleArchive = Join-Path $oldFolder '{0}-qualification.json'
|
||||
function Get-SuccessorPinBytes($name,$path) {
|
||||
if ((Hash $path) -cne $oldHashes.$name) { throw "Changed predecessor: $name" }
|
||||
$utf8=[Text.UTF8Encoding]::new($false,$true)
|
||||
$data=$utf8.GetString([IO.File]::ReadAllBytes($path)).Replace($oldHashes.agent,$newHashes.agent)
|
||||
if ($name -ceq 'pin') { $data=$data.Replace($oldHashes.settings,$newHashes.settings) }
|
||||
return ,$utf8.GetBytes($data)
|
||||
}
|
||||
function Copy-EchoInput($folder,$name,$digest,[long]$maxBytes) {
|
||||
$inputFile=Join-Path $PSScriptRoot $name
|
||||
$entry=Get-Item -LiteralPath $inputFile -Force
|
||||
if ($entry.PSIsContainer -or $entry.Attributes -band [IO.FileAttributes]::ReparsePoint -or
|
||||
$entry.Length -lt 1 -or $entry.Length -gt $maxBytes) { throw 'Unexpected passive release input' }
|
||||
$bytes=[IO.File]::ReadAllBytes($inputFile)
|
||||
$sha=[Security.Cryptography.SHA256]::Create()
|
||||
try { $observed=[BitConverter]::ToString($sha.ComputeHash($bytes)).Replace('-','').ToLowerInvariant() }
|
||||
finally { $sha.Dispose() }
|
||||
if ($observed -cne $digest) { throw "Passive media input changed: $name" }
|
||||
if (!(Test-Path -LiteralPath $folder)) { [RmmTimeProfileCase]::CreatePrivateOnce($folder) }
|
||||
CheckControl $folder $true
|
||||
$dest=Join-Path $folder $name
|
||||
if (!(Test-Path -LiteralPath $dest)) { WriteBytes $dest $bytes }
|
||||
CheckControl $dest $false
|
||||
if ((Hash $dest) -cne $digest) { throw "Different previously staged input: $name" }
|
||||
}
|
||||
if ($EchoPassive) {
|
||||
$manifestHash = '7c331501e40c57597624ed889ea12f34a9b16d8d10f41a2a5a73d8b7d01280a1'
|
||||
if ($manifestHash -cnotmatch '^[0-9a-f]{64}$') { throw 'Echo passive build has not been sealed' }
|
||||
$proofDir = Join-Path $boot $manifestHash
|
||||
$manifest = Join-Path $proofDir 'passive-build.json'
|
||||
CheckControl $boot $true
|
||||
if ($Mode -ceq 'StageEchoInputs') { Copy-EchoInput $proofDir 'passive-build.json' $manifestHash 8192 }
|
||||
CheckControl $proofDir $true
|
||||
CheckControl $manifest $false
|
||||
if ((Hash $manifest) -cne $manifestHash) { throw 'Unrecognized passive build manifest' }
|
||||
$build = Get-Content -LiteralPath $manifest -Raw | ConvertFrom-Json
|
||||
$previousCase = $work
|
||||
$previousSample = Join-Path $previousCase 'samples-after-restart-a1959583-44f4-47db-aff4-f0229468a15b.json'
|
||||
CheckControl $previousCase $true
|
||||
CheckControl $previousSample $false
|
||||
if ((Hash $previousSample) -cne '34fe01eb8413c37f7e5269e1465d764bf730aa46b1a6cc371f113c7f9d285c9a') {
|
||||
throw 'Predecessor role sample changed'
|
||||
}
|
||||
$sample = Get-Content -LiteralPath $previousSample -Raw | ConvertFrom-Json
|
||||
$previousPublication = Join-Path $previousCase 'profile-published.json'
|
||||
CheckControl $previousPublication $false
|
||||
$previousPublicationHash = Hash $previousPublication
|
||||
if ($sample.pair_case_id -cne $id -or $sample.profile_receipt_sha256 -cne $previousPublicationHash) {
|
||||
throw 'Predecessor profile does not match the native role sample'
|
||||
}
|
||||
$id = '1d61d88b-ab17-49b1-9a8d-2427348313b4'
|
||||
if ($build.case_id -cne $id -or $build.kind -cne 'rmm.windows.echo-passive-build.v1') { throw 'Wrong passive build case' }
|
||||
foreach ($field in @('agent_sha256','agent_build_sha256','linux_fixture_sha256','windows_fixture_sha256','cargo_inputs_sha256','cross_crate_inputs_sha256')) {
|
||||
if ($build.$field -isnot [string] -or $build.$field -cnotmatch '^[0-9a-f]{64}$') { throw "Invalid manifest digest: $field" }
|
||||
}
|
||||
$oldHashes = $newHashes
|
||||
$newHashes = [ordered]@{agent=$build.agent_sha256}
|
||||
$work = Join-Path $boot "job-passive-pair-$id"
|
||||
foreach ($name in @('settings','pin')) {
|
||||
$baseline = Join-Path $work ('old-'+$name)
|
||||
if (Test-Path -LiteralPath $baseline) { CheckControl $work $true; CheckControl $baseline $false }
|
||||
elseif ($name -ceq 'settings') { $baseline=$settings } else { $baseline=$pin }
|
||||
$sha=[Security.Cryptography.SHA256]::Create()
|
||||
try { $newHashes[$name]=[BitConverter]::ToString($sha.ComputeHash((Get-SuccessorPinBytes $name $baseline))).Replace('-','').ToLowerInvariant() }
|
||||
finally { $sha.Dispose() }
|
||||
}
|
||||
foreach ($name in $oldHashes.Keys) {
|
||||
if ($oldHashes[$name] -ceq $newHashes[$name]) { throw "Unchanged target generation: $name" }
|
||||
}
|
||||
$profileHash = $sample.profile_sha256
|
||||
$previousRevision = 2
|
||||
$platformArchive = Join-Path $previousCase 'profile-platform.json'
|
||||
$roleArchive = Join-Path $previousCase 'profile-role-{0}.json'
|
||||
$unitProof = Join-Path $proofDir 'windows-fixture.json'
|
||||
$unitHash = $build.windows_fixture_sha256
|
||||
$linuxProofHash = $build.linux_fixture_sha256
|
||||
$agentBuildHash = $build.agent_build_sha256
|
||||
foreach ($entry in @(@('agent-build.json',$agentBuildHash),@('linux-fixture.json',$linuxProofHash),@('windows-fixture.json',$unitHash),
|
||||
@('cargo-inputs.json',$build.cargo_inputs_sha256),@('cross-crate-inputs.json',$build.cross_crate_inputs_sha256))) {
|
||||
if ($Mode -ceq 'StageEchoInputs') { Copy-EchoInput $proofDir $entry[0] $entry[1] 1048576 }
|
||||
$proof = Join-Path $proofDir $entry[0]
|
||||
CheckControl $proof $false
|
||||
if ((Hash $proof) -cne $entry[1]) { throw 'Passive candidate evidence differs from the reviewed manifest' }
|
||||
}
|
||||
if ($Mode -ceq 'StageEchoInputs') {
|
||||
Copy-EchoInput (Join-Path $boot $newHashes.agent) 'rmm-agent-windows.exe' $newHashes.agent 100663296
|
||||
Write-Output "Staged passive release $manifestHash"
|
||||
return
|
||||
}
|
||||
}
|
||||
$source = Join-Path (Join-Path $boot $newHashes.agent) 'rmm-agent-windows.exe'
|
||||
CheckControl $boot $true
|
||||
CheckControl $oldFolder $true
|
||||
@@ -61,9 +162,8 @@ function VerifyPassiveContext {
|
||||
(Hash $helperBinary) -cne $helperHash) { throw 'Passive config, predecessor time profile or unchanged helper differs' }
|
||||
foreach ($dir in @((Split-Path $agentBinary),$agentRoot,$helperRoot)) { $null=ReadAcl $dir $true }
|
||||
foreach ($file in @($config,$settings,$pin,$target,$agentBinary,$helperBinary)) { $null=ReadAcl $file $false }
|
||||
$unitProof=Join-Path $boot 'profile-unit-fcec400-result.json'
|
||||
CheckControl $unitProof $false
|
||||
if ((Hash $unitProof) -cne '48de474d842ebc87550ba2e27b66086e6aa573973f252f4b8e19ac7b12b75a63') {
|
||||
if ((Hash $unitProof) -cne $unitHash) {
|
||||
throw 'Current native Windows profile unit receipt differs'
|
||||
}
|
||||
}
|
||||
@@ -91,7 +191,7 @@ function LiveRole($role,$expectedHash) {
|
||||
} finally { $handle.Dispose() }
|
||||
}
|
||||
function PreservedDevice {
|
||||
return [ordered]@{
|
||||
$device = [ordered]@{
|
||||
config=(FileIdentity $config)
|
||||
identity=(FileIdentity (Join-Path $agentState 'identity.json') $true)
|
||||
certificate=(FileIdentity (Join-Path $agentState 'device.pem') $true)
|
||||
@@ -99,6 +199,28 @@ function PreservedDevice {
|
||||
helper=(FileIdentity $helperBinary)
|
||||
time_profile=(FileIdentity $target)
|
||||
}
|
||||
if ($EchoPassive) {
|
||||
$device['journals'] = [ordered]@{}
|
||||
foreach ($journal in @((Join-Path $agentState 'telemetry.sqlite'),(Join-Path $agentState 'consumption.sqlite'),(Join-Path $helperState 'ledger.sqlite'))) {
|
||||
$item=Get-Item -LiteralPath $journal -Force
|
||||
if ($item.PSIsContainer) { throw 'Unexpected journal directory' }
|
||||
for ($ancestor=$item; $null -ne $ancestor; ) {
|
||||
if ($ancestor.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw 'Journal path is a reparse point' }
|
||||
if ($ancestor -is [IO.FileInfo]) { $ancestor=$ancestor.Directory } else { $ancestor=$ancestor.Parent }
|
||||
}
|
||||
# FILE_READ_ATTRIBUTES with read/write/delete sharing permits the passive
|
||||
# runtime to append. No journal contents are opened or copied.
|
||||
$handle=[RmmPipeNative]::CreateFile($journal,0x80,7,[IntPtr]::Zero,3,0,[IntPtr]::Zero)
|
||||
try {
|
||||
$identity=New-Object RmmPipeNative+FileId
|
||||
if ($handle.IsInvalid -or ![RmmPipeNative]::GetFileInformationByHandleEx($handle,18,[ref]$identity,24)) {
|
||||
throw 'Cannot bind native journal identity'
|
||||
}
|
||||
$device.journals[$journal]=[ordered]@{volume=$identity.Volume.ToString();file_id=[BitConverter]::ToString($identity.Id);acl_sha256=(AclHash $journal)}
|
||||
} finally { $handle.Dispose() }
|
||||
}
|
||||
}
|
||||
return $device
|
||||
}
|
||||
function FlushFile($path) {
|
||||
$f=[IO.File]::Open($path,'Open','ReadWrite','Read')
|
||||
@@ -130,7 +252,9 @@ function SwapFile($name,$inputPath,$oldId,$newHash,$prefix) {
|
||||
if (!(JsonEqual $oldId (FileIdentity $dest)) -or (Hash $inputPath) -cne $newHash -or (Test-Path -LiteralPath $backup)) {
|
||||
throw "Replacement precondition $name"
|
||||
}
|
||||
[IO.File]::Copy($inputPath,$stage,$false)
|
||||
# A new independently written stage preserves the case directory ACL and
|
||||
# avoids inheriting a read-only ISO file attribute.
|
||||
WriteBytes $stage ([IO.File]::ReadAllBytes($inputPath))
|
||||
FlushFile $stage
|
||||
$candidate=FileIdentity $stage
|
||||
if ($candidate.sha256 -cne $newHash -or $candidate.volume_serial -cne $oldId.volume_serial) { throw 'Invalid same-volume candidate' }
|
||||
@@ -174,12 +298,9 @@ function PrepareFiles($before) {
|
||||
FlushFile $copy
|
||||
if ((Hash $copy) -cne $oldHashes.$name) { throw "Backup $name" }
|
||||
}
|
||||
$utf8=[Text.UTF8Encoding]::new($false,$true)
|
||||
foreach ($name in @('settings','pin')) {
|
||||
$data=$utf8.GetString([IO.File]::ReadAllBytes($locations[$name])).Replace($oldHashes.agent,$newHashes.agent)
|
||||
if ($name -eq 'pin') { $data=$data.Replace($oldHashes.settings,$newHashes.settings) }
|
||||
$path=Join-Path $work ('new-'+$name)
|
||||
WriteBytes $path ($utf8.GetBytes($data))
|
||||
WriteBytes $path (Get-SuccessorPinBytes $name $locations[$name])
|
||||
if ((Hash $path) -cne $newHashes.$name) { throw "Closed successor bytes $name" }
|
||||
}
|
||||
if (!(JsonEqual $before (CurrentFiles))) { throw 'Original inputs changed during copy' }
|
||||
|
||||
Reference in New Issue
Block a user