You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Azure NSG规则通过Service Tags允许Azure DevOps管道访问资源

问题分析与配置指导

当前NSG规则的核心问题

你配置的AzureDevOps服务标签无法覆盖Azure DevOps Pipelines代理的来源IP,这是导致流量被阻止的根本原因:

  • AzureDevOps服务标签仅包含Azure DevOps平台自身的IP范围,而Pipelines的微软托管代理出站IP属于对应区域的AzureCloud服务标签(而非AzureDevOps标签);自托管代理则使用自身的公网/VNet内IP。
  • 入站规则的目标端口设置为*过于宽泛,且未明确匹配SonarQube实际使用的端口(错误中显示是端口80)。

修正后的NSG规则示例(ARM模板片段)

针对微软托管代理的场景,替换为区域级AzureCloud服务标签,并限定目标端口:

{
  "name": "inbound-devops-pipelines-sonarqube",
  "properties": {
    "description": "Allow Azure DevOps Microsoft-hosted agents to access SonarQube",
    "protocol": "TCP",
    "sourcePortRange": "*",
    "destinationPortRange": "80", // 替换为你的SonarQube实际端口(如9000)
    "sourceAddressPrefix": "AzureCloud.eastus", // 替换为DevOps组织所在的Azure区域
    "destinationAddressPrefix": "*", // 建议限定为SonarQube实例所在子网/私有IP以提升安全性
    "access": "Allow",
    "priority": 100,
    "direction": "Inbound"
  }
},
{
  "name": "InboundRequiredGatewayPorts",
  "properties": {
    "description": "Inbound AZ admin",
    "protocol": "TCP",
    "sourcePortRange": "*",
    "destinationPortRange": "65200-65535",
    "sourceAddressPrefix": "GatewayManager",
    "destinationAddressPrefix": "*",
    "access": "Allow",
    "priority": 115,
    "direction": "Inbound"
  }
}

详细配置指导

1. 确定代理来源IP范围

  • 微软托管代理:使用DevOps组织所在区域的AzureCloud服务标签(例如AzureCloud.westus),或者获取该区域微软托管代理的具体IP列表进行精准配置。
  • 自托管代理:
    • 若代理部署在目标VNet内,直接允许代理所在子网的IP范围;
    • 若代理在公网环境,添加代理的公网静态IP。

2. 优化NSG规则细节

  • 限定目标端口:仅开放SonarQube实际使用的端口(如80、9000),避免全端口开放。
  • 缩小目标地址范围:将destinationAddressPrefix设置为SonarQube实例的私有IP或所在子网,而非*,进一步提升安全性。
  • 优先级检查:确保允许规则的优先级(如100)高于默认的DenyAllInbound规则(优先级65500),且不与其他高优先级拒绝规则冲突。

3. 连通性验证

使用Azure Network Watcher的IP流验证工具,测试从代理来源IP到SonarQube实例IP+端口的连通性,确认NSG规则是否正常放行流量。

4. 额外检查点

  • 确认SonarQube的ACI实例已正确加入目标VNet,且网络配置允许外部(代理)访问;
  • 检查VNet路由表是否存在阻止流量的自定义路由规则;
  • 若使用私有端点,需确保私有DNS区域配置正确,且DevOps代理能够解析SonarQube的私有域名。

内容的提问来源于stack exchange,提问作者DCaugs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 22:15:27