Fix Windows public-file rights and bind no-effect bootstrap resume
Rust development slice / linux (push) Failing after 8s
Rust development slice / linux (push) Failing after 8s
This commit is contained in:
@@ -220,6 +220,7 @@ def main():
|
||||
# by this module's CLI. Both existing daemons must already be quiescent/stopped;
|
||||
# starts and fresh signed-sync/native effect acceptance remain separate steps.
|
||||
APPLY_STOPPED = r'''
|
||||
param([switch]$ResumeNoEffectEb285544)
|
||||
$ErrorActionPreference='Stop'
|
||||
$p=([Console]::In.ReadLine()|ConvertFrom-Json)
|
||||
if($p.operation-cne'windows_system_script_scope_stopped_v1'-or$p.phase-cnotin@('apply-stopped','readback')){throw 'Fixed bootstrap operation'}
|
||||
@@ -235,7 +236,7 @@ function CheckPath([string]$path,[bool]$directory){$item=Get-Item -LiteralPath $
|
||||
function CheckStopped{if($null-eq$p.expected_service_processes-or@($p.expected_service_processes).Count-ne2){throw 'Two actual original process witnesses required'};foreach($old in @($p.expected_service_processes)){if([int]$old.pid-le0-or![string]$old.creation_filetime){throw 'Original kernel creation witness'};$live=Get-Process -Id ([int]$old.pid) -ErrorAction SilentlyContinue;if($null-ne$live){try{if($live.StartTime.ToUniversalTime().ToFileTimeUtc().ToString()-ceq$old.creation_filetime-and!$live.HasExited){throw 'Original service process still live'}}finally{$live.Dispose()}}};foreach($name in @('RmmDiscoveryWindows','RmmDiscoverySystemHelper')){$service=Get-CimInstance Win32_Service -Filter ("Name='"+$name+"'");if(!$service-or$service.State-cne'Stopped'){throw 'Coordinated quiescent pair stop required'}}}
|
||||
function PublicAcl{$acl=New-Object Security.AccessControl.FileSecurity;$acl.SetSecurityDescriptorSddlForm(('O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;0x1200a9;;;'+$agentSid+')(A;;0x1200a9;;;'+$helperSid+')'));return $acl}
|
||||
function WritePublicOnce([string]$path,[byte[]]$bytes){
|
||||
$rights=[Security.AccessControl.FileSystemRights]::ReadWrite
|
||||
$rights=[Security.AccessControl.FileSystemRights]([int][Security.AccessControl.FileSystemRights]::Read-bor[int][Security.AccessControl.FileSystemRights]::Write)
|
||||
$stream=New-Object IO.FileStream($path,[IO.FileMode]::CreateNew,$rights,[IO.FileShare]::Read,4096,[IO.FileOptions]::WriteThrough,(PublicAcl))
|
||||
try{$stream.Write($bytes,0,$bytes.Length);$stream.Flush($true)}finally{$stream.Dispose()}
|
||||
$null=CheckPath $path $false
|
||||
@@ -285,6 +286,17 @@ function PreservedFiles {
|
||||
}
|
||||
return ($result|ConvertTo-Json -Depth 8 -Compress)
|
||||
}
|
||||
function CheckExactNoEffectResume {
|
||||
if(!$ResumeNoEffectEb285544-or$caseId-cne'eb285544-3714-43e4-872e-5e43b75b9794'){throw 'Only the reviewed no-effect case can resume'}
|
||||
$null=CheckPath $case $true
|
||||
$leaves=@(Get-ChildItem -LiteralPath $case -Force)
|
||||
if($leaves.Count-ne1-or$leaves[0].Name-cne'intent.json'-or$leaves[0].PSIsContainer){throw 'Only untouched original intent permits resume'}
|
||||
$original=Join-Path $case 'intent.json';$null=CheckPath $original $false
|
||||
$expected='4c3019b04a92dd080590d4b157b7c975f26ae9874b29c6f0dcd75c36d35d9ef5'
|
||||
if((HashFile $original)-cne$expected-or(HashBytes ([Text.Encoding]::UTF8.GetBytes(($p|ConvertTo-Json -Depth 20 -Compress))))-cne$expected){throw 'Exact original intent bytes required'}
|
||||
if($p.old_settings_sha256-cne'3902a7d61829e6959442c9577e025e28262edbb87a0ac4ffd76565ee241ec754'-or$p.old_pin_sha256-cne'4e098eb3d18cceba81627d0d18c52f45521c9384c1412225f0628835f8fb82ca'-or$p.old_config_sha256-cne'5cd4cb9802d0dd20b961de7e3cd4e5874a1e9a72fc57b577e075e2d2918baac6'){throw 'Original no-effect control bytes required'}
|
||||
if((HashFile 'C:\ProgramData\RustDiscoverySystem\time-attestation.json')-cne'04cc3b58ab233715fa0abf118b8af6a5518fe3fcee7a5b6a7c79e09b19495d28'){throw 'Original no-effect clock profile required'}
|
||||
}
|
||||
$null=CheckPath 'C:\ProgramData\RustDiscoveryBootstrap' $true
|
||||
$null=CheckPath $helperRoot $true
|
||||
if($p.phase-ceq'readback'){
|
||||
@@ -298,11 +310,12 @@ $definitions=ServiceDefinitions
|
||||
if($p.helper_start_transition.before-cne'Manual'-or$p.helper_start_transition.after-cne'Auto'-or$definitions.RmmDiscoverySystemHelper.start_mode-cne'Manual'-or$definitions.RmmDiscoveryWindows.start_mode-cne'Auto'){throw 'Exact Manual to Auto helper transition only'}
|
||||
if((HashFile 'C:\ProgramData\RustDiscovery\config.json')-cne$p.old_config_sha256){throw 'Preserved active configuration CAS'}
|
||||
$locks=[RmmSystemScopeLocks]::new()
|
||||
$recordFailure=$false;$stage='original-preflight'
|
||||
try {
|
||||
$lockIds=($locks.LockIds()-join',');$preserved=PreservedFiles
|
||||
$null=CheckPath $targets.settings $false
|
||||
$null=CheckPath $targets.pin $false
|
||||
if(Test-Path -LiteralPath $case){throw 'Existing case means readback only'}
|
||||
if($ResumeNoEffectEb285544){CheckExactNoEffectResume}elseif(Test-Path -LiteralPath $case){throw 'Existing case means readback only'}
|
||||
foreach($name in @('native_result','qualification')){if(Test-Path -LiteralPath $targets[$name]){throw 'First script scope requires absent prior qualification files'}}
|
||||
if((HashFile $targets.settings)-cne$p.old_settings_sha256-or(HashFile $targets.pin)-cne$p.old_pin_sha256){throw 'Fresh original public settings and pin CAS'}
|
||||
if((HashFile 'C:\Program Files\RustDiscovery\rmm-agent-windows.exe')-cne$p.agent_binary_sha256-or(HashFile 'C:\Program Files\RustDiscovery\rmm-helper-windows.exe')-cne$p.helper_binary_sha256){throw 'Actual image pair required'}
|
||||
@@ -316,11 +329,22 @@ if($next.agent.binary_sha256-cne$p.agent_binary_sha256-or$next.helper.binary_sha
|
||||
$qualification=[Text.Encoding]::UTF8.GetString($payloads.qualification)|ConvertFrom-Json
|
||||
$native=[Text.Encoding]::UTF8.GetString($payloads.native_result)|ConvertFrom-Json
|
||||
if(($qualification.actions-join',')-cne'run_script'-or$qualification.policy_sha256-cne$p.policy_sha256-or$qualification.native_result_sha256-cne$p.files.native_result.sha256-or$native.scope-cne'native_prerequisites_only'-or$native.target_job_executed-ne$false-or$native.status-cne'passed'){throw 'Truthful prerequisite qualification only'}
|
||||
New-Item -ItemType Directory -Path $case|Out-Null
|
||||
$private=New-Object Security.AccessControl.DirectorySecurity;$private.SetSecurityDescriptorSddlForm('O:BAG:BAD:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)');Set-Acl -LiteralPath $case -AclObject $private
|
||||
WritePrivateOnce (Join-Path $case 'intent.json') ([Text.Encoding]::UTF8.GetBytes(($p|ConvertTo-Json -Depth 20 -Compress)))
|
||||
$stage='create-or-resume-intent'
|
||||
if($ResumeNoEffectEb285544){
|
||||
CheckExactNoEffectResume
|
||||
$recordFailure=$true
|
||||
WritePrivateOnce (Join-Path $case 'resume-no-effect-intent.json') ([Text.Encoding]::UTF8.GetBytes('{"schema_version":1,"case_id":"eb285544-3714-43e4-872e-5e43b75b9794","original_intent_sha256":"4c3019b04a92dd080590d4b157b7c975f26ae9874b29c6f0dcd75c36d35d9ef5","reason":"invalid_FileSystemRights_ReadWrite_enum_before_first_candidate","repeat_allowed":false}'))
|
||||
}else{
|
||||
New-Item -ItemType Directory -Path $case|Out-Null
|
||||
$private=New-Object Security.AccessControl.DirectorySecurity;$private.SetSecurityDescriptorSddlForm('O:BAG:BAD:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)');Set-Acl -LiteralPath $case -AclObject $private
|
||||
$recordFailure=$true
|
||||
WritePrivateOnce (Join-Path $case 'intent.json') ([Text.Encoding]::UTF8.GetBytes(($p|ConvertTo-Json -Depth 20 -Compress)))
|
||||
}
|
||||
WritePrivateOnce (Join-Path $case 'preserved-before-files.json') ([Text.Encoding]::UTF8.GetBytes($preserved))
|
||||
$stage='public-candidates'
|
||||
foreach($name in @('settings','pin','native_result','qualification')){WritePublicOnce (Join-Path $case ($name+'.candidate.json')) $payloads[$name]}
|
||||
foreach($name in @('settings','pin')){
|
||||
$stage='replace-'+$name
|
||||
CheckStopped
|
||||
$expected=if($name-ceq'settings'){$p.old_settings_sha256}else{$p.old_pin_sha256}
|
||||
if((HashFile $targets[$name])-cne$expected){throw 'Immediate original file CAS'}
|
||||
@@ -331,6 +355,7 @@ foreach($name in @('settings','pin')){
|
||||
$null=CheckPath $targets[$name] $false
|
||||
}
|
||||
foreach($name in @('native_result','qualification')){
|
||||
$stage='publish-'+$name
|
||||
CheckStopped
|
||||
if(Test-Path -LiteralPath $targets[$name]){throw 'Public prerequisite target appeared'}
|
||||
WritePrivateOnce (Join-Path $case ($name+'-publish-intent.json')) ([Text.Encoding]::UTF8.GetBytes('{"create_once":true}'))
|
||||
@@ -339,16 +364,23 @@ foreach($name in @('native_result','qualification')){
|
||||
$null=CheckPath $targets[$name] $false
|
||||
}
|
||||
CheckStopped
|
||||
$stage='helper-autostart'
|
||||
$current=ServiceDefinitions
|
||||
if(($current|ConvertTo-Json -Depth 6 -Compress)-cne($definitions|ConvertTo-Json -Depth 6 -Compress)){throw 'SCM changed before helper Automatic transition'}
|
||||
WritePrivateOnce (Join-Path $case 'helper-autostart-intent.json') ([Text.Encoding]::UTF8.GetBytes('{"from":"Manual","to":"Auto","no_start":true}'))
|
||||
[RmmSystemScopeLocks]::SetHelperAutomatic()
|
||||
$automatic=ServiceDefinitions
|
||||
if($automatic.RmmDiscoverySystemHelper.start_mode-cne'Auto'-or$automatic.RmmDiscoveryWindows.start_mode-cne'Auto'){throw 'Actual automatic startup readback'}
|
||||
$stage='final-preservation'
|
||||
if((PreservedFiles)-cne$preserved-or($locks.LockIds()-join',')-cne$lockIds){throw 'Original identities, journals, clock profile and locks must be preserved'}
|
||||
$result=@{schema_version=1;files_installed=$true;services_started=$false;target_job_executed=$false;approval_performed=$false;state_or_keys_changed=$false;helper_autostart='Auto';services=$automatic;policy_sha256=$p.policy_sha256;next='root must refresh actual SCM/role/time qualification then start pair once and verify fresh signed clock/sync; first actual SYSTEM job requires WebUI approval'}
|
||||
WritePrivateOnce (Join-Path $case 'completed.json') ([Text.Encoding]::UTF8.GetBytes(($result|ConvertTo-Json -Compress)))
|
||||
$result|ConvertTo-Json -Compress
|
||||
} catch {
|
||||
$failure=@{schema_version=1;error_code='SYSTEM_SCRIPT_SCOPE_BOOTSTRAP_FAILED';stage=$stage;exception_type=$_.Exception.GetType().FullName;hresult=$_.Exception.HResult;repeat_allowed=$false}
|
||||
if($recordFailure){try{$errorPath=Join-Path $case 'bootstrap-error.json';if(!(Test-Path -LiteralPath $errorPath)){WritePrivateOnce $errorPath ([Text.Encoding]::UTF8.GetBytes(($failure|ConvertTo-Json -Compress)))}}catch{}}
|
||||
$failure|ConvertTo-Json -Compress
|
||||
throw 'SYSTEM_SCRIPT_SCOPE_BOOTSTRAP_FAILED'
|
||||
} finally {$locks.Dispose()}
|
||||
'''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user