Powershell 为什么TFS秘密不是SecureString?

Powershell 为什么TFS秘密不是SecureString?,powershell,security,tfs,Powershell,Security,Tfs,据了解,您必须将TFS 2018中的一个秘密传递给powershell,如下所示: Param( [string]$sauceArgument, [string]$secretSauceArgument ) Write-Host No problem reading $env:SAUCE or $sauceArgument Write-Host But I cannot read $env:SECRET_SAUCE Write-Host But I can read $secretS

据了解,您必须将TFS 2018中的一个秘密传递给powershell,如下所示:

Param(
   [string]$sauceArgument,
   [string]$secretSauceArgument
)
Write-Host No problem reading $env:SAUCE or $sauceArgument
Write-Host But I cannot read $env:SECRET_SAUCE
Write-Host But I can read $secretSauceArgument "(but the log is redacted so I do not
           spoil the secret)"
将其作为字符串传递不允许在凭据中使用机密。我只能在通过ConvertTo SecureString-AsPlainText转换它时使用它,根据以下说明,这应该是一种不好的做法:

如果将输入类型从[String]更改为[SecureString],则会出现以下转换错误:

Cannot process argument transformation on parameter 'secretSauceArgument'. Cannot convert the "***" value of type "System.String" to type "System.Security.SecureString".
它真的需要转换吗?这是否意味着使用秘密是不好的做法


更新以澄清我的问题:我能够将秘密传递到powershell。我无法使用机密作为凭据(仅通过ConvertTo SecureString-AsPlainText-Force,这是一种糟糕的做法)。

Azure DevOps管道中的机密变量在静止时使用2048位RSA密钥加密。代理上提供了用于任务和脚本的机密

您使用了系统保留的变量前缀
secret
,因此无法读取。尝试修改变量名,不要使用系统保留的变量前缀

检查:

用户定义的变量可以由字母、数字、
\uu
人物。不要使用由 系统。它们是:
endpoint
input
secret
securefile
。 以这些字符串之一开头的任何变量(无论 大写)将不适用于您的任务和脚本


更新:


现在我更了解你的问题了。根据我的测试,即使您在脚本中定义了
$password='123'
,您仍然需要
-AsPlainText-Force
。脚本中定义的所有变量都被视为字符串,管道中没有
SecureString
。您可以尝试从文件中的加密字符串创建一个安全字符串:。

我的个人收获是:TFS机密对于powershell中的凭据不是最佳的—这是一个惊喜,因为我希望机密主要用于凭据


Cece Dong-MSFT使用文件的答案是一个可靠的选择。

如果我将名称更改为mySauce,我会得到相同的错误:无法处理参数“mySauce”的参数转换。无法将“System.String”类型的“***”值转换为“System.Security.SecureString”类型。我使用了文档示例的名称,因此根据您链接的站点,这是错误的:在您的原始帖子中,您提到了文档,因此,我假设您在管道的web界面中设置了机密。如果您从脚本中设置了变量,则可以使用前缀
secret
。管道中的脚本可以定义变量,以便管道中的后续步骤之一可以使用该变量。此方法设置的所有变量都被视为字符串。不确定我们讨论的是否是同一个问题:我能够将web界面和脚本中的秘密传递给其他任务。很好。我无法在powershell中将机密用作SecureString。我认为一个秘密应该用于凭证,因此应该是SecureString或安全地转换为SecureString。(我只能使用AsPlainText转换,这是一种糟糕的做法)…如果我的回答对您有所帮助,您可以,这对其他社区成员阅读此帖子是有益的。我知道这一点。非常感谢。
Cannot process argument transformation on parameter 'secretSauceArgument'. Cannot convert the "***" value of type "System.String" to type "System.Security.SecureString".