为 Azure 中继命名空间配置 IP 防火墙

默认情况下,只要请求附带有效的身份验证和授权,就可以从 Internet 访问中继命名空间。 使用 IP 防火墙,可以将其进一步限制为采用 CIDR(无类域间路由)表示法的一组 IPv4 地址或一个 IPv4 地址。

在仅应从某些知名站点访问 Azure 中继的情况下,此功能很有用。 可以通过防火墙规则来配置规则,以便接受来自特定 IPv4 地址的流量。 例如,如果将中继与 Azure Express Route 配合使用,则可创建防火墙规则,仅允许来自本地基础结构 IP 地址的流量。

启用 IP 防火墙规则

在命名空间级别应用 IP 防火墙规则。 因此,这些规则适用于通过任何受支持协议从客户端发出的所有连接。 如果某 IP 地址与命名空间的允许 IP 规则不匹配,系统会拒绝来自该地址的任何连接尝试并将其标记为“未经授权”。 响应不会提及 IP 规则。 IP 筛选器规则将按顺序应用,与 IP 地址匹配的第一个规则决定了将执行接受操作还是执行拒绝操作。

使用 Azure 门户

本部分演示如何使用 Azure 门户为命名空间创建 IP 防火墙规则。

  1. Azure 门户中导航到“中继命名空间”。
  2. 在左侧菜单中选择“网络”。
  3. 若要将访问限制为特定网络和 IP 地址,请选择“所选网络”选项。 在“防火墙”部分执行以下步骤:
    1. 选择“添加客户端 IP 地址”选项,使当前客户端 IP 可以访问命名空间。

    2. 对于“地址范围”,请输入某个特定的 IPv4 地址或以 CIDR 表示法表示的 IPv4 地址范围。

    3. 如果要允许 Azure 中继服务信任的 Azure 服务绕过此防火墙,则请针对“允许受信任的 Microsoft 服务绕过此防火墙?”选择“是”。

      Screenshot showing the Public access tab of the Networking page with the Firewall enabled.

  4. 在工具栏上选择“保存”,保存这些设置。 请等待几分钟,直到门户通知中显示确认消息。

使用 Resource Manager 模板

以下资源管理器模板可用于向现有的中继命名空间添加 IP 筛选器规则。

模板采用一个参数:ipMask,它是单个 IPv4 地址或以 CIDR 表示法表示的一个 IP 地址块。 例如,在 CIDR 表示法中,70.37.104.0/24 表示从 70.37.104.0 到 70.37.104.255 的 256 个 IPv4 地址,其中 24 表示范围的有效前缀位数。

注意

虽然不可能具有拒绝规则,但 Azure 资源管理器模板的默认操作设置为“允许”,不限制连接。 制定虚拟网络或防火墙规则时,必须更改“defaultAction”

from

"defaultAction": "Allow"

to

"defaultAction": "Deny"
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "namespaces_name": {
            "defaultValue": "contosorelay0215",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Relay/namespaces",
            "apiVersion": "2021-11-01",
            "name": "[parameters('namespaces_name')]",
            "location": "China East",
            "sku": {
                "name": "Standard",
                "tier": "Standard"
            },
            "properties": {}
        },
        {
            "type": "Microsoft.Relay/namespaces/authorizationrules",
            "apiVersion": "2021-11-01",
            "name": "[concat(parameters('namespaces_sprelayns0215_name'), '/RootManageSharedAccessKey')]",
            "location": "chinaeast",
            "dependsOn": [
                "[resourceId('Microsoft.Relay/namespaces', parameters('namespaces_sprelayns0215_name'))]"
            ],
            "properties": {
                "rights": [
                    "Listen",
                    "Manage",
                    "Send"
                ]
            }
        },
        {
            "type": "Microsoft.Relay/namespaces/networkRuleSets",
            "apiVersion": "2021-11-01",
            "name": "[concat(parameters('namespaces_sprelayns0215_name'), '/default')]",
            "location": "China East",
            "dependsOn": [
                "[resourceId('Microsoft.Relay/namespaces', parameters('namespaces_sprelayns0215_name'))]"
            ],
            "properties": {
                "publicNetworkAccess": "Enabled",
                "defaultAction": "Deny",
                "ipRules": [
                    {
                        "ipMask": "172.72.157.204",
                        "action": "Allow"
                    },
                    {
                        "ipMask": "10.1.1.1",
                        "action": "Allow"
                    },
                    {
                        "ipMask": "11.0.0.0/24",
                        "action": "Allow"
                    }
                ]
            }
        }
    ]
}

若要部署模板,请按照 Azure 资源管理器的说明进行操作。

受信任的 Azure 服务

启用“允许受信任的 Azure 服务绕过此防火墙”设置时,将授权以下服务访问你的 Azure 中继资源

受信服务 支持的使用方案
Azure 机器学习 AML Kubernetes 使用 Azure 中继促进 AML 服务和 Kubernetes 群集之间的通信。 Azure 中继是一项完全托管的服务,为托管在不同网络上的应用程序之间提供安全的双向通信。 这使得它非常适合在专用链接环境中使用,其中 Azure 资源和本地资源之间的通信受到限制。
Azure Arc 与上述资源提供程序关联的已启用 Azure Arc 的服务将能够以发送方身份连接到 Azure 中继命名空间中的混合连接,而不会被 Azure 中继命名空间上设置的 IP 防火墙规则阻止。 Microsoft.Hybridconnectivity 服务在 Azure 中继命名空间中创建混合连接,并根据场景向相关 Arc 服务提供连接信息。 如果使用的是 Azure Arc,则这些服务只与你的 Azure 中继命名空间以及以下 Azure 服务通信:

- Azure Kubernetes
- Azure Purview

下面提供了 Azure 中继的其他受信任服务:

  • Azure 事件网格
  • Azure IoT 中心
  • Azure 流分析
  • Azure Monitor
  • Azure API 管理
  • Azure Synapse
  • Azure 数据资源管理器
  • Azure IoT Central
  • Azure Healthcare Data Services
  • Azure 数字孪生

后续步骤

若要了解其他与网络安全性相关的功能,请参阅网络安全性