Files
scadaproj/docs/deploy/2026-11-19-vd03-nam-ldap/seed-secret.ps1
T

35 lines
2.0 KiB
PowerShell

# 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