使用Azure DevOps启用Azure钥匙库防火墙 - 当KV在不同订阅中的最佳方法是什么?

发布于 2025-01-26 22:41:22 字数 352 浏览 4 评论 0 原文

使用Azure DevOps启用Azure钥匙库防火墙 - 当KV在不同订阅中的最佳方法是什么?

  • 要求是将SSL证书从KeyVault附加到应用程序服务。
  • 运行管道时,它总是显示Azure构建代理没有访问权限,并且错误为[statusCode = 403 - 原始错误:Autorest/Azure:服务返回错误。状态= 403 code =“禁止”消息=“客户端地址未经授权,呼叫者不是值得信赖的服务。InnerError= {“代码”:“ ForbiddenbyFireWall”})

是否有一种方法可以最好地实现此目标?我们不能允许所有MS Build Agent允许所有MS Build Agent IPS。

Enabling Azure Key Vault Firewall with Azure DevOps - what is the best way when the KV is in a different subscription ?

  • The requirement is to attach the ssl certificate from the keyvault to an app service.
  • When the pipeline was run, it always shows the Azure Build Agent doesn't have access and the error is [ StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403
    Code="Forbidden" Message="Client address is not authorized and caller is not a trusted service. InnerError={"code":"ForbiddenByFirewall"} )

Is there a way to best achieve this? We cannot allow all the MS build agent IPs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬﹪忆之殇 2025-02-02 22:41:22

由于需要创建服务主体为了授予管道访问键库,您可以简单地提供在Azure门户中,KeyVault页面的访问控制(IAM)窗格中更新防火墙设置的相同主要特权,并暂时将代理IP地址添加到Key Vault Vault的Firewall White列表中,例如:

  - task: AzureCLI@2
    displayName: Add devops host ip address
    inputs:
      azureSubscription: "MyAzureSubscription"
      scriptType: "bash"
      scriptLocation: "inlineScript"
      inlineScript: |
        agent_ip=$(curl -s http://ipinfo.io/json | jq -r '.ip')
        az keyvault network-rule add --name MyKeyVault --resource-group MyResourceGroup --ip-address $agent_ip

  - task: AzureKeyVault@2
    displayName: Load Secret from Key Vault
    inputs:
      azureSubscription: "MyAzureSubscription"
      KeyVaultName: "MyKeyVault"
      SecretsFilter: "*"
      # If this is true, then it will run before the ip address is whitelisted
      RunAsPreJob: false 

  - task: AzureCLI@2
    displayName: Remove devops host ip address (Clean up)
    # this ensures that the firewall is cleaned up, even if a prior task fails:
    condition: always()
    inputs:
      azureSubscription: "MyAzureSubscription"
      scriptType: "bash"
      scriptLocation: "inlineScript"
      inlineScript: |
        agent_ip=$(curl -s http://ipinfo.io/json | jq -r '.ip')
        az keyvault network-rule remove --name MyKeyVault --resource-group MyResourceGroup --ip-address $agent_ip

Since it is required to create a service principal in order to grant the pipeline access to the Key Vault, you can simply provided the same principal privileges to update your firewall settings in the Access Control (IAM) pane of KeyVault's page in the Azure portal, and temporarily add the agents IP address to the Key Vault's Firewall white list, like so:

  - task: AzureCLI@2
    displayName: Add devops host ip address
    inputs:
      azureSubscription: "MyAzureSubscription"
      scriptType: "bash"
      scriptLocation: "inlineScript"
      inlineScript: |
        agent_ip=$(curl -s http://ipinfo.io/json | jq -r '.ip')
        az keyvault network-rule add --name MyKeyVault --resource-group MyResourceGroup --ip-address $agent_ip

  - task: AzureKeyVault@2
    displayName: Load Secret from Key Vault
    inputs:
      azureSubscription: "MyAzureSubscription"
      KeyVaultName: "MyKeyVault"
      SecretsFilter: "*"
      # If this is true, then it will run before the ip address is whitelisted
      RunAsPreJob: false 

  - task: AzureCLI@2
    displayName: Remove devops host ip address (Clean up)
    # this ensures that the firewall is cleaned up, even if a prior task fails:
    condition: always()
    inputs:
      azureSubscription: "MyAzureSubscription"
      scriptType: "bash"
      scriptLocation: "inlineScript"
      inlineScript: |
        agent_ip=$(curl -s http://ipinfo.io/json | jq -r '.ip')
        az keyvault network-rule remove --name MyKeyVault --resource-group MyResourceGroup --ip-address $agent_ip
海拔太高太耀眼 2025-02-02 22:41:22

您不能用默认代理池对此进行存档。您必须在Azure租户中使用自托管代理作为VM或Scale-Set,然后可以配置防火墙,甚至可以在专用网络中使用KV。更多此处对于scale-set,上面是此链接,您可以找到如何安装代理在单个VM(Linux或Windows)上

You can't archive this with default agent pool. You must use self-hosted agent in your Azure tenant as VM or scale-set, then you can configure firewall and even use KV in private network. More here https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/scale-set-agents?view=azure-devops for scale-set, above this link you can find how to install agent on single VM (Linux or Windows)

苯莒 2025-02-02 22:41:22

我遇到了同样的问题,正如我所看到的,我们有很少的选择:

I've encountered the same problem and as I can see we have few alternatives:

  • self-hosted agent - you have your own Virtual Machine with agents that is connected to your Azure DevOps organization and then, since VM has public IP you can whitelist this IP in your Key Vault - quite a lot of effort to setup the VM but gives a lot of flexibility
  • whitelisting all the IP addresses of Microsoft-hosted agents - my least favourite one
  • whitelisting particular IP during the pipeline execution as described by Panu Oksala in How to Access Restricted Azure Key Vault from Azure DevOps - the one I like the most in a simple scenario, for large number of pipelines I would go with the first option
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文