azure - 检索 Azure Pipeline 中管道服务主体的客户端 ID

标签 azure azure-devops azure-yaml-pipelines

在我的 Azure Pipeline (YAML) 中,我正在部署 ARM 模板来创建 key 保管库(以及其他资源),然后运行 ​​PowerShell 脚本来生成证书并将其存储在 key 保管库中。这给了我一个 Forbidden 错误。在 Use secrets from Azure Key Vault in Azure Pipelines ,Microsoft 建议我需要为管道服务主体的 key 保管库创建访问策略。当我这样做时,脚本成功。

Service connections 图片来自cache404

我现在想以编程方式创建此访问策略作为 ARM 模板的一部分,但我不知道如何在管道内以编程方式检索管道服务主体的对象 ID。有人可以帮忙吗?

最佳答案

虽然 Hugh Lin 的答案是有效的,但我发现适应起来更简单 Nick Graham's answer作为 PowerShell 脚本本身的一部分,授予对管道服务主体的 key 保管库访问权限:

$Context = Get-AzContext
Set-AzKeyVaultAccessPolicy -VaultName $vaultName -ServicePrincipalName $Context.Account.Id -PermissionsToCertificates Get,List,Create

关于azure - 检索 Azure Pipeline 中管道服务主体的客户端 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64124474/

相关文章:

azure - Powershell : How to create/Manage Shared Access Policy for a Service Bus queue

azure - Powershell - 创建 Azure 部署包

Azure YAML-Pipeline 跳过作业,我不知道为什么

azure - 如果变量不等于azure pipeline yaml中的预期值,如何跳过模板?

azure - 如何在 Azure 上获取构建名称?

c# - Azure消息队列中的消息将直接进入Poison消息队列

azure - AuthorizeForScopesAttribute 的内联等效项

azure - 独立的暂存和生产管道

azure - 无法在 Azure DevOps 中构建角度项目

git - Azure 管道子模块克隆失败