Powershell 的日志中未显示值

时间:2021-03-09 09:56:35

标签: azure-devops azure-powershell

我正在 Azure Devops 的 Azure Powershell 任务中执行以下代码:

$secret="<<SecretValue>>"
$AppId="<<ClientId>>"
$tenantid="<<TenantId>>"

$cred = New-Object System.Management.Automation.PSCredential ($AppId, (ConvertTo-SecureString $secret –ASPlainText –Force))
Connect-AzureRMAccount -ServicePrincipal -Credential $cred -Tenant $tenantId

$KeyVaultSecret= (Get-AzureKeyVaultSecret -vaultName '<<KVName>>' -name '<<SecretName>>').SecretValueText
write-host " Value: $KeyVaultSecret"

作业执行后,该值不会显示在作业执行中,但通过本地系统 powershell 执行时相同的代码会显示该值。

Devops 输出:

enter image description here

本地系统输出:

enter image description here

Azure Devops 没有价值的任何原因?

2 个答案:

答案 0 :(得分:0)

默认情况下,Azure DevOps Pipelines 会根据 this documentation(“重要”注释部分)尝试删除输出源中的机密。

这可能是未在输出中显示的原因。

还有另一种通过变量组从 KeyVault 获取机密的方法。 Here is the documentation for how to set that up

答案 1 :(得分:0)

我认为这是一种正确的行为。 Azure DevOps 有自己的安全策略,旨在保护您的机密和敏感信息。

如果 Azure DevOps 允许可以在来自密钥保管库的控制台日志中打印机密的实际值,则任何有权查看管道日志的人都可以获得机密。显然,这会让你的秘密面临容易泄露的风险。

直接在本地系统执行脚本时,Azure DevOps的安全策略没有应用到本地系统,也可能没有其他Azure的安全策略应用到本地系统,所以可以打印输出日志的秘密值。

您可以尝试在系统上安装自托管代理,以在 Azure DevOps 的管道中运行脚本。如果秘密值仍然隐藏,正如我上面提到的,这就是 Azure DevOps 的安全策略。