跳转到内容
搜索文档

用户组

最后更新 查看 MarkdownAgent 设置

用户组是一组账户成员的集合,从访问控制角度来看被同等对待。用户组可以分配权限策略,组内各成员将继承分配给该用户组的所有角色权限。如果用户还有单独分配的权限,其有效权限是所有单独权限加上其所属所有用户组权限的并集。

手动创建用户组

  1. 在 Cloudflare 仪表板中,转到 Members(成员) 页面。

    Go to Members ↗
  2. 选择 Groups(组) 选项卡。

  3. 选择 Create a Group(创建组) 并输入新组的名称和描述。

  4. 选择 Create group(创建组) 确认更改。Group members(组成员) 选项卡将显示。

  5. 选择 Add members(添加成员)

  6. 选择要包含在组中的相关成员,然后选择 Add to Group(添加到组)

分配权限策略

创建组后,您可以向组添加权限策略

  1. Groups(组) 选项卡下的 Permission policies(权限策略) 中,选择 Add a Policy(添加策略)
  2. 指定要应用于组成员的范围和权限。
  3. 选择 Create Policy(创建策略) 将其应用于组。

使用上一节中的角色标识符,您可以为组创建权限策略。

export ADMIN_ROLE='...' # id field from admin or desired role entry from permission_groups API response

Example requestcurl
$ cat <<-PAYLOAD | curl -XPUT  -H "Authorization: Bearer $AOT" -H "Content-type: application/json" --data-binary @- https://api.cloudflare.com/client/v4/accounts/$ACCT/iam/user_groups/$PUSHED_GROUP  | jq .
{
    "policies": [
        {
            "access": "allow",
            "permission_groups": [{"id": "$ADMIN_ROLE"}],
            "resource_groups": [{
                "scope": {
                    "key": "com.cloudflare.api.account.$ACCT",
                    "objects": [{"key":"*"}]
                }
            }]
        }
    ]
}
PAYLOAD

将策略重置为空状态

如果在创建组策略时出错或需要将策略重置为空状态,请向组 API 发送另一个 PUT 请求,使用空策略数组覆盖为新策略。

$ cat <<-PAYLOAD | curl -XPUT  -H "Authorization: Bearer $AOT" -H "Content-type: application/json" --data-binary @- https://api.cloudflare.com/client/v4/accounts/$ACCT/iam/user_groups/$PUSHED_GROUP  | jq .
{
    "policies": []
}
PAYLOAD

使用 SCIM 创建用户组

已配置 SCIM 集成的客户可以从上游身份提供商同步用户组到 Cloudflare。Cloudflare 的 SCIM 集成要求每个账户一个外部应用程序。

要使用 SCIM 设置用户组,请参阅 SCIM 配置指南

为用户组设置权限

用户组在 Cloudflare 仪表板中手动创建或通过 SCIM 集成创建后,最后一步是为其附加权限。

  1. 转到 Manage members(管理成员) > Members(成员) > User groups(用户组)
  2. 选择要附加权限的用户组。
  3. 选择 Permission policies(权限策略) 选项卡,然后选择 Add policy(添加策略)
  4. 选择要应用于策略的范围和角色。
  5. 选择 Save(保存) 应用策略。

开始之前,使用以下命令确认内部创建的或已推送到 Cloudflare 的组。

1. 获取用户组

Example requestcurl
$ curl -X GET -H "Authorization: Bearer $AOT" https://api.cloudflare.com/client/v4/accounts/$ACCT/iam/user_groups | jq .
Example responsecurl
{
    "errors": [],
    "messages": [],
    "result": [
        {
            "created_on": "2025-01-24T15:31:36.759979Z",
            "id": "f234f49f66df4db8864c5189fe78c87f",
            "modified_on": "2025-01-24T15:35:50.151764Z",
            "name": "My Cool Demo Group",
            "status": "V"
        },
        {
            "created_on": "2025-01-16T20:43:01.019311Z",
            "id": "7148c1e4d9f247f5b6dcd3ef20f998f9",
            "modified_on": "2025-01-16T20:44:07.627233Z",
            "name": "My Cool Demo Group, now with policies!",
            "policies": [
                {
                    "access": "allow",
                    "created_on": "2025-01-16T20:44:07.627233Z",
                    "id": "8d82cf8c15c64e07a4bee58e00d80bca",
                    "modified_on": "2025-01-16T20:44:07.627233Z",
                    "permission_groups": [
                        {
                            "created_on": "2023-06-21T18:58:29.907496Z",
                            "id": "a1a099e3256942259bfde18c688b67d5",
                            "meta": {
                                "description": "Grants write access to Page Shield for domain",
                                "editable": "false",
                                "label": "domain_page_shield",
                                "scopes": "com.cloudflare.api.account.zone"
                            },
                            "modified_on": "2023-06-21T18:58:29.907496Z",
                            "name": "Domain Page Shield",
                            "permissions": ["dev note: snipped for length"],
                            "status": "V"
                        }
                    ],
                    "resource_groups": [
                        {
                            "created_on": "2025-01-16T20:44:07.627233Z",
                            "modified_on": "2025-01-16T20:44:07.627233Z",
                            "scope": {
                                "key": "com.cloudflare.api.account.a3324a084cd290080b563ab39c91545a",
                                "objects": [
                                    {
                                        "key": "*"
                                    }
                                ]
                            }
                        }
                    ],
                    "status": "V"
                }
            ],
            "status": "V"
        }
    ],
    "result_info": {
        "count": 2,
        "page": 1,
        "per_page": 100,
        "total_count": 2,
        "total_pages": 1
    },
    "success": true
}

2. 针对资源 ID 进行查询

找到从 IdP 推送的组的标签,并使用它直接查询其资源 ID:

export PUSHED_GROUP='...' # Pull this value from the "id" json field in the group list response

Example requestcurl
$ curl -XGET -H "Authorization: Bearer $AOT" https://api.cloudflare.com/client/v4/accounts/$ACCT/iam/user_groups/$PUSHED_GROUP | jq .

此响应应包含身份提供商中指定的组名,且未附加任何策略。

3. 查看可用权限组

修改组策略之前,通过查询账户 API 查看可用的权限组(角色)。

Example requestcurl
$ curl -XGET -H "Authorization: Bearer $DEMO_AOT" https://api.cloudflare.com/client/v4/accounts/$ACCT/iam/permission_groups | jq .
Example responsecurl
{
  "result": [
    {
      "id": "1a0fc8bdeae24387b64d5b8de1ad052a",
      "name": "Administrator Read Only",
      "status": "V",
      "meta": {
        "description": "Can access the full account in read-only mode.",
        "editable": "false",
        "label": "admin_readonly",
        "scopes": "com.cloudflare.api.account"
      },
      "created_on": "2020-07-06T12:19:13.099114Z",
      "modified_on": "2020-10-13T11:18:00.208228Z"
    },
    {
      "id": "ce2c69b09baf4ca38223910a8b7e07a9",
      "name": "Administrator",
      "status": "V",
      "meta": {
        "description": "Can access the full account, except for membership management and billing.",
        "editable": "false",
        "label": "admin",
        "scopes": "com.cloudflare.api.account"
      },
      "created_on": "2020-07-06T12:19:13.099114Z",
      "modified_on": "2020-10-13T11:18:00.208228Z"
    }
  ],
  "success": true,
  "errors": [],
  "messages": []
}

检查组成员

要验证 IdP 是否同步了 SCIM 操作中推送的组和用户成员,请查询 Group Members API。

Example requestcurl
$ curl -XGET -H "Authorization: Bearer $DEMO_AOT" https://api.cloudflare.com/client/v4/accounts/$ACCT/iam/user_groups/$PUSHED_GROUP/members | jq .
Example responsecurl
{
  "result": [
    {
      "id": "a4366a09c43a0b0c4606dc5528472bb6",
      "email": "luke.skywalker@rebelalliance.net"
    },
    {
      "id": "0329c17f6c13f5202dc38d2036efb1a9",
      "email": "arya.stark@winterfell.place"
    }
  ],
  "result_info": {
    "page": 1,
    "per_page": 100,
    "total_pages": 1,
    "count": 2,
    "total_count": 2
  },
  "success": true,
  "errors": [],
  "messages": []
}

这篇文档对您有帮助吗?