Add reviewed Windows scope completion and idle certificate renewal; deploy completion API
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
#requires -Version 5.1
|
||||
#requires -RunAsAdministrator
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)][ValidateSet('Prepare','InstallPassive','PrepareProfile','PublishProfile','Read')][string]$Action,
|
||||
[Parameter(Mandatory)][string]$ManifestSha256
|
||||
)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if ($ManifestSha256 -cnotmatch '^[0-9a-f]{64}$') { throw 'Expected exact development manifest digest.' }
|
||||
$bootstrap = 'C:\ProgramData\RustDiscoveryBootstrap'
|
||||
$manifestPath = Join-Path (Join-Path $bootstrap $ManifestSha256) 'successor.json'
|
||||
if ((Get-FileHash -LiteralPath $manifestPath).Hash.ToLowerInvariant() -cne $ManifestSha256) { throw 'Manifest changed.' }
|
||||
$m = Get-Content -LiteralPath $manifestPath -Raw | ConvertFrom-Json
|
||||
$fields = 'agent_build_sha256,case_id,linux_proof_sha256,new_agent_sha256,old_agent_sha256,old_pin_sha256,old_profile_sha256,old_settings_sha256,previous_publication_sha256,windows_proof_sha256'
|
||||
if ((($m.PSObject.Properties.Name | Sort-Object) -join ',') -cne $fields -or
|
||||
[guid]::ParseExact($m.case_id,'D').ToString() -cne $m.case_id) { throw 'Unexpected development manifest schema.' }
|
||||
foreach ($p in $m.PSObject.Properties) {
|
||||
if ($p.Name -cne 'case_id' -and $p.Value -cnotmatch '^[0-9a-f]{64}$') { throw 'Manifest digest format.' }
|
||||
}
|
||||
if ($m.old_agent_sha256 -ceq $m.new_agent_sha256) { throw 'No successor code.' }
|
||||
|
||||
# Reuse the already qualified native file-ID/process/ACL and stop/swap/start
|
||||
# implementation. Load declarations only, with exact original source checks.
|
||||
$prior = Join-Path $bootstrap 'mvp-successor-prerequisites'
|
||||
$common = Join-Path $prior 'Set-PassiveJobPair.ps1'
|
||||
$publication = Join-Path $prior 'Publish-JobPairTimeProfile.ps1'
|
||||
$commonExpected = 'b70313bfec6e2f055e0f9554d69a9a44acec4abc8afea457a059d33db3e5e410'
|
||||
$publicationExpected = '6b6f64192d82f98c449ea3c36c5da0f8b179ecd5d6f944f36151969d645b9fb5'
|
||||
if ((Get-FileHash -LiteralPath $common).Hash.ToLowerInvariant() -cne $commonExpected -or
|
||||
(Get-FileHash -LiteralPath $publication).Hash.ToLowerInvariant() -cne $publicationExpected) { throw 'Original native controllers changed.' }
|
||||
$text = [Text.Encoding]::UTF8.GetString([IO.File]::ReadAllBytes($common))
|
||||
$first = "`n`$originalCase = "
|
||||
$last = "`nif (`$Mode -eq 'Read') {"
|
||||
$i = $text.IndexOf($first,[StringComparison]::Ordinal)
|
||||
$j = $text.IndexOf($last,[StringComparison]::Ordinal)
|
||||
if ($i -lt 0 -or $j -le $i -or $i -ne $text.LastIndexOf($first,[StringComparison]::Ordinal) -or
|
||||
$j -ne $text.LastIndexOf($last,[StringComparison]::Ordinal)) { throw 'Native declaration boundary.' }
|
||||
$EchoPassive = $false
|
||||
$Mode = 'Read'
|
||||
. ([scriptblock]::Create($text.Substring($i,$j-$i)))
|
||||
|
||||
CheckControl $bootstrap $true
|
||||
CheckControl (Split-Path $manifestPath) $true
|
||||
CheckControl $manifestPath $false
|
||||
$previousCase = Join-Path $bootstrap 'job-passive-pair-c62d698d-d044-4815-acbe-3eeb383d44d5'
|
||||
$previousPublication = Join-Path $previousCase 'profile-published.json'
|
||||
CheckControl $previousCase $true
|
||||
CheckControl $previousPublication $false
|
||||
if ((Hash $previousPublication) -cne $m.previous_publication_sha256) { throw 'Previous publication changed.' }
|
||||
$previous = Get-Content -LiteralPath $previousPublication -Raw | ConvertFrom-Json
|
||||
if ($previous.successor_revision -ne 4 -or $previous.configuration.sha256 -cne $m.old_profile_sha256 -or
|
||||
$previous.agent.image_file.sha256 -cne $m.old_agent_sha256) { throw 'Expected actual revision 4 predecessor.' }
|
||||
$id = $m.case_id
|
||||
$work = Join-Path $bootstrap ('job-passive-pair-' + $id)
|
||||
$oldHashes = [ordered]@{agent=$m.old_agent_sha256;settings=$m.old_settings_sha256;pin=$m.old_pin_sha256}
|
||||
$newHashes = [ordered]@{agent=$m.new_agent_sha256}
|
||||
$source = Join-Path (Join-Path $bootstrap $newHashes.agent) 'rmm-agent-windows.exe'
|
||||
$profileHash = $m.old_profile_sha256
|
||||
$previousRevision = 4
|
||||
$previousPublicationHash = $m.previous_publication_sha256
|
||||
$platformArchive = Join-Path $previousCase 'profile-platform.json'
|
||||
$roleArchive = Join-Path $previousCase 'profile-role-{0}.json'
|
||||
$agentBuildHash = $m.agent_build_sha256
|
||||
$linuxProofHash = $m.linux_proof_sha256
|
||||
$unitHash = $m.windows_proof_sha256
|
||||
$unitProof = Join-Path (Split-Path $manifestPath) 'windows-proof.json'
|
||||
foreach ($entry in @(@('windows-proof.json',$unitHash),@('linux-proof.json',$linuxProofHash),@('agent-build.json',$agentBuildHash))) {
|
||||
$path = Join-Path (Split-Path $manifestPath) $entry[0]
|
||||
CheckControl $path $false
|
||||
if ((Hash $path) -cne $entry[1]) { throw 'Successor qualification evidence changed.' }
|
||||
}
|
||||
# The fixture receipts must explicitly report a successful native run. Their
|
||||
# detailed source/artifact bindings are reviewed in the local build manifest.
|
||||
foreach ($name in @('windows-proof.json','linux-proof.json')) {
|
||||
$proof = Get-Content -LiteralPath (Join-Path (Split-Path $manifestPath) $name) -Raw | ConvertFrom-Json
|
||||
if ($proof.verified -ne $true) { throw 'Native prerequisite did not pass.' }
|
||||
}
|
||||
foreach ($name in @('settings','pin')) {
|
||||
$baseline = $locations[$name]
|
||||
if (Test-Path -LiteralPath (Join-Path $work ('old-'+$name))) { $baseline = Join-Path $work ('old-'+$name) }
|
||||
$sha = [Security.Cryptography.SHA256]::Create()
|
||||
try { $newHashes[$name] = [BitConverter]::ToString($sha.ComputeHash((Get-SuccessorPinBytes $name $baseline))).Replace('-','').ToLowerInvariant() }
|
||||
finally { $sha.Dispose() }
|
||||
}
|
||||
$EchoPassive = $true # include stable journal file IDs in preservation evidence
|
||||
$pubText = [Text.Encoding]::UTF8.GetString([IO.File]::ReadAllBytes($publication))
|
||||
$i = $pubText.IndexOf('function RequireNewPassivePair {',[StringComparison]::Ordinal)
|
||||
$j = $pubText.IndexOf("`nif (`$Action -ceq 'Read') {",[StringComparison]::Ordinal)
|
||||
if ($i -lt 0 -or $j -le $i) { throw 'Publication declaration boundary.' }
|
||||
. ([scriptblock]::Create($pubText.Substring($i,$j-$i)))
|
||||
|
||||
if ($Action -ceq 'Read') {
|
||||
[ordered]@{id=$id;files=(CurrentFiles);device=(PreservedDevice);agent=(Service 'agent');helper=(Service 'helper');markers=@(Get-ChildItem -LiteralPath $work -File -Filter '*.json' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Name)} | ConvertTo-Json -Depth 12 -Compress
|
||||
return
|
||||
}
|
||||
if ($Action -ceq 'Prepare') {
|
||||
VerifyPassiveContext
|
||||
VerifyFiles (CurrentFiles) $oldHashes
|
||||
if (Test-Path -LiteralPath $work) { throw 'Existing case: read only.' }
|
||||
[RmmTimeProfileCase]::CreatePrivateOnce($work)
|
||||
$before = CurrentFiles
|
||||
$device = PreservedDevice
|
||||
$agent = LiveRole 'agent' $oldHashes.agent
|
||||
$helper = LiveRole 'helper' $helperHash
|
||||
PrepareFiles $before
|
||||
Record 'prepared' ([ordered]@{id=$id;manifest_sha256=$ManifestSha256;files=$before;device=$device;agent=$agent;helper=$helper})
|
||||
Write-Output "Prepared passive successor $id"
|
||||
return
|
||||
}
|
||||
$preparedPair = LoadRecord 'prepared'
|
||||
if ($preparedPair.id -cne $id -or $preparedPair.manifest_sha256 -cne $ManifestSha256) { throw 'Different prepared successor.' }
|
||||
if ($Action -ceq 'InstallPassive') {
|
||||
VerifyPassiveContext
|
||||
if (Test-Path -LiteralPath (Marker 'install-intent')) { throw 'Existing transition: read only.' }
|
||||
if (!(JsonEqual $preparedPair.files (CurrentFiles)) -or !(JsonEqual $preparedPair.device (PreservedDevice)) -or
|
||||
!(JsonEqual $preparedPair.agent (LiveRole 'agent' $oldHashes.agent)) -or
|
||||
!(JsonEqual $preparedPair.helper (LiveRole 'helper' $helperHash))) { throw 'Prepared predecessor changed.' }
|
||||
Record 'install-intent' @{id=$id;manifest_sha256=$ManifestSha256}
|
||||
StopKnownRole 'agent' $agentName $preparedPair.agent 'install'
|
||||
StopKnownRole 'helper' $helperName $preparedPair.helper 'install'
|
||||
foreach ($name in $locations.Keys) {
|
||||
$inputPath = Join-Path $work ('new-'+$name)
|
||||
if ($name -ceq 'agent') { $inputPath=$source }
|
||||
SwapFile $name $inputPath $preparedPair.files.$name $newHashes.$name 'install'
|
||||
}
|
||||
if (!(JsonEqual $preparedPair.device (PreservedDevice))) { throw 'Device or history file identities changed.' }
|
||||
StartKnownRole 'helper' $helperName $helperHash 'install'
|
||||
StartKnownRole 'agent' $agentName $newHashes.agent 'install'
|
||||
Record 'installed' ([ordered]@{id=$id;files=(CurrentFiles);device=(PreservedDevice);agent=(LiveRole 'agent' $newHashes.agent);helper=(LiveRole 'helper' $helperHash);job_mode=$false;clock_qualified=$false})
|
||||
Write-Output "Installed passive successor $id"
|
||||
return
|
||||
}
|
||||
RequireNewPassivePair
|
||||
$installed = LoadRecord 'installed'
|
||||
if ($installed.id -cne $id -or $installed.job_mode -ne $false -or $installed.clock_qualified -ne $false) { throw 'Expected passive installation.' }
|
||||
$activation = Marker 'profile-publish-intent'
|
||||
$ready = Marker 'profile-prepared'
|
||||
$success = Marker 'profile-published'
|
||||
if ($Action -ceq 'PrepareProfile') {
|
||||
VerifyPassiveContext
|
||||
if (Test-Path -LiteralPath $ready) { throw 'Profile already prepared: read only.' }
|
||||
BuildSuccessor
|
||||
Write-Output "Prepared successor profile $id"
|
||||
return
|
||||
}
|
||||
$prepared = LoadRecord 'profile-prepared'
|
||||
CheckPrepared
|
||||
VerifyPassiveContext
|
||||
$held = LoadRecord 'profile-independent-native-read'
|
||||
if (!(JsonEqual $held.agent (LiveRole 'agent' $newHashes.agent)) -or
|
||||
!(JsonEqual $held.helper (LiveRole 'helper' $helperHash)) -or
|
||||
!(JsonEqual $held.device (PreservedDevice))) { throw 'Actual passive role observations changed.' }
|
||||
Record 'profile-publish-intent' ([ordered]@{id=$id;utc=[DateTime]::UtcNow.ToString('o');prepared_sha256=(Hash $ready)})
|
||||
StopKnownRole 'agent' $agentName $held.agent 'time'
|
||||
StopKnownRole 'helper' $helperName $held.helper 'time'
|
||||
$locations.Add('time',$target)
|
||||
SwapFile 'time' (Join-Path $work 'new-time-profile') $prepared.predecessor $prepared.successor_sha256 'time'
|
||||
$locations.Remove('time')
|
||||
FinishPublication
|
||||
Reference in New Issue
Block a user