feat(admin): #1078 headless POST /api/cluster/failover (key-gated, same service+audit) and unattended SCM-restart gate
fix(install): #1075 worker identity gets read+execute (not Modify) on <PeCacheDir>\pe; re-run replaces the old grant
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
makes must pass for the host account AND that set.
|
||||
2. PeCacheDir created; ACL replaced: protected, owner Administrators, SYSTEM + Administrators + the host
|
||||
account full control. No Users, no worker access (the HMAC key and launch markers live here).
|
||||
3. PeEntriesDir <PeCacheDir>\pe, the worker identity gets Modify (workers compile and write HMAC'd entries).
|
||||
3. PeEntriesDir <PeCacheDir>\pe, the worker identity gets read+execute only (the host writes entries since #1014; a re-run replaces an older Modify grant, #1075).
|
||||
4. WorkerFolderAcl <InstallRoot>\script-worker, the worker identity gets read + execute.
|
||||
5. InstallRootDeny <InstallRoot>, the worker identity is DENIED read and write (inherited): ReadData/List,
|
||||
WriteData/AddFile, AppendData/AddSubdirectory, WriteAttributes/EA, Delete, DeleteChild,
|
||||
|
||||
@@ -72,7 +72,7 @@ function Get-OtOpcUaPeCacheSddl {
|
||||
The PeCacheDir root's security descriptor: owner Administrators, PROTECTED (no inherited Users/Everyone/
|
||||
Authenticated Users), SYSTEM + Administrators + the host account full control (container + object inherit).
|
||||
The worker identity gets NOTHING here — the HMAC key (pe-cache.key) and the launch markers (workers\) stay
|
||||
host-only; the worker's one writable place is the pe\ subfolder (Get-OtOpcUaPeEntriesAce).
|
||||
host-only; the worker can only READ the pe\ subfolder (Get-OtOpcUaPeEntriesAce, #1075).
|
||||
#>
|
||||
param([Parameter(Mandatory)] [string]$HostSid)
|
||||
$aces = @(
|
||||
@@ -84,9 +84,11 @@ function Get-OtOpcUaPeCacheSddl {
|
||||
}
|
||||
|
||||
function Get-OtOpcUaPeEntriesAce {
|
||||
# pe\ : the worker compiles in-process (owner decision §14 #7) and writes HMAC'd entries here — Modify, inherited.
|
||||
# pe\ : read and execute only, inherited (lmxopcua#1075). Since #1014 the host verifies, compiles and writes every entry and
|
||||
# sends verified images over the pipe, so the worker never writes here. Set-OtOpcUaExplicitAce PURGES the identity's existing
|
||||
# explicit ACEs before adding this one, so a re-run on a box installed with the old Modify grant replaces it (idempotent upgrade).
|
||||
param([Parameter(Mandatory)] [string]$WorkerSid)
|
||||
Format-OtOpcUaAce -Type A -Flags 'OICI' -Mask $script:Modify -Sid $WorkerSid
|
||||
Format-OtOpcUaAce -Type A -Flags 'OICI' -Mask $script:ReadAndExecute -Sid $WorkerSid
|
||||
}
|
||||
|
||||
function Get-OtOpcUaScriptWorkerFolderAce {
|
||||
@@ -220,8 +222,8 @@ function Get-ScriptWorkerIsolationPlan {
|
||||
"create the PE cache directory and set its ACL (protected; SYSTEM, Administrators, host account full control; no Users; no worker access to the key or markers)" `
|
||||
@{ Path = $cache; Sddl = (Get-OtOpcUaPeCacheSddl -HostSid $HostSid) }))
|
||||
$steps.Add((New-OtOpcUaPlanStep 'PeEntriesDir' $entries `
|
||||
"create the PE entries directory and grant the worker identity Modify (it compiles and writes HMAC'd entries)" `
|
||||
@{ Path = $entries; Ace = (Get-OtOpcUaPeEntriesAce -WorkerSid $workerSid); Sid = $workerSid; Mask = $script:Modify; Type = 'Allow' }))
|
||||
"create the PE entries directory and grant the worker identity read+execute only (host-side signing since #1014; replaces an older Modify grant on re-run)" `
|
||||
@{ Path = $entries; Ace = (Get-OtOpcUaPeEntriesAce -WorkerSid $workerSid); Sid = $workerSid; Mask = $script:ReadAndExecute; Type = 'Allow' }))
|
||||
$steps.Add((New-OtOpcUaPlanStep 'WorkerFolderAcl' $workerFolder `
|
||||
"grant the worker identity read+execute on its own binaries" `
|
||||
@{ Path = $workerFolder; Ace = (Get-OtOpcUaScriptWorkerFolderAce -WorkerSid $workerSid); Sid = $workerSid; Mask = $script:ReadAndExecute; Type = 'Allow' }))
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
node did not exit non-zero" when leg 2 fails.
|
||||
|
||||
Triggers (-Trigger):
|
||||
Failover (default) the script pauses and asks the operator to press "Trigger failover" on the AdminUI cluster
|
||||
Failover (default) with -FailoverUrl + a key (-FailoverApiKey or env OTOPCUA_FAILOVER_API_KEY) the script POSTs the
|
||||
headless failover endpoint (lmxopcua#1078, POST /api/cluster/failover on an admin node, key =
|
||||
Security:FailoverApiKey) - unattended. Without them the script pauses and asks the operator to press "Trigger failover" on the AdminUI cluster
|
||||
redundancy page (/clusters/{id}/redundancy). Manual failover asks the driver PRIMARY to leave, so run this on
|
||||
the box hosting the current Primary of a two-node pair. Needs an interactive console.
|
||||
Command runs -TriggerCommand (a PowerShell script block, as text) that makes THIS node leave or be downed, e.g. a
|
||||
@@ -43,6 +45,14 @@
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File scripts\install\tests\Test-ScmRestartAfterClusterExit.Windows.ps1 -KillControl
|
||||
pwsh -NoProfile -File ...\Test-ScmRestartAfterClusterExit.Windows.ps1 -Trigger Command -TriggerCommand '<script>'
|
||||
|
||||
.PARAMETER FailoverUrl
|
||||
Base URL of an admin node of THIS node's cluster (e.g. http://central-1:9200). With a key, -Trigger Failover calls
|
||||
POST <FailoverUrl>/api/cluster/failover instead of prompting; the call is audited as cluster.manual-failover with actor
|
||||
rest-api:Test-ScmRestartAfterClusterExit. HTTP 409 = no peer (refused, nothing changed) and the script exits 2.
|
||||
|
||||
.PARAMETER FailoverApiKey
|
||||
The value of Security:FailoverApiKey. Defaults to env OTOPCUA_FAILOVER_API_KEY. Never commit it.
|
||||
|
||||
.PARAMETER ServiceName
|
||||
The service under test (default OtOpcUaHost, as Install-Services.ps1 names it).
|
||||
|
||||
@@ -54,6 +64,8 @@ param(
|
||||
[string]$ServiceName = 'OtOpcUaHost',
|
||||
[ValidateSet('Failover', 'Command')][string]$Trigger = 'Failover',
|
||||
[string]$TriggerCommand,
|
||||
[string]$FailoverUrl,
|
||||
[string]$FailoverApiKey = $env:OTOPCUA_FAILOVER_API_KEY,
|
||||
[int]$TimeoutSeconds = 180,
|
||||
[switch]$SkipStopControl,
|
||||
[switch]$KillControl)
|
||||
@@ -65,7 +77,9 @@ if ($PSVersionTable.PSEdition -eq 'Core' -and -not $IsWindows) { Write-Host 'SKI
|
||||
$principal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host 'run elevated'; exit 2 }
|
||||
if ($Trigger -eq 'Command' -and [string]::IsNullOrWhiteSpace($TriggerCommand)) { Write-Host '-Trigger Command needs -TriggerCommand'; exit 2 }
|
||||
if ($Trigger -eq 'Failover' -and -not [Environment]::UserInteractive) { Write-Host '-Trigger Failover needs an interactive console (use -Trigger Command)'; exit 2 }
|
||||
$useEndpoint = $Trigger -eq 'Failover' -and $FailoverUrl -and $FailoverApiKey
|
||||
if ($Trigger -eq 'Failover' -and ($FailoverUrl -xor $FailoverApiKey)) { Write-Host '-FailoverUrl and a key (-FailoverApiKey / OTOPCUA_FAILOVER_API_KEY) must be given together'; exit 2 }
|
||||
if ($Trigger -eq 'Failover' -and -not $useEndpoint -and -not [Environment]::UserInteractive) { Write-Host '-Trigger Failover needs an interactive console, or -FailoverUrl + a key (or use -Trigger Command)'; exit 2 }
|
||||
|
||||
$svc = Get-CimInstance Win32_Service -Filter "Name='$ServiceName'"
|
||||
if (-not $svc) { Write-Host "service $ServiceName is not installed"; exit 2 }
|
||||
@@ -124,7 +138,20 @@ try {
|
||||
$before = Get-ServicePid
|
||||
$proc = Watch-ServiceProcess $before
|
||||
$since = (Get-Date).AddSeconds(-1)
|
||||
if ($Trigger -eq 'Failover') {
|
||||
if ($useEndpoint) {
|
||||
$uri = $FailoverUrl.TrimEnd('/') + '/api/cluster/failover'
|
||||
Write-Host " POST $uri"
|
||||
try {
|
||||
$resp = Invoke-RestMethod -Method Post -Uri $uri -Headers @{ 'X-Api-Key' = $FailoverApiKey; 'X-Actor' = 'Test-ScmRestartAfterClusterExit' } -TimeoutSec 30
|
||||
Write-Host " failover accepted; leaving node: $($resp.leavingNode)"
|
||||
}
|
||||
catch {
|
||||
$code = if ($_.Exception.Response) { [int]$_.Exception.Response.StatusCode } else { 0 }
|
||||
Write-Host " failover endpoint failed (HTTP $code): $($_.Exception.Message)"
|
||||
exit 2
|
||||
}
|
||||
}
|
||||
elseif ($Trigger -eq 'Failover') {
|
||||
Write-Host ' Press "Trigger failover" on the AdminUI cluster redundancy page for THIS node''s cluster (this node must be the'
|
||||
Write-Host ' driver Primary), then press Enter here.'
|
||||
$null = Read-Host
|
||||
|
||||
@@ -58,8 +58,8 @@ Assert ($sysSddl -eq 'O:BAG:SYD:PAI(A;OICI;0x1f01ff;;;SY)(A;OICI;0x1f01ff;;;BA)'
|
||||
|
||||
$pe = $byId['PeEntriesDir'].Data
|
||||
Assert ($pe.Path -eq "$cache\pe" -or $pe.Path -eq "$cache/pe") "entries dir is <PeCacheDir>\pe ($($pe.Path))"
|
||||
Assert ($pe.Ace -eq "(A;OICI;0x1301bf;;;$workerSid)") "worker gets Modify on pe\ ($($pe.Ace))"
|
||||
Assert ($pe.Type -eq 'Allow' -and $pe.Mask -eq 0x1301BF -and $pe.Sid -eq $workerSid) 'pe\ ACE data matches its SDDL'
|
||||
Assert ($pe.Ace -eq "(A;OICI;0x1200a9;;;$workerSid)") "worker gets read+execute only on pe\ ($($pe.Ace))"
|
||||
Assert ($pe.Type -eq 'Allow' -and $pe.Mask -eq 0x1200A9 -and $pe.Sid -eq $workerSid) 'pe\ ACE data matches its SDDL'
|
||||
|
||||
$wf = $byId['WorkerFolderAcl'].Data
|
||||
Assert ($wf.Ace -eq "(A;OICI;0x1200a9;;;$workerSid)") "worker gets read+execute on script-worker\ ($($wf.Ace))"
|
||||
|
||||
Reference in New Issue
Block a user