在发布管道中使用私有 ip 从 Azure 密钥库下载机密

时间:2021-02-25 00:11:19

标签: azure azure-devops azure-keyvault azure-devops-deploymentgroups

我想使用管道和私有 IP 下载 Azure Key Vault,因为由于 NSG 限制性规则,机器只能通过私有 IP 进行通信。我的 azure 管道在部署组上运行,该部署组也与密钥保管库位于同一资源组中。默认的 Keyvault 任务使用公共 IP。有没有办法在管道中做到这一点?

1 个答案:

答案 0 :(得分:1)

<块引用>

有没有办法在管道中做到这一点?

根据您的描述,您的 azure 密钥保管库似乎位于虚拟网络后面。

您可以尝试将私有 IP 添加到 Azure Keyvault 防火墙白名单。

然后您可以使用 Azure Key Vault Task 下载 Key Vault。

最后,您可以删除 Ip 规则。

这是我的示例:

steps:
- task: AzurePowerShell@5
  displayName: 'Azure PowerShell script: InlineScript'
  inputs:
    azureSubscription: kevin0225
    ScriptType: InlineScript
    Inline: |
     $IP= Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
     
     $IP
     
     Add-AzKeyVaultNetworkRule -VaultName "keyvaultname" -IpAddressRange "$IP"
    preferredAzurePowerShellVersion: 3.1.0

- task: AzureKeyVault@1
  displayName: 'Azure Key Vault: kevin0225'
  inputs:
    azureSubscription: kevin0225
    KeyVaultName: kevin0225

- task: AzurePowerShell@5
  displayName: 'Azure PowerShell script: InlineScript'
  inputs:
    azureSubscription: kevin0225
    ScriptType: InlineScript
    Inline: |
     $IP= Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
     
     $IP
     
     Remove-AzKeyVaultNetworkRule -VaultName "keyvaultname" -IpAddressRange "$IP"
    preferredAzurePowerShellVersion: 3.1.0

这是关于 add IP to azure keyvault firewall 方法的文档。