创建安全群组

本页介绍了如何创建安全群组。您可以创建新的安全群组或将 Google 群组更新为安全群组。

准备工作

在继续此页面的信息之前,请先执行以下任务:

安全群组要求

安全群组只能包含以下内容:

  • 您网域内或网域外的用户(同时与 Google 服务相关联)
  • 网域内或网域外的服务账号
  • 您网域中的安全群组

您无法将安全群组标签应用于不符合这些条件的 Google 群组。

只有预定义的超级用户或群组管理员有权更新安全群组。

创建新的安全群组

REST

如需创建安全群组,请使用新群组的实例调用 groups.create()。群组实例必须包含 groupKeyParent 以及设置为 cloudidentity.googleapis.com/groups.securitycloudidentity.googleapis.com/groups.discussion_forumlabels

Python

以下示例展示了使用 Python 客户端库创建 Google 群组的辅助函数:

def create_google_group(service, customer_id, group_id, group_display_name, group_description):
  group_key = {"id": group_id}
  group = {
    "parent": "customers/" + customer_id,
    "description": group_description,
    "displayName": group_display_name,
    "groupKey": group_key,
    # Set the label to specify creation of a Google Group.
    "labels": {
      "cloudidentity.googleapis.com/groups.security": "",
      "cloudidentity.googleapis.com/groups.discussion_forum": ""
    }
  }

  try:
    request = service.groups().create(body=group)
    request.uri += "&initialGroupConfig=WITH_INITIAL_OWNER"
    response = request.execute()
    print(response)
  except Exception as e:
    print(e)

将 Google 群组更新为安全群组

REST

如需将 Google 群组更新为安全群组,请调用 groups.patch(),并将 updateMask 设置为 cloudidentity.googleapis.com/groups.securitycloudidentity.googleapis.com/groups.discussion_forum

请求正文示例

{
  "labels": {
    "cloudidentity.googleapis.com/groups.security": "",
    "cloudidentity.googleapis.com/groups.discussion_forum": ""
  }
}

Python

以下示例展示了使用 Python 客户端库将 Google 群组更新为安全群组的辅助函数:

def add_security_label_to_group(service, group_name):
  group = {
    "labels": {
      "cloudidentity.googleapis.com/groups.security": "",
      "cloudidentity.googleapis.com/groups.discussion_forum": ""
    }
  }
  try:
    request = service.groups().patch(name=group_name, body=group)
    request.uri = request.uri + '&updateMask=labels'
    response = request.execute()
    print(response)
  except Exception as e:
    print(e)