将证书导入 Azure Key Vault:密钥在指定状态下使用无效

Importing certificate to Azure Key Vault: Key not valid for use in specified state

我正在尝试通过 Azure Pipelines 任务 Azure PowerShell 将证书导入到 Azure Key Vault

我在那里输入了这个内联脚本:

$Password = ConvertTo-SecureString -String "$(cert.password)" -AsPlainText -Force
Import-AzureKeyVaultCertificate -VaultName %KVNAME% -Name %NAME% -FilePath $(cert.secureFilePath) -Password $Password

我收到这样的错误:"Key not valid for use in specified state"

您对错误原因有什么建议吗?

Key not valid for use in specified state

根据错误信息,您的 Azure 连接字符串似乎没有执行该操作的权限。

请尝试使用以下方式给Azure连接字符串权限

首先,如果我们要访问Azure资源,我们需要配置IAM。

其次,如果我们要将证书导入Key Vault,还需要添加访问策略。之后,PowerShell 命令 Import-AzureKeyVaultCertificate 应该可以在 Azure Devops 管道中运行。

注意应用程序Id应与服务原理Id[相同=32=] 用于 azure 连接字符串。