amazon-web-services - 创建 Azure 策略以防止直接通过订阅访问 Internet
问题描述
我想创建一个 Azure 订阅,其中无法创建可以直接访问 Internet 的资源,而是需要路由回本地设备。
我创建了以下策略并将其应用于订阅
{
"if": {
"anyOf": [
{
"source": "action",
"like": "Microsoft.Network/publicIPAddresses/*"
}
]
},
"then": {
"effect": "deny"
}
但是,看起来仍然可以访问互联网。我们是否需要为所有子网创建自定义 UDR 以将所有 0.0.0.0/0 流量路由回本地?
顺便说一句,在 AWS 中创建类似的 SCP 相当简单: https ://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_example-scps.html#example_scp_5
解决方案
我有同样的问题,我解决了如下:
{
"policyType": "Custom",
"mode": "All",
"displayName": "check_default_route_gateway_plus_default",
"policyRule": {
"if": {
"count": {
"field": "Microsoft.Network/routeTables/routes[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Network/routeTables/routes[*].nextHopIpAddress",
"equals": "[parameters('DefaultGW')]"
},
{
"field": "Microsoft.Network/routeTables/routes[*].name",
"equals": "DEFAULT"
},
{
"field": "Microsoft.Network/routeTables/routes[*].addressPrefix",
"equals": "0.0.0.0/0"
}
]
}
},
"notEquals": 1
},
"then": {
"effect": "deny"
}
},
"parameters": {
"DefaultGW": {
"type": "String",
"metadata": {
"displayName": "Default Gateway IP",
"description": "The default Gateway IP. It correspond to the Proxy IP"
},
"defaultValue": "PUT_HERE_THE_IP_OF_YOUR_APPLIANCE"
}
}
}
此策略将失败,因为没有使用指向您的设备DEFAULT
的 addressPrefix调用默认路由。0.0.0.0/0
我花了一些时间才到达它,因为逻辑与我的预期行为相反。该策略在其表达式被评估为true时触发,而我认为它会触发然后评估为false。
实现它的一大帮助来自 VSCode 插件Azure Policy,您可以在其中交互式测试您的策略,而无需等待云延迟。
此外https://docs.microsoft.com/en-us/azure/governance/policy/concepts/definition-structure对于查看所有策略结构很有用。
推荐阅读
- unity3d - Unity3D SetDestination 更新
- laravel - 安装 Behat 时出现“-bash: behat: command not found”
- android - 多次成功调用后,带有 MySQL 服务器和 Xamarin 客户端的 SignalR 停止工作
- python - 不使用内置函数的列表和最大数量
- excel - 使用 VBA 将 Excel 文档转换为 PDF
- angular - Angular 6,我应该将秘密环境变量放在 environment.ts 文件中吗?
- python - Celery/Flask 接收未注册类型的任务(App Factory + Blueprints)
- javascript - 文本框屏蔽 - 如何在文本框中放置逗号和 .00
- node.js - 运行“npm start”时出错
- laravel - 由于写入权限,Laravel 显然没有执行