Files
scadaproj/docs/deploy/2026-11-19-vd03-nam-ldap/otopcua-cutover.ps1
T

22 lines
2.2 KiB
PowerShell

# 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 }