<# .SYNOPSIS 为同一 Windows 用户下的 RPA Worker 创建当前用户可解密的 Secret 文件。 .DESCRIPTION Secret 文件使用 PowerShell SecureString/Windows DPAPI 保存,不能被其他用户直接解密。 启动脚本只在 Worker 子进程中设置 Process 级环境变量,不写入 User/Machine 环境变量。 Secret 文件应保存在仓库之外,例如 C:\HxopsRpaSecrets\test.xml。 DSV/Crane 登录地址、账号和密码不在本文件中保存;它们由 HXOPS RPA Profile 配置并随加密 credential_envelope 进入 trigger,Worker 使用 CredentialKey 解密。 #> param( [Parameter(Mandatory = $true)] [ValidateSet("test", "prod")] [string]$Environment, [string]$OutputRoot = "C:\HxopsRpaSecrets" ) $ErrorActionPreference = "Stop" $secretPath = Join-Path $OutputRoot ("{0}.xml" -f $Environment) New-Item -ItemType Directory -Force -Path $OutputRoot | Out-Null function Read-RequiredSecret { param([Parameter(Mandatory = $true)][string]$Prompt) $value = Read-Host $Prompt -AsSecureString if (-not $value -or $value.Length -eq 0) { throw "$Prompt 不能为空" } return $value } $record = [pscustomobject]@{ ToolApiKey = Read-RequiredSecret "请输入 $Environment 环境 SHIPPING_NOTICE_TOOL_API_KEY" CredentialKey = Read-RequiredSecret "请输入 $Environment 环境 SHIPPING_NOTICE_RPA_CREDENTIAL_KEY" } $record | Export-Clixml -LiteralPath $secretPath $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name icacls $secretPath /inheritance:r /grant:r "${currentUser}:F" | Out-Null Write-Host "Secret 文件已创建:$secretPath" Write-Host "仅当前 Windows 用户可解密;不要复制到其他账号、提交 Git 或写入日志。"