【问题标题】:Azure Custom RBAC with wildcard in assinableScopes - is it possible?assinableScopes 中带有通配符的 Azure 自定义 RBAC - 这可能吗?
【发布时间】:2023-01-18 14:56:35
【问题描述】:

我正在尝试创建 Azure 自定义 RBAC,它在 action/noaction 中接受通配符,但是当我在 assinableScopes 中尝试通配符时它不起作用。

我需要限制某些资源组的权限,但我不知道资源组的确切名称。但是,我确实知道命名约定,并且我希望能够在 assinableScopes 中使用通配符。

我想做但 Azure 不允许的示例:

{
    "properties": {
        "roleName": "MySampleCustomRole",
        "description": "My Sample Custom Role",
        "assignableScopes": [
            "/subscriptions/*/resourceGroups/ABCDXYZ-*"
        ],
        "permissions": [{
                "actions": [],
                "notActions": [
                    "Microsoft.Compute/snapshots/delete",
                    "Microsoft.Compute/snapshots/write",
                    "Microsoft.Compute/snapshots/beginGetAccess/action",
                    "Microsoft.Compute/snapshots/endGetAccess/action",
                    "Microsoft.Compute/disks/beginGetAccess/action"
                ],
                "dataActions": [],
                "notDataActions": []
            }
        ]
    }
}

【问题讨论】:

  • 除操作外,不能在角色中使用通配符。但是,您可以使用资源名称中的通配符通过 Azure Policy 分配角色。 Marco Laitinen 写了 a nice blog 关于通过策略分配 Azure 角色
  • @RoderickBant - 感谢您对政策驱动替代方案的建议和参考。策略可以成为救世主,但它必须依赖于资源组命名约定或标签。除非保持标签的完整性,否则使用标签进行 RBAC 分配是不明智的。太冒险了!为了进行比较,我们在 IAM 策略中使用通配符,您可以在资源定义中使用通配符。 Azure 应该与 AWS 相提并论,但 Azure 似乎落后于自定义 RBAC 功能!

标签: azure azure-rbac


【解决方案1】:

我同意 @罗德里克班特, 无法使用通配符在可分配的范围内。

我试图在我的环境中重现相同的结果并得到以下结果:

我的订阅中很少有资源组的命名约定以 test 开头。

当我尝试通过包含创建自定义 RBAC 角色时通配符在可分配范围内test*,我得到如下错误:

PUT https://management.azure.com/subscriptions/<subID>/resourceGroups/test*/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionId}?api-version=2022-04-01

{
    "properties": {
        "roleName": "MySampleCustomRole",
        "description": "My Sample Custom Role",
        "assignableScopes": [
            "/subscriptions/<subID>/resourceGroups/test*"
        ],
        "permissions": [{
                "actions": [],
                "notActions": [
                    "Microsoft.Compute/snapshots/delete",
                    "Microsoft.Compute/snapshots/write",
                    "Microsoft.Compute/snapshots/beginGetAccess/action",
                    "Microsoft.Compute/snapshots/endGetAccess/action",
                    "Microsoft.Compute/disks/beginGetAccess/action"
                ],
                "dataActions": [],
                "notDataActions": []
            }
        ]
    }
}
}

回复:

在下面使用CLI 命令使用命名约定 test 获取资源组的确切名称:

az group list --query "[?contains(name,'test')].name"

回复:

而不是包括通配符assignableScopes 中,目前唯一的方法是在创建自定义 RBAC 角色时将上述名称一一传递,如下所示:

PUT https://management.azure.com/subscriptions/<subID>/resourceGroups/testrg/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionId}?api-version=2022-04-01

{
    "properties": {
        "roleName": "MySampleCustomRole",
        "description": "My Sample Custom Role",
        "assignableScopes": [
            "/subscriptions/<subID>/resourceGroups/testrg",
            "/subscriptions/<subID>/resourceGroups/testsri",
            "/subscriptions/<subID>/resourceGroups/testdevi"
        ],
        "permissions": [{
                "actions": [],
                "notActions": [
                    "Microsoft.Compute/snapshots/delete",
                    "Microsoft.Compute/snapshots/write",
                    "Microsoft.Compute/snapshots/beginGetAccess/action",
                    "Microsoft.Compute/snapshots/endGetAccess/action",
                    "Microsoft.Compute/disks/beginGetAccess/action"
                ],
                "dataActions": [],
                "notDataActions": []
            }
        ]
    }
}
}

回复:

当我在 Portal 中检查相同时,上面的自定义角色在只要 test*assignableScopes 中提到的资源组如下所示:

测试:

测试:

测试设备:

当我签入时其他来自同一订阅的资源组,自定义角色是无法使用如下所示:

参考:

Azure custom role definition with special AssignableScopes - Stack Overflow by Joy Wang

【讨论】:

    猜你喜欢
    • 2021-03-15
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    • 2011-10-25
    相关资源
    最近更新 更多