建立安全性群組
本頁說明如何建立安全群組。您可以建立新的安全性群組,或將 Google 群組更新為安全性群組。
事前準備
請先執行下列工作,再繼續瞭解本頁資訊:
安全性群組規定
安全性群組只能包含下列項目:
- 網域內或外的使用者 (已連結 Google 服務)
 - 網域內或外的服務帳戶
 - 網域內的安全性群組
 
您無法將安全性群組標籤套用至不符合這些條件的 Google 網路論壇群組。
只有預先定義的超級管理員或群組管理員具備更新安全性群組的權限。
建立新的安全性群組
REST
如要建立安全群組,請使用新群組的例項呼叫 groups.create()。群組例項必須包含 groupKey、Parent 和 labels,並設為 cloudidentity.googleapis.com/groups.security 和 cloudidentity.googleapis.com/groups.discussion_forum
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.security 和 cloudidentity.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)