From c80d5e79a5d2c74dca28698af50c734786bc0a55 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Thu, 19 Nov 2026 15:17:13 -0500 Subject: [PATCH] =?UTF-8?q?deploy(ldap):=20DEV=20vd03=20NAM=20AD=20cutover?= =?UTF-8?q?=20executed=20=E2=80=94=20HG,=20mxgw,=20ScadaBridge,=20OtOpcUa?= =?UTF-8?q?=20(record=20+=20scripts)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deploy/2026-11-19-vd03-nam-ldap/README.md | 83 +++++++++++++++++++ .../2026-11-19-vd03-nam-ldap/ldap-block.json | 15 ++++ .../2026-11-19-vd03-nam-ldap/login-test.sh | 13 +++ .../otopcua-cookie.ps1 | 11 +++ .../otopcua-cutover.ps1 | 21 +++++ .../2026-11-19-vd03-nam-ldap/preflight.ps1 | 44 ++++++++++ .../sb-central-cutover.ps1 | 15 ++++ .../sb-role-mappings.ps1 | 20 +++++ .../2026-11-19-vd03-nam-ldap/seed-secret.ps1 | 34 ++++++++ docs/plans/2026-11-15-nam-ldap-cutover.md | 4 + 10 files changed, 260 insertions(+) create mode 100644 docs/deploy/2026-11-19-vd03-nam-ldap/README.md create mode 100644 docs/deploy/2026-11-19-vd03-nam-ldap/ldap-block.json create mode 100755 docs/deploy/2026-11-19-vd03-nam-ldap/login-test.sh create mode 100644 docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cookie.ps1 create mode 100644 docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cutover.ps1 create mode 100644 docs/deploy/2026-11-19-vd03-nam-ldap/preflight.ps1 create mode 100644 docs/deploy/2026-11-19-vd03-nam-ldap/sb-central-cutover.ps1 create mode 100644 docs/deploy/2026-11-19-vd03-nam-ldap/sb-role-mappings.ps1 create mode 100644 docs/deploy/2026-11-19-vd03-nam-ldap/seed-secret.ps1 diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/README.md b/docs/deploy/2026-11-19-vd03-nam-ldap/README.md new file mode 100644 index 0000000..c08a490 --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/README.md @@ -0,0 +1,83 @@ +# 2026-11-19: DEV vd03 NAM AD LDAP cutover (HistorianGateway, MxAccessGateway, ScadaBridge, OtOpcUa) + +**Owner go (2026-11-19):** "ok, do it. winrm usage approved (for the vd03 deploy)". Plan: +[`docs/plans/2026-11-15-nam-ldap-cutover.md`](../../plans/2026-11-15-nam-ldap-cutover.md) §0 (today's groups and accounts). +Umbrella: scadaproj#6. **DEV only; QA untouched (hold stands).** + +**Result: all four apps on vd03 now sign users in against NAM AD** over LDAPS (nam1, nam2 as fallback), bound as +`svc_igntadmin@nam.zimmer.com` with the password from `${secret:nam-ldap-svc-password}` in each app's own store. +Zero service-account bind failures during the whole run. + +## Steps (EST) + +| Time | Step | +|---|---| +| 14:52–14:53 | **ScadaBridge `061432c8` → `2e0ce81e`** (#144 + #145, binary-only, no migration). Record: ScadaBridge `docs/deployment/deployment-records/2026-11-19-wonder-app-vd03-2e0ce81e.md`. Site ~47 s, central API ~30 s down | +| 14:56 | Phase 0 (`preflight.ps1`): nam1/nam2 reachable on 636 + 389 from vd03; **`zimmer-rootca` already in `LocalMachine\Root`** (thumbprint `78D941D7…`, exp 2036), LDAPS chain validates with no policy errors → `AllowInsecure=false` everywhere (D4 settled). Backups of every service key and appsettings → `E:\ApiInstall\_ldapcut-20261119T145640\`. OtOpcUa `LdapGroupRoleMapping` overlay: 0 rows | +| 14:58 | Secret seeded in all four stores (`seed-secret.ps1`) with the Secrets CLI built from current source (0.6.6, stdin input; the box's 0.6.2 CLI has no stdin mode). No schema or envelope change since 0.6.2. Read-back matched in all four; the transient value file was ACL'd to Administrators/SYSTEM and deleted. CLI left at `E:\ApiInstall\_tools\secret-0.6.6\` | +| 15:01 | **HistorianGateway**: `Server\appsettings.Production.json` → NAM block + `Dashboard:DisableLogin=false` + DEV `GroupToRole`; restart | +| 15:10 | **MxAccessGateway**: `Server\appsettings.json` (the service runs `ASPNETCORE_ENVIRONMENT=Staging`, no overlay; the root `MxGateway\appsettings.json` is a stale copy, unused) → NAM block (stale `RequiredGroup` dropped) + `DisableLogin=false` + DEV `GroupToRole` (replaces the `SCADA-*` rows); restart | +| 15:11 | **ScadaBridge Central**: `appsettings.Central.json` → NAM block; `Auth` block (`DisableLogin`/`AllowOutsideDevelopment`) removed; env entry `ScadaBridge__Security__Ldap__ServiceAccountPassword` (GLAuth) removed so it can't override the secret (12 → 11 entries); Central restarted, Site untouched | +| 15:12 | ScadaBridge role rows by SQL on the box (`sb-role-mappings.ps1`; nobody held a role yet): ids 6–9 | +| 15:14 | **OtOpcUa**: 18 `Security__Ldap__*` env entries + `Security__Auth__DisableLogin` true→false; restart (~9 s) | +| 15:15 | OtOpcUa: `Security__Cookie__RequireHttpsCookie=false` added; restart (~9 s). See finding 1 | + +## Mappings now on vd03 + +| Group | OtOpcUa | ScadaBridge | MxAccessGateway | HistorianGateway | +|---|---|---|---|---| +| `UG_WW_APP_ADMIN_DEV` | Administrator | Administrator | Administrator | Administrator | +| `UG_WW_APP_IDE_DEV` | Designer | Designer | Viewer | — | +| `UG_WW_APP_IDE_RO_DEV` | Viewer | Viewer | Viewer | Viewer | +| `UG_WW_HIST_ADMIN_DEV` | Viewer | **Deployer (DEV interim, plan §0.2)** | — | Administrator | + +ScadaBridge still holds the five `SCADA-*` seed rows (ids 1–5); they name GLAuth groups and grant nothing in NAM. + +## Verification + +| Check | HG `:5220` | mxgw `:5130` | ScadaBridge `:8085` | OtOpcUa `:9000` | +|---|---|---|---|---| +| Anonymous `GET /` → login | 302 | 302 | 302 | 302 | +| Bogus user refused, no `system-side` warning | ✓ | ✓ | ✓ | ✓ | +| `dohertj2` signs in | ✓ | ✓ | ✓ cookie; `/auth/token` 200 roles Administrator+Designer+Deployer; CLI (HTTP Basic) `instance list` + admin `role-mapping list` | ✓ cookie, `GET /` 200; `/auth/token` 200 roles Viewer+Designer+Administrator | +| Zero-role user refused | ✓ (`adm_dohertj2`, "no GroupToRole mapping matched") | not run (already refused by code) | ✓ `dohertj2` **before** the rows existed: `/auth/login`, `/auth/token` and the CLI all refused, log "bind succeeded but none of the user's 176 group(s) maps to a ScadaBridge role" | not run (needs a second outage; covered by #913's tests) | +| Health after | ready 200 | ready 200 | central + site ready 200; MxGateway Connected, 810/810 resolved, good 399 / bad 411 (baseline 398/412) | ready 200 | + +Overview `:5320` 200 throughout. + +**Not done, by owner instruction:** the DC-failover checks (§7.6 step 5, acceptance A2). Before that instruction one HG +check had run: with the primary pointed at closed port nam1:637 the login went through nam2 and the library logged +`sticky preference moved to uswap-vdc-nam2…:636`. The config was then restored (byte-compared). A temporary Windows Firewall rule +was also tried and removed; it had no effect because the firewall is **off** on every profile on vd03. + +**Viewer-only login was not tested live**: the only `APP_IDE_RO_DEV` members also hold `APP_ADMIN_DEV`. + +## Findings + +1. **OtOpcUa AdminUI login loops on plain HTTP.** `Security:Cookie:RequireHttpsCookie` defaults to `true`, so the + auth cookie is `Secure` and a browser never sends it back over `http://…:9000`. It never showed before because + login was off on vd03. Fixed for DEV with `Security__Cookie__RequireHttpsCookie=false`, as HG, mxgw and ScadaBridge + already run on vd03. QA needs the same decision (or HTTPS) before its OtOpcUa step. +2. **The box's Secrets CLI (0.6.2) can only take a value on argv.** Seeding needs the newer CLI (stdin), or the app's + `/admin/secrets` page. QA will need the same. +3. **mxgw `appsettings.json` exists twice** (`MxGateway\` and `MxGateway\Server\`); only `Server\` is read (NSSM + `AppDirectory`). The mxgw deploy notes must carry the `GroupToRole`/LDAP edit forward on every redeploy, since a + redeploy replaces `Server\appsettings.json`. +4. **HG's own log files are empty**; its logs go only to the box OTel collector (`E:\ApiInstall\OtelCollector\data\logs.jsonl`). + +## Rollback (per app) + +Everything is in `E:\ApiInstall\_ldapcut-20261119T145640\` (`reg-.reg`, `_appsettings*.json`): +- **HG / mxgw:** copy back the backed-up `Server\appsettings*.json`, restart the service. +- **ScadaBridge:** copy back `sb-appsettings.Central.json.pre-cutover` as `app\appsettings.Central.json`, + `reg import reg-ScadaBridge-Central.reg`, restart Central. The `UG_WW_*` rows can stay (they grant nothing with login off). +- **OtOpcUa:** `reg import reg-OtOpcUaHost.reg`, restart `OtOpcUaHost`. +- ScadaBridge binary rollback to `061432c8`: see the ScadaBridge record. + +The seeded secrets are inert once nothing references them. The box-local GLAuth (`ScadaBridge-LDAP`) is still running. + +## Files + +`preflight.ps1`, `seed-secret.ps1`, `sb-central-cutover.ps1`, `sb-role-mappings.ps1`, `otopcua-cutover.ps1`, +`otopcua-cookie.ps1`, `ldap-block.json` (the block written into HG, mxgw and ScadaBridge), and `login-test.sh` (Mac-side +login probe; passwords come from the Keychain into a 0600 temp file, never argv). diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/ldap-block.json b/docs/deploy/2026-11-19-vd03-nam-ldap/ldap-block.json new file mode 100644 index 0000000..c7e11f0 --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/ldap-block.json @@ -0,0 +1,15 @@ +{ + "Enabled": true, + "Server": "uswap-vdc-nam1.nam.zimmer.com", + "Port": 636, + "Transport": "Ldaps", + "AllowInsecure": false, + "FallbackServers": [ "uswap-vdc-nam2.nam.zimmer.com:636" ], + "SearchBase": "DC=nam,DC=zimmer,DC=com", + "ServiceAccountDn": "svc_igntadmin@nam.zimmer.com", + "ServiceAccountPassword": "${secret:nam-ldap-svc-password}", + "UserNameAttribute": "sAMAccountName", + "DisplayNameAttribute": "name", + "GroupAttribute": "memberOf", + "BindMode": "ServiceAccount" +} diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/login-test.sh b/docs/deploy/2026-11-19-vd03-nam-ldap/login-test.sh new file mode 100755 index 0000000..b9dc661 --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/login-test.sh @@ -0,0 +1,13 @@ +#!/bin/zsh +# usage: login-test.sh +# Prints the HTTP status + Location of the credential POST. Password is read from the Keychain into a 0600 temp file. +base=$1; getp=$2; postp=$3; user=$4; svc=$5 +t=$(mktemp -d); umask 077; jar=$t/jar +if [[ $svc == -bogus ]]; then printf 'not-a-password-%s' $RANDOM > $t/p; else security find-generic-password -s "$svc" -w | tr -d '\n' > $t/p; fi +html=$(curl -s -c $jar -b $jar "$base$getp") +tok=$(print -r -- "$html" | grep -o 'name="__RequestVerificationToken"[^>]*value="[^"]*"' | head -1 | sed 's/.*value="//;s/"$//') +[[ -z $tok ]] && tok=$(print -r -- "$html" | grep -o 'value="[^"]*"[^>]*name="__RequestVerificationToken"' | head -1 | sed 's/^value="//;s/".*//') +curl -s -o /dev/null -c $jar -b $jar -w "user=$user status=%{http_code} location=%{redirect_url}\n" \ + --data-urlencode "__RequestVerificationToken=$tok" --data-urlencode "username=$user" --data-urlencode "password@$t/p" --data-urlencode "returnUrl=/" "$base$postp" +print " cookies: $(awk '!/^#/ && NF>=7 {print $6}' $jar | tr '\n' ' ')" +rm -rf $t diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cookie.ps1 b/docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cookie.ps1 new file mode 100644 index 0000000..f5434e9 --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cookie.ps1 @@ -0,0 +1,11 @@ +# vd03 AdminUI is plain HTTP: the Secure-only auth cookie never comes back, so login loops. Match HG/mxgw/ScadaBridge on vd03. +$ErrorActionPreference = 'Stop' +$k = 'HKLM:\SYSTEM\CurrentControlSet\Services\OtOpcUaHost' +$before = @((Get-ItemProperty $k).Environment) +if (@($before | Where-Object { $_ -like 'Security__Cookie__RequireHttpsCookie=*' }).Count) { throw 'already set' } +Set-ItemProperty -Path $k -Name Environment -Value ([string[]]($before + 'Security__Cookie__RequireHttpsCookie=false')) -Type MultiString +"env entries $($before.Count) -> $(@((Get-ItemProperty $k).Environment).Count)" +"restarting $(Get-Date -Format HH:mm:ss)"; Restart-Service OtOpcUaHost -Force +$deadline = (Get-Date).AddSeconds(240); $ok = $false +while ((Get-Date) -lt $deadline) { try { if ((Invoke-WebRequest -UseBasicParsing 'http://127.0.0.1:9000/health/ready' -TimeoutSec 5).StatusCode -eq 200) { $ok = $true; break } } catch {}; Start-Sleep 2 } +"ready=$ok at $(Get-Date -Format HH:mm:ss)"; if (-not $ok) { exit 1 } diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cutover.ps1 b/docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cutover.ps1 new file mode 100644 index 0000000..3641d59 --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cutover.ps1 @@ -0,0 +1,21 @@ +# OtOpcUa AdminUI NAM cutover on vd03: add Security__Ldap__* + GroupToRole to the OtOpcUaHost env, DisableLogin true->false, restart. +# Every other env entry stays byte-identical. Rollback = reg import E:\ApiInstall\_ldapcut-20261119T145640\reg-OtOpcUaHost.reg + restart. +$ErrorActionPreference = 'Stop' +$k = 'HKLM:\SYSTEM\CurrentControlSet\Services\OtOpcUaHost' +$before = @((Get-ItemProperty $k).Environment) +$add = @( + 'Security__Ldap__Enabled=true','Security__Ldap__DevStubMode=false', + 'Security__Ldap__Server=uswap-vdc-nam1.nam.zimmer.com','Security__Ldap__Port=636','Security__Ldap__Transport=Ldaps','Security__Ldap__AllowInsecure=false', + 'Security__Ldap__FallbackServers__0=uswap-vdc-nam2.nam.zimmer.com:636','Security__Ldap__SearchBase=DC=nam,DC=zimmer,DC=com', + 'Security__Ldap__ServiceAccountDn=svc_igntadmin@nam.zimmer.com','Security__Ldap__ServiceAccountPassword=${secret:nam-ldap-svc-password}', + 'Security__Ldap__UserNameAttribute=sAMAccountName','Security__Ldap__DisplayNameAttribute=name','Security__Ldap__GroupAttribute=memberOf','Security__Ldap__BindMode=ServiceAccount', + 'Security__Ldap__GroupToRole__UG_WW_APP_ADMIN_DEV=Administrator','Security__Ldap__GroupToRole__UG_WW_APP_IDE_DEV=Designer', + 'Security__Ldap__GroupToRole__UG_WW_APP_IDE_RO_DEV=Viewer','Security__Ldap__GroupToRole__UG_WW_HIST_ADMIN_DEV=Viewer') +if (@($before | Where-Object { $_ -like 'Security__Ldap__*' }).Count -gt 0) { throw 'Security__Ldap__* already present; resolve by hand' } +$new = @($before | ForEach-Object { if ($_ -eq 'Security__Auth__DisableLogin=true') { 'Security__Auth__DisableLogin=false' } else { $_ } }) + $add +Set-ItemProperty -Path $k -Name Environment -Value ([string[]]$new) -Type MultiString +"env entries $($before.Count) -> $($new.Count)" +"restarting OtOpcUaHost $(Get-Date -Format HH:mm:ss)"; Restart-Service OtOpcUaHost -Force +$deadline = (Get-Date).AddSeconds(240); $ok = $false +while ((Get-Date) -lt $deadline) { try { if ((Invoke-WebRequest -UseBasicParsing 'http://127.0.0.1:9000/health/ready' -TimeoutSec 5).StatusCode -eq 200) { $ok = $true; break } } catch {}; Start-Sleep 2 } +"ready=$ok at $(Get-Date -Format HH:mm:ss) status=$((Get-Service OtOpcUaHost).Status)"; if (-not $ok) { exit 1 } diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/preflight.ps1 b/docs/deploy/2026-11-19-vd03-nam-ldap/preflight.ps1 new file mode 100644 index 0000000..766cf63 --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/preflight.ps1 @@ -0,0 +1,44 @@ +# NAM LDAP cutover, vd03 — Phase 0 preflight + backups (read-only except the backup folder). Values of secrets are never printed. +$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue' +$ts = Get-Date -Format 'yyyyMMddTHHmmss' +$bk = "E:\ApiInstall\_ldapcut-$ts"; New-Item -ItemType Directory -Force $bk | Out-Null +"backup dir $bk" +# 1. DC reach +foreach ($h in 'uswap-vdc-nam1.nam.zimmer.com','uswap-vdc-nam2.nam.zimmer.com') { foreach ($p in 636,389) { + $c = New-Object Net.Sockets.TcpClient; $ok = $c.ConnectAsync($h,$p).Wait(4000); $c.Dispose(); "reach $h`:$p $ok" } } +# 2. TLS trust +$root = @(Get-ChildItem Cert:\LocalMachine\Root | Where-Object { $_.Subject -like '*zimmer-rootca*' }) +"zimmer-rootca in LocalMachine\Root: $($root.Count) $(($root | % { $_.Thumbprint + ' exp ' + $_.NotAfter.ToString('yyyy-MM-dd') }) -join '; ')" +foreach ($h in 'uswap-vdc-nam1.nam.zimmer.com','uswap-vdc-nam2.nam.zimmer.com') { + try { $t = New-Object Net.Sockets.TcpClient($h,636); $script:err = $null + $s = New-Object Net.Security.SslStream($t.GetStream(), $false, { param($a,$b,$c,$e) $script:err = $e; $true }) + $s.AuthenticateAsClient($h); "tls $h policyErrors=$script:err proto=$($s.SslProtocol)"; $s.Dispose(); $t.Dispose() } catch { "tls $h FAILED $($_.Exception.Message)" } } +# 3. services + env (allow-listed values only) + reg export +$svcs = Get-CimInstance Win32_Service | Where-Object { $_.PathName -match 'ApiInstall\\(HistorianGateway|MxGateway|OtOpcUa|ScadaBridge)' } +$show = '(?i)ENVIRONMENT$|DisableLogin|AllowOutside|__Ldap__(Enabled|Server|Port|Transport|AllowInsecure|SearchBase|ServiceAccountDn|UserNameAttribute|BindMode|FallbackServers)|GroupToRole|^Secrets__(SqlitePath|MasterKey__Source|MasterKey__FilePath|MasterKey__EnvVarName|Replication__Enabled)|RequiredGroup|Thumbprint' +foreach ($s in $svcs) { + "== service $($s.Name) state=$($s.State) path=$($s.PathName)" + & reg.exe export "HKLM\SYSTEM\CurrentControlSet\Services\$($s.Name)" "$bk\reg-$($s.Name).reg" /y | Out-Null + $k = "HKLM:\SYSTEM\CurrentControlSet\Services\$($s.Name)" + $lines = @((Get-ItemProperty $k -ErrorAction SilentlyContinue).Environment) + @((Get-ItemProperty "$k\Parameters" -ErrorAction SilentlyContinue).AppEnvironmentExtra) | Where-Object { $_ } + foreach ($l in $lines) { $i = $l.IndexOf('='); if ($i -lt 1) { continue }; $n = $l.Substring(0,$i) + if ($n -match $show) { " env $l" } else { " env $n=" } } +} +# 4. config file copies +foreach ($p in 'HistorianGateway\Server\appsettings*.json','MxGateway\appsettings.json','MxGateway\Server\appsettings*.json','OtOpcUa\appsettings*.json','ScadaBridge\app\appsettings*.json') { + foreach ($f in Get-ChildItem "E:\ApiInstall\$p") { $d = "$bk\" + ($f.FullName.Substring(15) -replace '\\','_'); Copy-Item $f.FullName $d; "copied $($f.FullName) sha256 $((Get-FileHash $d).Hash.Substring(0,16))" } } +# 5. OtOpcUa DB overlay rows +$oto = Get-CimInstance Win32_Service | Where-Object { $_.PathName -match 'ApiInstall\\OtOpcUa\\' } | Select-Object -First 1 +$env1 = @((Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\$($oto.Name)").Environment) +$cs = ($env1 | Where-Object { $_ -match '^(ConnectionStrings__ConfigDb|.*ConfigDb.*|.*ConnectionString.*)=' } | Select-Object -First 1) +if ($cs) { $cs = $cs.Substring($cs.IndexOf('=')+1) + try { $c = New-Object System.Data.SqlClient.SqlConnection $cs; $c.Open(); $cmd = $c.CreateCommand() + $cmd.CommandText = "SELECT COUNT(*) FROM sys.tables WHERE name='LdapGroupRoleMapping'"; if ($cmd.ExecuteScalar() -gt 0) { + $cmd.CommandText = "SELECT * FROM dbo.LdapGroupRoleMapping"; $r = $cmd.ExecuteReader(); $n=0 + while ($r.Read()) { $n++; " otopcua overlay row: " + ((0..($r.FieldCount-1) | % { $r.GetName($_) + '=' + $r.GetValue($_) }) -join ' ') }; "otopcua overlay rows: $n" } else { "otopcua overlay table absent" } + $c.Close() } catch { "otopcua overlay query failed: $($_.Exception.Message)" } } else { "otopcua: no config connstr env found" } +# 6. secret CLI +Get-ChildItem 'E:\ApiInstall\_tools\secret' | Select-Object -First 8 | % { "tool $($_.Name) $($_.Length)" } +$exe = Get-ChildItem 'E:\ApiInstall\_tools\secret' -Recurse -Filter 'secret.exe' | Select-Object -First 1 +if ($exe) { "secret.exe $($exe.FullName) ver $($exe.VersionInfo.ProductVersion)" } +"PREFLIGHT DONE $bk" diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/sb-central-cutover.ps1 b/docs/deploy/2026-11-19-vd03-nam-ldap/sb-central-cutover.ps1 new file mode 100644 index 0000000..324d23d --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/sb-central-cutover.ps1 @@ -0,0 +1,15 @@ +# ScadaBridge Central NAM cutover on vd03: appsettings.Central.json was pushed over SMB as app\appsettings.Central.json.new. +# Swap it in, drop the GLAuth password env entry (others unchanged), restart Central only. Rollback = the _ldapcut backups. +$ErrorActionPreference = 'Stop' +$app = 'E:\ApiInstall\ScadaBridge\app'; $k = 'HKLM:\SYSTEM\CurrentControlSet\Services\ScadaBridge-Central' +$before = @((Get-ItemProperty $k).Environment) +$keep = @($before | Where-Object { $_ -notlike 'ScadaBridge__Security__Ldap__ServiceAccountPassword=*' }) +"env entries $($before.Count) -> $($keep.Count)" +Copy-Item "$app\appsettings.Central.json" "E:\ApiInstall\_ldapcut-20261119T145640\sb-appsettings.Central.json.pre-cutover" -Force +Move-Item "$app\appsettings.Central.json.new" "$app\appsettings.Central.json" -Force +Set-ItemProperty -Path $k -Name Environment -Value ([string[]]$keep) -Type MultiString +$after = @((Get-ItemProperty $k).Environment); foreach ($e in $keep) { if ($after -notcontains $e) { throw 'env entry changed' } } +"restarting Central"; Restart-Service 'ScadaBridge-Central' -Force +$deadline = (Get-Date).AddSeconds(180); $ok = $false +while ((Get-Date) -lt $deadline) { try { if ((Invoke-WebRequest -UseBasicParsing 'http://localhost:8085/health/ready' -TimeoutSec 5).StatusCode -eq 200) { $ok = $true; break } } catch {}; Start-Sleep 2 } +"central ready=$ok status=$((Get-Service ScadaBridge-Central).Status)"; if (-not $ok) { exit 1 } diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/sb-role-mappings.ps1 b/docs/deploy/2026-11-19-vd03-nam-ldap/sb-role-mappings.ps1 new file mode 100644 index 0000000..0d41148 --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/sb-role-mappings.ps1 @@ -0,0 +1,20 @@ +# Insert the DEV UG_WW_* -> role rows (plan §4.4 SQL + §0.2 DEV interim HIST_ADMIN_DEV->Deployer). Idempotent; refuses conflicts. +$ErrorActionPreference = 'Stop' +$e = @((Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\ScadaBridge-Central').Environment) +$cs = ($e | Where-Object { $_ -like 'ScadaBridge__Database__ConfigurationDb=*' }) -replace '^[^=]*=','' +$sb = New-Object System.Data.SqlClient.SqlConnectionStringBuilder $cs +$c = New-Object System.Data.SqlClient.SqlConnection $sb.ConnectionString; $c.Open(); $cmd = $c.CreateCommand() +$cmd.CommandText = @" +SET XACT_ABORT ON; +BEGIN TRAN; +DECLARE @t TABLE (LdapGroupName nvarchar(500) NOT NULL, Role nvarchar(100) NOT NULL); +INSERT @t VALUES (N'UG_WW_APP_ADMIN_DEV', N'Administrator'), (N'UG_WW_APP_IDE_DEV', N'Designer'), (N'UG_WW_APP_IDE_RO_DEV', N'Viewer'), (N'UG_WW_HIST_ADMIN_DEV', N'Deployer'); +IF EXISTS (SELECT 1 FROM dbo.LdapGroupMappings m JOIN @t t ON t.LdapGroupName = m.LdapGroupName WHERE m.Role <> t.Role) + THROW 50001, 'LdapGroupMappings maps one of these groups to a different role; resolve by hand.', 1; +INSERT dbo.LdapGroupMappings (LdapGroupName, Role) +SELECT t.LdapGroupName, t.Role FROM @t t +WHERE NOT EXISTS (SELECT 1 FROM dbo.LdapGroupMappings m WHERE m.LdapGroupName = t.LdapGroupName); +COMMIT; +SELECT Id, LdapGroupName, Role FROM dbo.LdapGroupMappings ORDER BY Id; +"@ +$r = $cmd.ExecuteReader(); while ($r.Read()) { "{0} {1} -> {2}" -f $r[0],$r[1],$r[2] }; $c.Close() diff --git a/docs/deploy/2026-11-19-vd03-nam-ldap/seed-secret.ps1 b/docs/deploy/2026-11-19-vd03-nam-ldap/seed-secret.ps1 new file mode 100644 index 0000000..ba34a8b --- /dev/null +++ b/docs/deploy/2026-11-19-vd03-nam-ldap/seed-secret.ps1 @@ -0,0 +1,34 @@ +# Seed nam-ldap-svc-password into the four app stores on vd03 with the secret CLI 0.6.6 (stdin), then verify read-back. +# The value arrives in $vf over SMB just before this runs and is deleted at the end. It is never printed. +$ErrorActionPreference = 'Stop' +$bk = 'E:\ApiInstall\_ldapcut-20261119T145640' +$vf = "$bk\_v.tmp" +$cli = 'E:\ApiInstall\_tools\secret-0.6.6\ZB.MOM.WW.Secrets.Cli.exe' +$name = 'nam-ldap-svc-password' +& icacls.exe $vf /inheritance:r /grant:r 'BUILTIN\Administrators:F' 'NT AUTHORITY\SYSTEM:F' | Out-Null +$stores = [ordered]@{ + HistorianGateway = @('E:\ApiInstall\HistorianGateway\data\histgw-secrets.db','E:\ApiInstall\HistorianGateway\data\kek.key') + MxGateway = @('E:\ApiInstall\MxGateway\data\mxgateway-secrets.db','E:\ApiInstall\MxGateway\data\kek.key') + ScadaBridge = @('E:\ApiInstall\ScadaBridge\central\data\scadabridge-secrets.db','E:\ApiInstall\ScadaBridge\kek.key') + OtOpcUa = @('E:\ApiInstall\OtOpcUa-data\otopcua-secrets.db','E:\ApiInstall\OtOpcUa-data\kek.key') +} +$fail = 0 +try { + $want = [IO.File]::ReadAllText($vf) + "value file read, length $($want.Length)" + foreach ($k in $stores.Keys) { + $env:Secrets__SqlitePath = $stores[$k][0]; $env:Secrets__MasterKey__Source = 'File'; $env:Secrets__MasterKey__FilePath = $stores[$k][1] + $out = & cmd.exe /c "`"$cli`" set $name - --description `"NAM LDAP lookup account (svc_igntadmin, DEV interim 2026-11-19)`" < `"$vf`"" 2>&1 + $rc = $LASTEXITCODE + $got = (& $cli get $name 2>$null | Out-String) + $got = $got.TrimEnd("`r","`n") + $match = ($got -ceq $want) + if (-not $match) { try { $j = $got | ConvertFrom-Json; $match = ($j.value -ceq $want) } catch {} } + "$k set rc=$rc out=$($out -join ' ') readback-match=$match" + if ($rc -ne 0 -or -not $match) { $fail++ } + } +} finally { + Remove-Item $vf -Force -ErrorAction SilentlyContinue; "value file removed: $(-not (Test-Path $vf))" + Remove-Item Env:Secrets__SqlitePath,Env:Secrets__MasterKey__Source,Env:Secrets__MasterKey__FilePath -ErrorAction SilentlyContinue +} +"SEED DONE failures=$fail"; exit $fail diff --git a/docs/plans/2026-11-15-nam-ldap-cutover.md b/docs/plans/2026-11-15-nam-ldap-cutover.md index 3b6f003..a160200 100644 --- a/docs/plans/2026-11-15-nam-ldap-cutover.md +++ b/docs/plans/2026-11-15-nam-ldap-cutover.md @@ -7,6 +7,10 @@ > (§10 lists what changed). The independent review of 2026-11-15 is applied (§11). **Written 2026-11-15. Status: PLAN ONLY. Nothing here has been executed.** +**EXECUTED ON DEV 2026-11-19** (§0): all four apps on vd03 log in against NAM AD. Record: +[`docs/deploy/2026-11-19-vd03-nam-ldap/`](../deploy/2026-11-19-vd03-nam-ldap/README.md). The DC-failover checks +(§7.6 step 5, A2) are dropped by owner instruction. New QA prerequisite from DEV: OtOpcUa's `RequireHttpsCookie` +on a plain-HTTP AdminUI (record, finding 1). QA not started. **Updated 2026-11-19:** §0 is the **DEV vd03 execution plan using the groups and accounts that exist today**, so it does not wait for scadaproj#58, the D3 automation account or the D6 deploy group. QA keeps the full prerequisites in §5–§7, and the QA deploy hold still stands.