本文提供了示例自定义 Azure 策略用于控制可在事件网格的事件订阅中配置的目标。 Azure Policy 可帮助你强制实施组织标准和法规遵从性来解除各种忧虑,例如安全性、成本、资源一致性、管理,等等。若要解除这些忧虑,最重要的是实施安全合规标准来帮助维持组织的安全态势。 本文中所述的策略可帮助你实施安全控制,以防止数据渗透或事件被传送给未经授权的终结点或 Azure 服务。
备注
Azure 事件网格提供合规方面的内置策略,以及与多个合规标准相关的安全控制。 可以在事件网格的 Microsoft Cloud 安全基准中找到这些内置策略。
为了防止数据渗透,组织可能希望限制事件网格可将事件传送到的目标。 为此,可以分配策略来允许创建或更新包含策略中批准的目标之一的事件订阅。 用于防止资源请求成功的策略效果为“拒绝”。
以下各部分介绍了强制实施允许的目标列表的示例策略定义。 在定义策略时,可以搜索包含 destination
的属性别名,并将其用作要与允许的目标列表进行比较的 field
。
可以按照此文中所述,运行 CLI 或 PowerShell 命令找到为事件网格定义的属性别名(使用命名空间 Microsoft.EventGrid
)。
有关定义策略的详细信息,请参阅 Azure Policy 定义结构一文。
以下策略定义限制系统主题的事件订阅中配置的 Webhook 终结点目标。
{
"mode": "All",
"policyRule": {
"if": {
"not": {
"field": "Microsoft.EventGrid/systemTopics/eventSubscriptions/destination.WebHook.endpointUrl",
"in": "[parameters('allowedDestinationEndpointURLs')]"
}
},
"then": {
"effect": "deny"
}
},
"parameters": {
"allowedDestinationEndpointURLs": {
"type": "Array",
"metadata": {
"description": "Allowed event destination endpoint URLs.",
"displayName": "The list of allowed webhook endpoint destinations to which send events"
},
"allowedValues": [
"https://www.your-valid-destination-goes-here-1.com",
"https://www.your-valid-destination-goes-here-2.com",
"https://www.your-valid-destination-goes-here-3.com"
]
}
}
}
以下策略定义限制自定义主题的事件订阅中配置的特定事件中心目标。 对于其他类型的受支持 Azure 服务目标,可以采用类似的方法。
{
"mode": "All",
"policyRule": {
"if": {
"not": {
"field": "Microsoft.EventGrid/eventSubscriptions/destination.EventHub.resourceId",
"in": "[parameters('allowedResourceDestinations')]"
}
},
"then": {
"effect": "deny"
}
},
"parameters": {
"allowedResourceDestinations": {
"type": "Array",
"metadata": {
"description": "The list of allowed event delivery destinations.",
"displayName": "Allowed event delivery destinations"
},
"allowedValues": [
"/subscriptions/<your-event-subscription>/resourceGroups/<your-resource-group>/providers/Microsoft.EventHub/namespaces/<event-hubs-namespace-name>/eventhubs/<your-event-hub-name>"
]
}
}
}
- 若要详细了解 Azure Policy,请参阅以下文章:
- 若要详细了解 Azure 事件网格,请参阅“概念”部分下的文章,例如事件网格术语。