セキュリティ グループの作成
このページでは、セキュリティ グループを作成する方法について説明します。新しいセキュリティ グループを作成することも、Google グループをセキュリティ グループに更新することもできます。
始める前に
次の作業を実施した後、このページの内容に進んでください。
Groups API の概要を確認する。
セキュリティ グループの要件
セキュリティ グループには次のもののみを含めることができます。
- ドメイン内外のユーザー(Google サービスに関連付けられているユーザー)
 - ドメイン内外のサービス アカウント
 - ドメイン内のセキュリティ グループ
 
これらの条件を満たさない Google グループには、セキュリティ グループのラベルを適用できません。
セキュリティ グループを更新する権限を持つのは、事前定義された特権管理者またはグループ管理者のみです。
新しいセキュリティ グループの作成
REST
セキュリティ グループを作成するには、groups.create() を呼び出して新しいグループのインスタンスを指定します。グループ インスタンスには、cloudidentity.googleapis.com/groups.security および cloudidentity.googleapis.com/groups.discussion_forum に設定された groupKey、Parent、labels を含める必要があります。
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 グループをセキュリティ グループに更新するには、updateMask を cloudidentity.googleapis.com/groups.security と cloudidentity.googleapis.com/groups.discussion_forum に設定して groups.patch() を呼び出します。
リクエストの本文の例
{
  "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)