使用Connect-AzAccount保存ClientId和ClientSecret进行身份验证到Azure的安全方法

时间:2020-06-19 12:48:17

标签: azure powershell security authentication az

我正在寻找一种在本地计算机上运行脚本并在Azure中使用以下命令进行身份验证的安全方法:

static

问题是我不想在脚本中将秘密另存为纯文本。我发现的唯一解决方案是加密SecureString密码,并将其保存在可以使用密钥解密的文件中。这样,秘密就永远不会出现在纯文本中。

还有其他“干净”的方法吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

一次创建一个凭证对象,并使用Export-Clixml为当前用户/计算机存储它。

然后您可以使用Import-Clixml将它们读回到脚本中。

样本

# Set credentials
$Credentials = Get-Credential        # Set your id and secret
$Credentials | Export-Clixml -Path $PSScriptRoot\Access.xml -Confirm:$false


# Read the credentials
$Credentials = Import-Clixml -Path $PSScriptRoot\Access.xml
相关问题