Files
mtusi2026lab7/scripts/rotate-openbao-secret-ids.ps1
T

17 lines
972 B
PowerShell

[CmdletBinding()]
param([string]$EnvFile = '.env')
$ErrorActionPreference = 'Stop'
$projectRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
Set-Location $projectRoot
if ([string]::IsNullOrWhiteSpace($env:BAO_TOKEN)) { throw 'Set BAO_TOKEN for this operator action.' }
foreach($role in 'api','worker') {
$roleName = "messenger-$role"
$directory = Join-Path $projectRoot "secrets\openbao\$role"
New-Item -ItemType Directory -Path $directory -Force | Out-Null
$secretId = (& docker compose --env-file $EnvFile exec -T -e "BAO_TOKEN=$env:BAO_TOKEN" openbao bao write -field=secret_id -f "auth/approle/role/$roleName/secret-id" | Out-String).Trim()
if($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($secretId)){ throw "Failed to rotate $roleName SecretID" }
[System.IO.File]::WriteAllText((Join-Path $directory 'secret-id'),$secretId,[System.Text.Encoding]::ASCII)
}
Write-Host 'AppRole SecretIDs rotated without printing their values.'