From 9109e4e9056ecc027dae4ad1bef0af2d81982d56 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Thu, 19 Nov 2026 16:13:55 -0500 Subject: [PATCH] docs(deploy): QA vq03/vq04 on 2e0ce81e (#144/#145) + NAM AD login, one window Claude-Session: https://claude.ai/code/session_01GT67AD5mc2BnaaAfY3hqqQ --- .../2026-11-19-144-145/qa.tmpl.ps1 | 131 ++++++++++++++++++ ...026-11-19-wonder-app-vq03-vq04-2e0ce81e.md | 37 +++++ 2 files changed, 168 insertions(+) create mode 100644 docs/deployment/deploy-prep/2026-11-19-144-145/qa.tmpl.ps1 create mode 100644 docs/deployment/deployment-records/2026-11-19-wonder-app-vq03-vq04-2e0ce81e.md diff --git a/docs/deployment/deploy-prep/2026-11-19-144-145/qa.tmpl.ps1 b/docs/deployment/deploy-prep/2026-11-19-144-145/qa.tmpl.ps1 new file mode 100644 index 00000000..29b8e838 --- /dev/null +++ b/docs/deployment/deploy-prep/2026-11-19-144-145/qa.tmpl.ps1 @@ -0,0 +1,131 @@ +# ScadaBridge QA (vq03/vq04) 061432c8 -> 2e0ce81e (#144/#145, no migration) + NAM AD LDAP, one window. Rendered per call: ACTION / TS. +# prep | backup (vq03) | stop-site | stop-central | swap | start-central | start-site | verify | rollback-swap +# Derived from ScadaBridge deploy-prep/2026-11-15-143/qa.tmpl.ps1 (migrate dropped; the swap also installs the per-node NAM +# appsettings.Central.json and removes the GLAuth password env entry from the Central service). +$ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' +$Action = '__ACTION__' +$ts = '__TS__' +$sha = '2e0ce81e' +$fromSha = '061432c8' +$zipSha256 = '6C706B0A76B7E9EC7CA00E12CEA19C5D86814BEAF66B541F527CBFC3D6572E23' +$stageDir = "E:\psrem-stage\sb-$sha" +$stage = "$stageDir\unpacked" +$root = 'E:\ApiInstall\ScadaBridge' +$log = "$root\_DEPLOY-NOTES-$sha-$ts.txt" +$settings = 'appsettings.json','appsettings.Central.json','appsettings.Site.json' +$centralKey = 'HKLM:\SYSTEM\CurrentControlSet\Services\ScadaBridge-Central' +$namCentral = "$stageDir\appsettings.Central.json.nam-" + $env:COMPUTERNAME.Substring($env:COMPUTERNAME.Length-4).ToLower() +$bak = "F:\MSSQL\BACKUP\ScadaBridge_pre-$($sha)_$ts.bak" +function Say($m) { $line = "[{0:HH:mm:ss.fff}] {1} {2}" -f (Get-Date), $env:COMPUTERNAME, $m; $line; Add-Content -Path $log -Value $line } +function Is-Dropped($e) { $e -like 'ScadaBridge__Security__Ldap__ServiceAccountPassword=*' } +function Digest($entries) { + $h = [System.Security.Cryptography.SHA256]::Create(); $o = @() + foreach ($e in $entries) { $i = $e.IndexOf('='); if ($i -lt 1) { $o += ''; continue } + $v = $e.Substring($i+1); $x = -join ($h.ComputeHash([Text.Encoding]::UTF8.GetBytes($v)) | % { $_.ToString('x2') }) + $o += ("{0} sha256:{1} len={2}" -f $e.Substring(0,$i), $x.Substring(0,12), $v.Length) } + $h.Dispose(); $o | Sort-Object +} +function Wait-Ready($url, $seconds) { + $deadline = (Get-Date).AddSeconds($seconds) + while ((Get-Date) -lt $deadline) { try { if ((Invoke-WebRequest -UseBasicParsing $url -TimeoutSec 5).StatusCode -eq 200) { return $true } } catch {}; Start-Sleep 2 } + return $false +} +function Stop-Svc($s) { + if ((Get-Service $s).Status -ne 'Stopped') { Say "stopping $s"; Stop-Service $s -Force; (Get-Service $s).WaitForStatus('Stopped','00:02:00') } + Say "$s stopped" +} +function Sql-Init { + $envC = @((Get-ItemProperty $centralKey).Environment) + $cs = ($envC | Where-Object { $_ -like 'ScadaBridge__Database__ConfigurationDb=*' }) -replace '^[^=]*=','' + $script:sb = New-Object System.Data.SqlClient.SqlConnectionStringBuilder $cs + $script:db = $sb['Database']; if (-not $db) { $script:db = $sb.InitialCatalog } + if ($db -ne 'ScadaBridge') { throw "unexpected catalog" } + $env:SQLCMDPASSWORD = $sb.Password +} +function Sql-Scalar($q) { $r = & sqlcmd -S $sb.DataSource -d $db -U $sb.UserID -C -h -1 -W -b -Q "SET NOCOUNT ON; $q"; if ($LASTEXITCODE -ne 0) { throw "sql failed" }; ($r | Where-Object { $_ -and $_.Trim() } | Select-Object -First 1).Trim() } +$schemaQ = "SELECT CONCAT((SELECT COUNT(*) FROM __EFMigrationsHistory),'|',(SELECT MAX(MigrationId) FROM __EFMigrationsHistory),'|',(SELECT COUNT_BIG(*) FROM dbo.AuditLog))" + +switch ($Action) { +'prep' { + Say "PREP $fromSha -> $sha" + if ((Get-FileHash "$stageDir\scadabridge-$sha.zip" -Algorithm SHA256).Hash -ne $zipSha256) { throw "zip hash mismatch" } + if (-not (Test-Path $namCentral)) { throw "missing $namCentral" } + Get-Content $namCentral -Raw | ConvertFrom-Json | Out-Null + if (Test-Path $stage) { Remove-Item $stage -Recurse -Force } + Expand-Archive "$stageDir\scadabridge-$sha.zip" $stage + $sv = (Get-Item "$stage\app\ZB.MOM.WW.ScadaBridge.Host.exe").VersionInfo.ProductVersion + $sc = (Get-Item "$stage\cli\scadabridge.exe").VersionInfo.ProductVersion + if ($sv -notlike "*+$sha*" -or $sc -notlike "*+$sha*") { throw "staged exe $sv / $sc" } + $lv = (Get-Item "$root\app\ZB.MOM.WW.ScadaBridge.Host.exe").VersionInfo.ProductVersion + if ($lv -notlike "*+$fromSha*") { throw "live exe $lv" } + Say "staged $sv; live $lv; app files $((Get-ChildItem "$stage\app" -Recurse -File).Count), cli $((Get-ChildItem "$stage\cli" -Recurse -File).Count)" + foreach ($s in 'ScadaBridge-Central','ScadaBridge-Site') { + & reg.exe export "HKLM\SYSTEM\CurrentControlSet\Services\$s" "$stageDir\_envbak-$s-$ts.reg" /y | Out-Null + if ($LASTEXITCODE -ne 0) { throw "reg export $s failed" } + $e = @((Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\$s").Environment) + Say ("$s env entries {0}" -f $e.Count); Digest $e | % { Say " env $s $_" } + } + $keep = New-Item -ItemType Directory -Force -Path "$root\_appsettings-keep-$ts" + foreach ($f in $settings) { Copy-Item "$root\app\$f" "$keep\$f"; Say ("keep {0} sha256 {1}" -f $f, (Get-FileHash "$keep\$f" -Algorithm SHA256).Hash) } +} +'backup' { + Sql-Init + $pre = Sql-Scalar $schemaQ; Say "schema before: $pre" + if (-not $pre.StartsWith('65|')) { throw "expected 65 migrations" } + & sqlcmd -S $sb.DataSource -d master -U $sb.UserID -C -b -Q "BACKUP DATABASE [$db] TO DISK = N'$bak' WITH COPY_ONLY, CHECKSUM, COMPRESSION, INIT" | Out-Null + if ($LASTEXITCODE -ne 0) { throw "backup failed" } + & sqlcmd -S $sb.DataSource -d master -U $sb.UserID -C -b -Q "RESTORE VERIFYONLY FROM DISK = N'$bak' WITH CHECKSUM" | Out-Null + if ($LASTEXITCODE -ne 0) { throw "verifyonly failed" } + Say "backup $bak VERIFYONLY ok" +} +'stop-site' { Stop-Svc 'ScadaBridge-Site' } +'stop-central' { + Stop-Svc 'ScadaBridge-Central' + $deadline = (Get-Date).AddSeconds(30) + while ((Get-Process -Name 'ZB.MOM.WW.ScadaBridge.Host' -ErrorAction SilentlyContinue) -and (Get-Date) -lt $deadline) { Start-Sleep 1 } + if (Get-Process -Name 'ZB.MOM.WW.ScadaBridge.Host' -ErrorAction SilentlyContinue) { throw "Host.exe still running" } + Say "no Host.exe remains" +} +'swap' { + if (Get-Process -Name 'ZB.MOM.WW.ScadaBridge.Host' -ErrorAction SilentlyContinue) { throw "Host.exe running" } + Rename-Item "$root\app" "app.bak.$ts"; Rename-Item "$root\cli" "cli.bak.$ts" + Say "renamed app/cli -> *.bak.$ts" + Copy-Item "$stage\app" "$root\app" -Recurse + Copy-Item "$stage\cli" "$root\cli" -Recurse + $keep = "$root\_appsettings-keep-$ts" + foreach ($f in $settings) { + Copy-Item "$keep\$f" "$root\app\$f" -Force + if ((Get-FileHash "$keep\$f" -Algorithm SHA256).Hash -ne (Get-FileHash "$root\app\$f" -Algorithm SHA256).Hash) { throw "appsettings mismatch $f" } + Say "restored $f (sha256 match)" + } + Copy-Item $namCentral "$root\app\appsettings.Central.json" -Force + Say ("installed NAM appsettings.Central.json sha256 {0}" -f (Get-FileHash "$root\app\appsettings.Central.json" -Algorithm SHA256).Hash) + Say ("live Host " + (Get-Item "$root\app\ZB.MOM.WW.ScadaBridge.Host.exe").VersionInfo.ProductVersion + " / CLI " + (Get-Item "$root\cli\scadabridge.exe").VersionInfo.ProductVersion) + $before = @((Get-ItemProperty $centralKey).Environment) + $keepEnv = @($before | Where-Object { -not (Is-Dropped $_) }) + Set-ItemProperty -Path $centralKey -Name Environment -Value ([string[]]$keepEnv) -Type MultiString + $after = @((Get-ItemProperty $centralKey).Environment) + foreach ($e in $keepEnv) { if ($after -notcontains $e) { throw "env entry changed" } } + if (@($after | ? { Is-Dropped $_ }).Count -ne 0) { throw "GLAuth password entry still present" } + Say ("central env entries {0} -> {1}" -f $before.Count, $after.Count) +} +'start-central' { Say "starting ScadaBridge-Central"; Start-Service 'ScadaBridge-Central'; $ok = Wait-Ready 'http://localhost:8085/health/ready' 180; Say "central ready=$ok"; if (-not $ok) { throw "central not ready" } } +'start-site' { Say "starting ScadaBridge-Site"; Start-Service 'ScadaBridge-Site'; $ok = Wait-Ready 'http://localhost:8084/health/ready' 180; Say "site ready=$ok"; if (-not $ok) { throw "site not ready" } } +'verify' { + foreach ($s in 'ScadaBridge-Central','ScadaBridge-Site') { Say ("$s " + (Get-Service $s).Status) } + if ($env:COMPUTERNAME -eq 'WONDER-APP-VQ03') { Sql-Init; Say ("schema now: " + (Sql-Scalar $schemaQ)) } +} +'rollback-swap' { + foreach ($s in 'ScadaBridge-Site','ScadaBridge-Central') { Stop-Svc $s } + if (Test-Path "$root\app") { Rename-Item "$root\app" "app.failed.$ts" } + if (Test-Path "$root\cli") { Rename-Item "$root\cli" "cli.failed.$ts" } + Rename-Item "$root\app.bak.$ts" 'app'; Rename-Item "$root\cli.bak.$ts" 'cli' + & reg.exe import "$stageDir\_envbak-ScadaBridge-Central-$ts.reg" | Out-Null + Say "rolled back binaries + Central env (services left STOPPED; start Central vq03, vq04, then Sites)" +} +default { throw "bad action $Action" } +} +Remove-Item Env:SQLCMDPASSWORD -ErrorAction SilentlyContinue +Say "$Action OK" +exit 0 diff --git a/docs/deployment/deployment-records/2026-11-19-wonder-app-vq03-vq04-2e0ce81e.md b/docs/deployment/deployment-records/2026-11-19-wonder-app-vq03-vq04-2e0ce81e.md new file mode 100644 index 00000000..18baa80e --- /dev/null +++ b/docs/deployment/deployment-records/2026-11-19-wonder-app-vq03-vq04-2e0ce81e.md @@ -0,0 +1,37 @@ +# 2026-11-19: QA (wonder-app-vq03/vq04) `061432c8` → `2e0ce81e` (#144 + #145) + NAM AD login, one window + +**Owner go (2026-11-19):** "do the qa ldap plan, winrm usage approved" — scadaproj plan +`docs/plans/2026-11-15-nam-ldap-cutover.md` §0Q; full record `scadaproj/docs/deploy/2026-11-19-qa-nam-ldap/`. + +**Build:** the DEV artifact, zip SHA-256 `6c706b0a…6572e23` (record `2026-11-19-wonder-app-vd03-2e0ce81e.md`). No migration +(65 stays 65). Script: `docs/deployment/deploy-prep/2026-11-19-144-145/qa.tmpl.ps1` (the 11-15 QA template minus +`migrate`; its `swap` also installs each node's own NAM `appsettings.Central.json` and drops the GLAuth password env entry). + +## Before the window + +- `LdapGroupMappings` rows 6–10 added with the CLI as GLAuth `multi-role` (audited): `UG_WW_APP_ADMIN_QA`→Administrator, + `UG_WW_APP_IDE_QA`→Designer, `UG_WW_APP_IDE_RO_QA`→Viewer, `UG_WW_HIST_ADMIN_QA`→Deployer (interim), + `UG_WW_BTMGR_RO_QA`→Viewer. +- `nam-ldap-svc-password` seeded once into the shared SQL Server secret store (`zbsecrets`), with a Secrets CLI build that + honours `Secrets:Store:Provider=SqlServer` (the headless 0.6.6 CLI writes SQLite only). Both Centrals' KEK files match. +- DB backup `F:\MSSQL\BACKUP\ScadaBridge_pre-2e0ce81e_20261119T1600.bak` (VERIFYONLY ok). + +## Window (EST) + +Stop Site vq03 16:01:10, vq04 16:01:38; Central vq03 16:01:58, vq04 16:02:22. Swap both (central env 15 → 14). Central +vq03 ready 16:03:17, vq04 16:03:37; Site vq03 16:03:55, vq04 16:04:14. **Site data path ~2 min 17 s, central API ~55 s.** + +## Gates + +- `dohertj2`: cookie login ✓; `/auth/token` 200 with Administrator+Designer+Deployer; CLI (HTTP Basic) `instance list` (11) + and `security role-mapping list` ✓. Bogus user and GLAuth `multi-role` refused (UI and CLI). +- Active central vq03; site-a both nodes online; MxGateway Connected 2196/2196 Good; WarmCanary Connected 2/2 Good (also + after the OtOpcUa pair restart at 16:08–16:10); LocalDb replication connected. +- No LDAP / service-bind warning in the OTel log export. + +**Automation identity on QA is now `dohertj2`.** + +## Rollback + +`rollback-swap` (binaries ← `app.bak.20261119T1600`, Central env ← `_envbak-ScadaBridge-Central-20261119T1600.reg`), then +start Central vq03, vq04, then the Sites. No DB restore needed. The `UG_WW_*` rows can stay.