test(validation): #800 gate re-run on windev with the fixed isolation installer, both PowerShell hosts
v2-ci / unit-tests (push) Has been cancelled

Re-runs only the ScriptWorker step on windev (master da948e5f, SDK 2.0.1, 16 vCPUs): install as the OtOpcUaHost service,
repo Install-ScriptWorkerIsolation.ps1 applied/re-applied/uninstalled twice under pwsh 7 and Windows PowerShell 5.1,
restricted worker, pipe refuses the admin, runner Healthy, strict-peer/API-key matrix on, then cleanup. The harness drops
-PatchedIsolation, gains -PrepareFrom candidate and -ApplyHost, and suffixes the isolation evidence with -Label.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-12 11:24:00 -05:00
parent 88e53f7f84
commit 1172687d4b
61 changed files with 7736 additions and 28 deletions
@@ -12,16 +12,17 @@
process environment variables, never through arguments or output. Evidence (no secrets) goes to <Root>\evidence.
Phases, in order:
Prepare dirs + ACLs, secrets, baseline staged into <Root>\OtOpcUa, Install-Services.ps1, node env
Prepare dirs + ACLs, secrets, baseline (or -PrepareFrom candidate) staged into <Root>\OtOpcUa, Install-Services.ps1, node env
Boot -Label L Start-Service, wait for readiness, snapshot PKI/ACLs, health
Seed (after the first Stop) seed the deployment into the service-created LocalDb
Trust cross-trust the probe/CLI certificates with the server PKI
Checks -Label L strict-peer/API-key/anonymous probe matrix + the actual CLI read
Stop -Label L Stop-Service, exit code, redaction scan of the logs and event log
Upgrade backup, stage the candidate separately, carry config/PKI/LocalDb with ACLs, swap folders
IsolationInstall Install-ScriptWorkerIsolation.ps1 (-WhatIf, apply, re-apply) + Scripting__Runner=OutOfProcess
IsolationInstall Install-ScriptWorkerIsolation.ps1 (-WhatIf on both PowerShell hosts, apply with -ApplyHost, re-apply with the
other host and again with -ApplyHost) + Scripting__Runner=OutOfProcess
IsolationVerify (service running) worker processes, restricted token, pipe ACL, firewall rule, PE cache
IsolationUninstall -Uninstall twice, Scripting__Runner removed
IsolationUninstall -Uninstall with -ApplyHost, then with the other host (idempotent), Scripting__Runner removed
Rollback quarantine the candidate, restore the known-good folder, carry current PKI/LocalDb back
Compare compare every PKI snapshot and the node environment across labels
Cleanup delete the service, isolation leftovers, CLI state, the root folder (evidence copied first)
@@ -43,7 +44,15 @@ param(
# 64 bytes (every production 65-character API key) as RsaEncryptedSecret, which that server rejects; the production
# SDK 2 CLI forces the legacy format since lmxopcua#880 and must be admitted. See README.md.
[switch]$BaselineServer,
[switch]$PatchedIsolation
# Prepare: which build the service is first installed from. 'baseline' (default) is the upgrade/rollback flow; 'candidate'
# installs the SDK 2 build directly, with the install scripts of the same tree (used to re-run only the isolation step).
[ValidateSet('baseline', 'candidate')]
[string]$PrepareFrom = 'baseline',
# IsolationInstall / IsolationUninstall: the PowerShell host that applies / rolls back first ('pwsh' = 7, 'powershell.exe' = 5.1).
# The other host does the re-apply and the second uninstall, so running both phases once per value exercises each host as the
# applying host and as the re-applying host. Evidence files are suffixed with -Label.
[ValidateSet('pwsh', 'powershell.exe')]
[string]$ApplyHost = 'pwsh'
)
Set-StrictMode -Version Latest
@@ -184,10 +193,8 @@ function Get-ServiceRecord {
}
function Invoke-Isolation([string[]]$Extra, [string]$PsHost = 'powershell.exe') {
# lmxopcua#883: the repository installer fails on both hosts (PowerShell 7: no DirectoryInfo.GetAccessControl;
# 5.1: StrictMode .Count on a scalar), and so does -Uninstall. With -PatchedIsolation the gate uses the #883 patch
# (install-candidate-patched) so the runtime isolation can still be exercised.
$dir = if ($PatchedIsolation) { 'install-candidate-patched' } else { 'install-candidate' }
# The repository installer from the candidate tree. (Until lmxopcua#883 was fixed it failed on both hosts, and so did -Uninstall.)
$dir = 'install-candidate'
$script = Join-Path $Upload "$dir\Install-ScriptWorkerIsolation.ps1"
$out = & $PsHost -NoProfile -ExecutionPolicy Bypass -File $script -InstallRoot $Install -HostServiceAccount $ServiceAccount `
-PeCacheDir $PeCache -ConfigureHostService @Extra 2>&1 | Out-String
@@ -274,11 +281,12 @@ switch ($Phase) {
}
$s = Get-Secrets
# Known-good binaries into the service path, with an explicit service-account ACL.
robocopy (Join-Path $Upload 'baseline-host') $Install /E /R:1 /W:1 /NFL /NDL /NJH /NP | Out-Null
$from = $PrepareFrom
robocopy (Join-Path $Upload "$from-host") $Install /E /R:1 /W:1 /NFL /NDL /NJH /NP | Out-Null
if ($LASTEXITCODE -ge 8) { throw 'baseline copy failed' }
# The repository-supported install (Install-Services.ps1) creates the service and its 2-entry environment.
# It runs first because the NT SERVICE\ virtual account only resolves once its service exists.
& (Join-Path $Upload 'install-baseline\Install-Services.ps1') -InstallRoot $Install -ServiceAccount $ServiceAccount -Roles driver
& (Join-Path $Upload "install-$from\Install-Services.ps1") -InstallRoot $Install -ServiceAccount $ServiceAccount -Roles driver
if (-not (Get-Service $Service -ErrorAction SilentlyContinue)) { throw 'Install-Services.ps1 did not create the service' }
Add-AllowRule $Install $ServiceAccount 'ReadAndExecute'
foreach ($d in 'pki', 'data', 'logs') {
@@ -454,16 +462,23 @@ switch ($Phase) {
if ((Get-Service $Service).Status -ne 'Stopped') { throw 'stop the service first' }
$envBefore = @(Get-EnvNames)
$aclBefore = (& icacls $Install | Out-String)
$whatIf = Invoke-Isolation @('-WhatIf') 'pwsh'
$otherHost = if ($ApplyHost -eq 'pwsh') { 'powershell.exe' } else { 'pwsh' }
$whatIf = Invoke-Isolation @('-WhatIf') $ApplyHost
$whatIfOther = Invoke-Isolation @('-WhatIf') $otherHost
$whatIfChanged = ((& icacls $Install | Out-String) -ne $aclBefore) -or [bool](Get-NetFirewallRule -Name 'OtOpcUa-ScriptWorker-BlockOutbound' -ErrorAction SilentlyContinue) -or ((@(Get-EnvNames) -join ',') -ne ($envBefore -join ','))
$apply = Invoke-Isolation @() 'pwsh'
$again = Invoke-Isolation @() 'powershell.exe'
if ($apply.exit -ne 0 -or $again.exit -ne 0) { throw "isolation install failed: $($apply.output)$($again.output)" }
$apply = Invoke-Isolation @() $ApplyHost
$again = Invoke-Isolation @() $otherHost
$againSame = Invoke-Isolation @() $ApplyHost
foreach ($r in $whatIf, $whatIfOther, $apply, $again, $againSame) {
if ($r.exit -ne 0) { throw "isolation install failed ($($r.host) $($r.args)): $($r.output)" }
}
$env = @((Get-ItemProperty -Path $SvcKey -Name Environment).Environment) + 'Scripting__Runner=OutOfProcess'
Set-ItemProperty -Path $SvcKey -Name Environment -Type MultiString -Value ([string[]]$env)
$rule = Get-NetFirewallRule -Name 'OtOpcUa-ScriptWorker-BlockOutbound'
Write-Evidence 'isolation-install' ([ordered]@{ whatIf = $whatIf; whatIfChangedState = $whatIfChanged; apply = $apply; reapply = $again
reapplyAllUnchanged = -not ($again.output -match '\[(?!unchanged)[a-z]+\s*\]')
Write-Evidence "isolation-install-$Label" ([ordered]@{ applyHost = $ApplyHost; whatIf = $whatIf; whatIfOtherHost = $whatIfOther; whatIfChangedState = $whatIfChanged
apply = $apply; reapply = $again; reapplySameHost = $againSame
reapplyAllUnchanged = (-not ($again.output -match '\[(?!unchanged)[a-z]+\s*\]')) -and (-not ($againSame.output -match '\[(?!unchanged)[a-z]+\s*\]'))
reapplyStepCounts = @(([regex]::Matches($again.output, '\[unchanged\s*\]')).Count, ([regex]::Matches($againSame.output, '\[unchanged\s*\]')).Count)
envBefore = $envBefore; envAfter = @(Get-EnvNames)
anchor = (& sc.exe qc OtOpcUaScriptWorker | Out-String); anchorSid = (& sc.exe showsid OtOpcUaScriptWorker | Out-String)
installAcl = (& icacls $Install | Out-String); workerDirAcl = (& icacls (Join-Path $Install 'script-worker') | Out-String)
@@ -506,19 +521,20 @@ public static class Tok {
[ordered]@{ pipe = 'otopcua-sw-<random>'; adminConnect = $outcome }
})
$ready = Invoke-Http '/health/ready'
Write-Evidence 'isolation-verify' ([ordered]@{ hostPid = $hostPid; workers = $procs; pipes = $pipeChecks; ready = $ready
Write-Evidence "isolation-verify-$Label" ([ordered]@{ hostPid = $hostPid; workers = $procs; pipes = $pipeChecks; ready = $ready
peFiles = @(Get-ChildItem (Join-Path $PeCache 'pe') -File -ErrorAction SilentlyContinue).Count
hostLogWorkerLines = @(Get-ChildItem (Join-Path $Install 'logs') -File | ForEach-Object { (Read-SharedText $_.FullName) -split "`r?`n" } |
Where-Object { $_ -match 'ScriptWorker|script-runner|OutOfProcess' } | Select-Object -Last 30 | ForEach-Object { Protect-Text $_ }) })
}
'IsolationUninstall' {
if ((Get-Service $Service).Status -ne 'Stopped') { throw 'stop the service first' }
$first = Invoke-Isolation @('-Uninstall') 'powershell.exe'
$second = Invoke-Isolation @('-Uninstall') 'pwsh'
if ($first.exit -ne 0 -or $second.exit -ne 0) { throw "isolation uninstall failed: $($first.output)$($second.output)" }
$otherHost = if ($ApplyHost -eq 'pwsh') { 'powershell.exe' } else { 'pwsh' }
$first = Invoke-Isolation @('-Uninstall') $ApplyHost
$second = Invoke-Isolation @('-Uninstall') $otherHost
foreach ($r in $first, $second) { if ($r.exit -ne 0) { throw "isolation uninstall failed ($($r.host)): $($r.output)" } }
$env = @((Get-ItemProperty -Path $SvcKey -Name Environment).Environment | Where-Object { $_ -notlike 'Scripting__Runner=*' })
Set-ItemProperty -Path $SvcKey -Name Environment -Type MultiString -Value ([string[]]$env)
Write-Evidence 'isolation-uninstall' ([ordered]@{ first = $first; second = $second
Write-Evidence "isolation-uninstall-$Label" ([ordered]@{ applyHost = $ApplyHost; first = $first; second = $second
secondAllUnchanged = -not ($second.output -match '\[(?!unchanged)[a-z]+\s*\]')
anchorGone = -not (Get-Service OtOpcUaScriptWorker -ErrorAction SilentlyContinue)
firewallGone = -not (Get-NetFirewallRule -Name 'OtOpcUa-ScriptWorker-BlockOutbound' -ErrorAction SilentlyContinue)