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:
@@ -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