这个挑战涉及Azure和Azure DevOps,但我可以想象这种情况发生在类似的平台上(AWS、GCP、Github、Gitlab等)。
我目前正在使用Azure DevOps管道,但是我面临着与防火墙后面的资源交互的问题(无论是IP限制的还是虚拟网络限制的)。当Azure管道推出一个新的VM时,它要求我在每次运行时为新开发的机器提供公共IP的白名单。当我创建Azure管道作为可再现的子模块,从一个项目中扩展模板并在多个项目中使用时,这个白名单是非常简陋的。Terraform状态需要访问受限资源上的配置,从而引发拒绝访问的消息。
我研究了以下几点,以解决这些挑战和我对这些挑战的想法:
你对解决这个挑战有什么想法?
发布于 2020-12-28 19:14:44
您可以使用脚本获取云代理的ip。并使用azure PowerShel或Azure动态地为您的Azure存储帐户列出ip地址。见下面的例子:
1 .在Azure管道中,在Terraform任务之前添加azure Powershell任务,以获取代理的ip地址,并为azure存储帐户添加白名单。
- task: AzurePowerShell@5
displayName: 'Azure PowerShell script: InlineScript copy'
inputs:
azureSubscription: 'Microsoft-Azure'
ScriptType: InlineScript
Inline: |
$ip = Invoke-RestMethod http://ipinfo.io/json | Select -exp ip #get agent ip
#add ip to whitelist
Add-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -IPAddressOrRange $ip
azurePowerShellVersion: LatestVersion
2 .在管道的末尾添加另一个蔚蓝的powershell任务,以删除白名单。
- task: AzurePowerShell@5
displayName: 'Azure PowerShell script: InlineScript copy'
inputs:
azureSubscription: 'Microsoft-Azure'
ScriptType: InlineScript
Inline: |
$ip = Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
Remove-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -IPAddressOrRange $ip
azurePowerShellVersion: LatestVersion
有关更多信息,请查看文档这里。
云代理的IP范围每周更改一次。您还可以检查每周文件并手动更新白名单ip地址。有关更多信息,请查看这里。
https://stackoverflow.com/questions/65474656
复制