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

Download secrets from Azure keyvaults using private ip in release pipeline

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

Is there any way to do this in the pipeline?

根据你的描述,你的 azure keyvault 似乎在虚拟网络后面。

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

然后您可以使用 Azure 密钥保管库任务下载密钥保管库。

最后,您可以删除 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.

方法的文档