使用存取群組簡化存取管理

將使用者、服務 ID 和可信賴的設定檔組織為存取群組,以進行有效率的權限管理。 為整個群組一次指派細粒度的政策,以規模實施最小特權。

建立存取群組可將一組使用者、服務 ID 及受信任的設定檔組織為單一實體,方便您指派存取權限。 您可以為群組指定單一政策,而無需為個別使用者或服務 ID 多次指定相同的存取。

會指派原則給存取群組,將角色和許可權授與該群組的成員。 存取群組的成員可以包含多種身分類型,例如使用者、服務 ID 和可信賴的設定檔。 成員會繼承指派給存取群組的政策、角色和權限,也會保留個別指派給他們的角色。

例如,如果使用者在計費服務上被指派 viewer 角色,而他們被加入到在目錄管理服務上具有 publisher 角色的存取群組中,他們會保留 viewer 角色,即使這並非存取群組權限的一部分。

若要更輕鬆地指派及管理存取權,您可以設定資源群組,來組織您想要一群使用者能存取的一組資源。 設定好資源群組之後,您可以指派一個原則,來提供對該群組內所有資源的存取權,而不是為您帳戶內的個別服務實例建立存取原則。

開始之前

若要管理或建立新的存取群組,您必須具有下列類型的存取權:

  • 帳戶中 IAM 存取群組帳戶管理服務的管理員或編輯員
  • 所有帳戶管理服務的管理者或編輯者
  • 您必須是帳戶所有者

此外,管理者或編輯者可以藉由建立存取原則(其中資源是存取群組 ID)而獲指派存取權來管理個別群組。 如需 IAM 存取群組服務之存取原則及角色的相關資訊,請參閱 IAM 存取

開始之前

在使用 Terraform 設定存取群組之前,請確認您已完成下列事項:

  • 安裝 Terraform CLI 並為 Terraform 配置 IBM Cloud Provider 外掛程式。 如需詳細資訊,請參閱 IBM Cloud® 上的 Terraform 入門 教學。 外掛程式抽象出 IBM Cloud API,用來完成這項任務。
  • 建立名為 main.tf 的 Terraform 配置檔案。 在此檔案中,您使用 HashiCorp Configuration Language 定義資源。 如需詳細資訊,請參閱 Terraform 文件

在主控台中建立存取群組

必須使用唯一的名稱來區分帳戶中的存取群組。 若要建立存取群組,請完成下列步驟:

  1. 在 IBM Cloud® 主控台中,按一下管理 > 存取 (IAM),然後選擇存取群組
  2. 按一下建立
  3. 輸入唯一的名稱以識別您的存取群組、可選的說明,然後按一下建立

接下來,繼續加入使用者、服務 ID 或信任的設定檔來設定群組。 您可以手動或透過 建立動態規則 來新增使用者。 或者,您可以開始指派群組存取權限,稍後再決定要將誰加入存取群組。

您可以選取移除群組選項來刪除群組。 當您從帳戶移除群組時,您會從群組移除所有使用者及服務 ID,以及指派給群組的所有存取權。

使用 CLI 建立存取群組

若要使用 CLI 建立存取群組,您可以使用 ibmcloud iam access-group-create 指令。

ibmcloud iam access-group-create GROUP_NAME [-d, --description DESCRIPTION]

必須使用唯一的名稱來區分帳戶中的存取群組。

使用 API 建立存取群組

您可以透過呼叫 IBM Cloud® Identity and Access Management(IAM)Access Groups API 程式化建立存取群組,如以下範例請求所示。 本範例為帳戶中的經理建立存取群組:

curl -X POST -H "Authorization: Bearer {iam_token}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{ "name": "Managers", "description": "Group for managers" }' \
"{base_url}/groups?account_id={account_id}"
CreateAccessGroupOptions createAccessGroupOptions = new CreateAccessGroupOptions.Builder()
  .accountId(testAccountId)
  .name("Managers")
  .description("Group for managers")
  .build();

Response<Group> response = service.createAccessGroup(createAccessGroupOptions).execute();
Group group = response.getResult();

System.out.println(group);
const params = {
  accountId: testAccountId,
  name: 'Managers',
  description: 'Group for managers'
};

iamAccessGroupsService.createAccessGroup(params)
  .then(res => {
    testGroupId = res.result.id;
    console.log(JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
  });
group = iam_access_groups_service.create_access_group(
  account_id=test_account_id,
  name='Managers',
  description='Group for managers'
).get_result()

print(json.dumps(group, indent=2))
createAccessGroupOptions := iamAccessGroupsService.NewCreateAccessGroupOptions(testAccountID, "Managers")
createAccessGroupOptions.SetDescription("Group for managers")
group, response, err := iamAccessGroupsService.CreateAccessGroup(createAccessGroupOptions)
if err != nil {
  panic(err)
}
b, _ := json.MarshalIndent(group, "", "  ")
fmt.Println(string(b))

必須使用唯一的名稱來區分帳戶中的存取群組。

使用 Terraform 建立存取群組

使用以下步驟,透過 Terraform 建立存取群組:

  1. main.tf 檔案中建立一個參數。 以下範例使用 ibm_iam_access_group 資源建立存取群組,其中 name 是識別存取群組的唯一名稱。

    resource "ibm_iam_access_group" "accgrp" {
     name        = "test"
     description = "New access group"
    }
    

    您也可以在 description 選項上指定存取群組的說明。 如需詳細資訊,請參閱 Terraform Identity and Access Management(IAM) 頁面的參數參考細節。

透過 Terraform IBM 模組(TIM) for IAM 存取群組 將使用者和服務 ID 分組,簡化存取管理。

  1. 完成建立組態檔案後,初始化 Terraform CLI。 如需詳細資訊,請參閱 初始化工作目錄

    terraform init
    
  2. main.tf 檔案提供資源。 如需詳細資訊,請參閱 使用 Terraform 佈建基礎結構

    1. 執行 terraform plan 以產生 Terraform 執行計畫,預覽建議的動作。

      terraform plan
      
    2. 執行 terraform apply 以建立計劃中定義的資源。

      terraform apply
      

在主控台中指定群組存取權限

在您以使用者和服務 ID 設定群組之後,可以將一般存取原則指派給群組。 請記住,為群組設定的任何原則都會適用於群組內的所有實體。 例如,將存取政策指派給存取群組,可將授予或撤銷存取使用者、服務-ID 或受信任設定檔的能力,委派給該存取群組的管理員。

管理員可存取帳戶中的所有內容,包括撤銷其他具有管理員角色的使用者的存取權限。

使用下列步驟在主控台中指定群組的存取權限:

  1. 在 IBM Cloud 主控台中,按一下管理 > 存取 (IAM),然後選擇存取群組

  2. 對於要指派存取權的群組,選擇動作圖示動作圖示,然後按一下指派存取權

  3. 您可以僅對您管理的資源指派存取權限。 您必須至少指派一個存取選項。 對於您未新增及配置的任何存取選項,會指派預設值:不可存取。 取決於獲授權管理的選項,您可以指派下列類型的存取權:

    • 一組服務,如 所有啟用身分與存取的服務所有帳戶管理服務所有 IAM 帳戶管理服務
    • 特定服務
  4. 接下來,您可以根據選取的資源屬性 (例如存取管理標籤、位置或資源群組) 來設定所有資源或特定資源的存取範圍。

  5. 選取所有套用的角色。 若要檢視映射到每個角色的動作,請按一下每個角色旁邊列出的數字。 有些服務支援使用進階操作員,以授予對符合特定命名慣例的資源的存取權。 如需詳細資訊,請參閱 使用通配符原則指定存取

  6. 按一下審閱

  7. 按一下新增,將您的政策組態新增至政策摘要。

  8. 按一下指派

您也可以使用存取管理標籤來指定存取權。 如需詳細資訊,請參閱 使用標籤控制資源存取

使用 CLI 為群組指定存取權限

若要使用 CLI 建立存取群組原則,您可以使用 ibmcloud iam access-group-policy-create 指令。

ibmcloud iam access-group-policy-create GROUP_NAME {-f, --file @JSON_FILE | --roles ROLE_NAME1,ROLE_NAME2... [--service-name SERVICE_NAME] [--service-instance SERVICE_INSTANCE] [--region REGION] [--resource-type RESOURCE_TYPE] [--resource RESOURCE] [--resource-group-name RESOURCE_GROUP_NAME] [--resource-group-id RESOURCE_GROUP_ID]}

使用 API 指定群組存取權限

您可以透過呼叫 IBM Cloud® Identity and Access Management(IAM)Policy Management API,以程式化的方式將存取權指定給群組,如以下範例請求所示。 本範例為服務的實例指定存取群組 Editor 角色:

curl -X POST 'https://iam.cloud.ibm.com/v1/policies' \
-H 'Authorization: Bearer $TOKEN' \
-H 'Content-Type: application/json' \
-d '{
  "type": "access",
  "description": "Editor role for SERVICE_NAME's RESOURCE_NAME",
  "subjects": [
    {
      "attributes": [
        {
          "name": "access_group_id",
          "value": "exampleAccessGroupId"
        }
      ]
    }'
  ],
  "roles":[
    {
      "role_id": "crn:v1:bluemix:public:iam::::role:Editor"
    }
  ],
  "resources":[
    {
      "attributes": [
        {
          "name": "accountId",
          "value": "$ACCOUNT_ID"
        },
        {
          "name": "serviceName",
          "value": "$SERVICE_NAME"
        },
        {
          "name": "resource",
          "value": "$RESOURCE_NAME",
          "operator": "stringEquals"
        }
      ]
    }
  ]
}'
SubjectAttribute subjectAttribute = new SubjectAttribute.Builder()
        .name("access_group_id")
        .value(exampleAccessGroupId)
        .build();

PolicySubject policySubjects = new PolicySubject.Builder()
        .addAttributes(subjectAttribute)
        .build();

PolicyRole policyRoles = new PolicyRole.Builder()
        .roleId("crn:v1:bluemix:public:iam::::role:Editor")
        .build();

ResourceAttribute accountIdResourceAttribute = new ResourceAttribute.Builder()
        .name("accountId")
        .value(exampleAccountId)
        .operator("stringEquals")
        .build();

ResourceAttribute serviceNameResourceAttribute = new ResourceAttribute.Builder()
        .name("serviceType")
        .value("service")
        .operator("stringEquals")
        .build();

PolicyResource policyResources = new PolicyResource.Builder()
        .addAttributes(accountIdResourceAttribute)
        .addAttributes(serviceNameResourceAttribute)
        .build();

CreatePolicyOptions options = new CreatePolicyOptions.Builder()
        .type("access")
        .subjects(Arrays.asList(policySubjects))
        .roles(Arrays.asList(policyRoles))
        .resources(Arrays.asList(policyResources))
        .build();

Response<Policy> response = service.createPolicy(options).execute();
Policy policy = response.getResult();

System.out.println(policy);
const policySubjects = [
  {
    attributes: [
      {
        name: 'access_group_id',
        value: exampleAccessGroupId,
      },
    ],
  },
];
const policyRoles = [
  {
    role_id: 'crn:v1:bluemix:public:iam::::role:Editor',
  },
];
const accountIdResourceAttribute = {
  name: 'accountId',
  value: exampleAccountId,
  operator: 'stringEquals',
};
const serviceNameResourceAttribute = {
  name: 'serviceType',
  value: 'service',
  operator: 'stringEquals',
};
const policyResources = [
  {
    attributes: [accountIdResourceAttribute, serviceNameResourceAttribute],
  },
];
const params = {
  type: 'access',
  subjects: policySubjects,
  roles: policyRoles,
  resources: policyResources,
};

iamPolicyManagementService.createPolicy(params)
  .then(res => {
    examplePolicyId = res.result.id;
    console.log(JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
  });
policy_subjects = PolicySubject(
  attributes=[SubjectAttribute(name='access_group_id', value=exampleAccessGroupId)])
policy_roles = PolicyRole(
  role_id='crn:v1:bluemix:public:iam::::role:Editor')
account_id_resource_attribute = ResourceAttribute(
  name='accountId', value=example_account_id)
service_name_resource_attribute = ResourceAttribute(
  name='serviceType', value='service')
policy_resources = PolicyResource(
  attributes=[account_id_resource_attribute,
        service_name_resource_attribute])

policy = iam_policy_management_service.create_policy(
  type='access',
  subjects=[policy_subjects],
  roles=[policy_roles],
  resources=[policy_resources]
).get_result()

print(json.dumps(policy, indent=2))
subjectAttribute := &iampolicymanagementv1.SubjectAttribute{
  Name:  core.StringPtr("access_group_id"),
  Value: &exampleAccessGroupId,
}
policySubjects := &iampolicymanagementv1.PolicySubject{
  Attributes: []iampolicymanagementv1.SubjectAttribute{*subjectAttribute},
}
policyRoles := &iampolicymanagementv1.PolicyRole{
  RoleID: core.StringPtr("crn:v1:bluemix:public:iam::::role:Editor"),
}
accountIDResourceAttribute := &iampolicymanagementv1.ResourceAttribute{
  Name:     core.StringPtr("accountId"),
  Value:    core.StringPtr(exampleAccountID),
  Operator: core.StringPtr("stringEquals"),
}
serviceNameResourceAttribute := &iampolicymanagementv1.ResourceAttribute{
  Name:     core.StringPtr("serviceType"),
  Value:    core.StringPtr("service"),
  Operator: core.StringPtr("stringEquals"),
}
policyResources := &iampolicymanagementv1.PolicyResource{
  Attributes: []iampolicymanagementv1.ResourceAttribute{
    *accountIDResourceAttribute, *serviceNameResourceAttribute}
}

options := iamPolicyManagementService.NewCreatePolicyOptions(
  "access",
  []iampolicymanagementv1.PolicySubject{*policySubjects},
  []iampolicymanagementv1.PolicyRole{*policyRoles},
  []iampolicymanagementv1.PolicyResource{*policyResources},
)

policy, response, err := iamPolicyManagementService.CreatePolicy(options)
if err != nil {
  panic(err)
}
b, _ := json.MarshalIndent(policy, "", "  ")
fmt.Println(string(b))

您可以指派一組服務的存取權。 若要指定 所有啟用身分與存取的服務 的存取權限,請指定 serviceTypename 屬性,並使用 value service。 若要指定所有帳戶管理服務的存取權,請指定 serviceTypename 屬性,並使用 value platform_service。 若要指定帳戶管理服務子集的存取權所有 IAM 帳戶管理服務,請指定 service_group_idname 屬性,並使用 value IAM

使用 Terraform 為群組指派存取權限

設定群組後,請使用以下步驟,透過 Terraform 為群組指派存取權限。

  1. main.tf 檔案中建立一個參數。 以下範例透過使用 ibm_iam_access_group_policy 資源,建立一個 IAM 政策,授予存取群組成員 IAM Viewer 平台角色至所有啟用 IAM 的服務。 您必須擁有存取群組的現有 IAM ID,才能完成任務。

    resource "ibm_iam_access_group" "accgrp" {
     name = "test"
    }
    
    resource "ibm_iam_access_group_policy" "policy" {
     access_group_id = ibm_iam_access_group.accgrp.id
     roles           = ["Viewer"]
    }
    

    如需詳細資訊,請參閱 Terraform Identity and Access Management(IAM) 頁面的參數參考細節。

您也可以使用 IAM 存取群組模組,以大規模管理存取群組和政策。 以下範例示範使用該模組:

module "access_group" {
  source  = "terraform-ibm-modules/iam-access-group/ibm"
  version = "latest"

  access_group_name        = "my-access-group"
  access_group_description = "Access group for team members"

  policies = [
    {
      roles = ["Viewer"]
      resources = [{
        service = "cloud-object-storage"
      }]
    }
  ]
}

關於 Terraform IBM 模組的更多資訊,請參閱 關於 Terraform IBM 模組

  1. 完成建立組態檔案後,初始化 Terraform CLI。 如需詳細資訊,請參閱 初始化工作目錄

    terraform init
    
  2. main.tf 檔案提供資源。 如需詳細資訊,請參閱 使用 Terraform 佈建基礎結構

    1. 執行 terraform plan 以產生 Terraform 執行計畫,預覽建議的動作。

      terraform plan
      
    2. 執行 terraform apply 以建立計劃中定義的資源。

      terraform apply
      

在主控台中將成員加入存取群組

成員可以是使用者、服務 ID 和可信賴的設定檔。

  1. 在 IBM Cloud® 主控台中,按一下管理 > 存取 (IAM),然後選擇存取群組

  2. 按一下您建立的存取群組。

  3. 新增成員。

    1. 按一下新增使用者
    2. 按一下服務 ID > 新增服務 ID
    3. 按一下受信任的設定檔 > 新增受信任的設定檔

    如果您沒有看到新增會員的按鈕,可能是您沒有權限。 檢視 存取要求,並聯絡您的帳戶管理員以取得存取權限。

  4. 選取要加入群組的使用者、服務 ID 或受信任的設定檔,然後按一下加入群組

您新增到群組的成員可以使用您指派給群組的存取權限等級。

使用 CLI 將成員加入存取群組

成員可以是使用者、服務 ID 和可信賴的設定檔。 您新增到群組的成員可以使用您指派給群組的存取權限等級。

  1. 取得帳戶中的使用者、服務 ID 或信任的設定檔。 請注意要加入存取群組的成員所傳回的詳細資訊。

    取得所有使用者

    ibmcloud account users [-c, --account-id ACCOUNT_ID]
    

    列出所有服務 ID

    ibmcloud iam service-ids [--uuid]
    

    取得所有受信任的檔案

    ibmcloud iam trusted-profiles [--id | --output FORMAT] [-q, --quiet]
    
  2. 將成員加入存取群組:

    使用 ibmcloud iam access-group-user-add 指令將使用者新增至存取群組。 以下範例使用 CLI 將使用者 name@example.com 加入存取群組 example_group

    ibmcloud iam access-group-user-add example_group name@example.com
    

    使用 ibmcloud iam access-group-service-id-add 指令將服務 ID 新增至存取群組。 以下範例會將服務 ID example-service 加入存取群組 example_group

    ibmcloud iam access-group-service-id-add example_group example-service
    

    使用 ibmcloud iam access-group-trusted profile-add 指令將受信任的設定檔新增至存取群組。 以下範例會將服務 ID PROFILE_ID 加入存取群組 example_group

    ibmcloud iam access-group-trusted-profile-add GROUP_NAME (PROFILE_NAME | PROFILE_ID) [PROFILE_NAME2 | PROFILE_ID2...] [--output FORMAT] [-q, --quiet]
    

使用 API 將成員加入存取群組

成員可以是使用者、服務 ID 和可信賴的設定檔。

  1. 列出帳戶中的使用者、服務 ID 或受信任的設定檔,如以下範例請求所示。 請注意要加入存取群組的成員所傳回的 IBMid、服務 ID 或信任設定檔 ID。

    清單使用者

    curl -X GET https://user-management.cloud.ibm.com/v2/accounts/987d4cfd77b04e9b9e1a6asdcc861234/users -H 'Authorization: Bearer <IAM_TOKEN>'
    
    ListUsersOptions listUsersOptions = new ListUsersOptions.Builder()
      .accountId(accountId)
      .build();
    
    UsersPager pager = new UsersPager(userManagementService, listUsersOptions);
    List<UserProfile> allResults = new ArrayList<>();
    while (pager.hasNext()) {
      List<UserProfile> nextPage = pager.getNext();
      allResults.addAll(nextPage);
    }
    
    System.out.println(GsonSingleton.getGson().toJson(allResults));
    
    const params = {
      accountId: accountId,
    };
    
    const allResults = [];
    try {
      const pager = new UserManagementV1.UsersPager(userManagementService, params);
      while (pager.hasNext()) {
        const nextPage = await pager.getNext();
        expect(nextPage).not.toBeNull();
        allResults.push(...nextPage);
      }
      console.log(JSON.stringify(allResults, null, 2));
    } catch (err) {
      console.warn(err);
    }
    
    all_results = []
    pager = UsersPager(
      client=user_management_service,
      account_id=account_id,
    )
    while pager.has_next():
      next_page = pager.get_next()
      assert next_page is not None
      all_results.extend(next_page)
    
    print(json.dumps(all_results, indent=2))
    
    listUsersOptions := &usermanagementv1.ListUsersOptions{
      AccountID: &accountID,
    }
    
    pager, err := userManagementService.NewUsersPager(listUsersOptions)
    if err != nil {
      panic(err)
    }
    
    var allResults []usermanagementv1.UserProfile
    for pager.HasNext() {
      nextPage, err := pager.GetNext()
      if err != nil {
        panic(err)
      }
      allResults = append(allResults, nextPage...)
    }
    b, _ := json.MarshalIndent(allResults, "", "  ")
    fmt.Println(string(b))
    

    列出服務 ID

    curl -X GET 'https://iam.cloud.ibm.com/v1/serviceids?account_id=ACCOUNT_ID&name=My-serviceID' -H 'Authorization: Bearer TOKEN' -H 'Content-Type: application/json'
    
    ListServiceIdsOptions listServiceIdsOptions = new ListServiceIdsOptions.Builder()
        .accountId(accountId)
        .name(serviceIdName)
        .build();
    
    Response<ServiceIdList> response = service.listServiceIds(listServiceIdsOptions).execute();
    ServiceIdList serviceIdList = response.getResult();
    
    System.out.println(serviceIdList);
    
    const params = {
      accountId: accountId,
      name: serviceIdName,
    };
    
    try {
      const res = await iamIdentityService.listServiceIds(params)
      console.log(JSON.stringify(res.result, null, 2));
    } catch (err) {
      console.warn(err);
    }
    
    service_id_list = iam_identity_service.list_service_ids(
      account_id=account_id, name=serviceid_name
    ).get_result()
    
    print(json.dumps(service_id_list, indent=2))
    
    listServiceIdsOptions := iamIdentityService.NewListServiceIdsOptions()
    listServiceIdsOptions.SetAccountID(accountID)
    listServiceIdsOptions.SetName(serviceIDName)
    
    serviceIDList, response, err := iamIdentityService.ListServiceIds(listServiceIdsOptions)
    if err != nil {
      panic(err)
    }
    b, _ := json.MarshalIndent(serviceIDList, "", "  ")
    fmt.Println(string(b))
    

    列出受信任的設定檔

    curl -X GET 'https://iam.cloud.ibm.com/v1/profiles?account_id=ACCOUNT_ID' -H 'Authorization: Bearer TOKEN' -H 'Accept: application/json'
    
    ListProfilesOptions listProfilesOptions = new ListProfilesOptions.Builder()
        .accountId(accountId)
        .includeHistory(false)
        .build();
    
    Response<TrustedProfilesList> response = service.listProfiles(listProfilesOptions).execute();
    TrustedProfilesList profiles = response.getResult();
    
    System.out.println(profiles);
    
    const params = {
      accountId: accountId,
      includeHistory: false,
    };
    
    try {
      const res = await iamIdentityService.listProfiles(params);
      console.log(JSON.stringify(res.result, null, 2));
    } catch (err) {
      console.warn(err);
    }
    
    profile_list = iam_identity_service.list_profiles(account_id=account_id, include_history=True).get_result()
    
    print(json.dumps(profile_list, indent=2))
    
    listProfilesOptions := iamIdentityService.NewListProfilesOptions(accountID)
    listProfilesOptions.SetIncludeHistory(false)
    
    trustedProfiles, response, err := iamIdentityService.ListProfiles(listProfilesOptions)
    if err != nil {
      panic(err)
    }
    b, _ := json.MarshalIndent(trustedProfiles, "", "  ")
    fmt.Println(string(b))
    
  2. 透過呼叫 IAM 存取 群組 API 將成員加入存取群組,如以下範例請求所示。

    成員類型必須是 user, serviceprofile

    curl -X PUT --location --header "Authorization: Bearer {iam_token}" --header "Accept: application/json" --header "Content-Type: application/json" --data '{ "members": [ { "iam_id": "IBMid-user1", "type": "user" }, { "iam_id": "iam-ServiceId-123", "type": "service" }, { "iam_id": "iam-Profile-123", "type": "profile" } ] }' "{base_url}/v2/groups/{access_group_id}/members"
    
    AddGroupMembersRequestMembersItem member1 = new AddGroupMembersRequestMembersItem.Builder()
      .iamId("IBMid-user1")
      .type("user")
      .build();
    AddGroupMembersRequestMembersItem member2 = new AddGroupMembersRequestMembersItem.Builder()
      .iamId("iam-ServiceId-123")
      .type("service")
      .build();
      AddGroupMembersRequestMembersItem member3 = new AddGroupMembersRequestMembersItem.Builder()
      .iamId(testProfileId)
      .type("profile")
      .build();
    AddMembersToAccessGroupOptions addMembersToAccessGroupOptions = new AddMembersToAccessGroupOptions.Builder()
      .accessGroupId(testGroupId)
      .addMembers(member1)
      .addMembers(member2)
      .addMembers(member3)
      .build();
    Response<AddGroupMembersResponse> response = iamAccessGroupsService.addMembersToAccessGroup(addMembersToAccessGroupOptions).execute();
    AddGroupMembersResponse addGroupMembersResponse = response.getResult();
    
    System.out.println(addGroupMembersResponse);
    
    const groupMember1 = {
      iam_id: 'IBMid-user1',
      type: 'user',
    };
    const groupMember2 = {
      iam_id: 'iam-ServiceId-123',
      type: 'service',
    };
    var groupMember3 = {
      iam_id: profileId,
      type: 'profile',
    }
    
    const params = {
      accessGroupId: testGroupId,
      members: [groupMember1, groupMember2, groupMember3],
    };
    
    try {
      const res = await iamAccessGroupsService.addMembersToAccessGroup(params);
      console.log(JSON.stringify(res.result, null, 2));
    } catch (err) {
      console.warn(err);
    }
    
    member1 = AddGroupMembersRequestMembersItem(iam_id='IBMid-user1', type='user')
    member2 = AddGroupMembersRequestMembersItem(iam_id='iam-ServiceId-123', type='service')
    member3 = AddGroupMembersRequestMembersItem(iam_id=test_profile_id, type='profile')
    members = [member1, member2, member3]
    
    response = iam_access_groups_service.add_members_to_access_group(
      access_group_id=test_group_id,
      members=members,
    )
    add_group_members_response = response.get_result()
    
    print(json.dumps(add_group_members_response, indent=2))
    
    groupMembers := []iamaccessgroupsv2.AddGroupMembersRequestMembersItem{
      iamaccessgroupsv2.AddGroupMembersRequestMembersItem{
        IamID: core.StringPtr("IBMid-user1"),
        Type:  core.StringPtr("user"),
      },
      iamaccessgroupsv2.AddGroupMembersRequestMembersItem{
        IamID: core.StringPtr("iam-ServiceId-123"),
        Type:  core.StringPtr("service"),
      },
      iamaccessgroupsv2.AddGroupMembersRequestMembersItem{
        IamID: core.StringPtr(testProfileID),
        Type:  core.StringPtr("profile"),
      },
    }
    
    addMembersToAccessGroupOptions := iamAccessGroupsService.NewAddMembersToAccessGroupOptions(
      accessGroupIDLink,
    )
    addMembersToAccessGroupOptions.SetMembers(groupMembers)
    
    addGroupMembersResponse, response, err := iamAccessGroupsService.AddMembersToAccessGroup(addMembersToAccessGroupOptions)
    if err != nil {
      panic(err)
    }
    b, _ := json.MarshalIndent(addGroupMembersResponse, "", "  ")
    fmt.Println(string(b))
    

您新增到群組的成員可以使用您指派給群組的存取權限等級。

使用 Terraform 將成員加入存取群組

成員可以是使用者、服務 ID 和可信賴的設定檔。

  1. main.tf 檔案中建立一個參數。 以下範例將服務 ID、受信任設定檔和 ID 為 user@ibm.com 的使用者加入存取群組。

    resource "ibm_iam_access_group_members" "accgroupmem" {
      access_group_id = ibm_iam_access_group.accgroup.id
      ibm_ids         = ["user@ibm.com"]
      iam_service_ids = [ibm_iam_service_id.serviceID.id]
      iam_profile_ids = [ibm_iam_trusted_profile.profileID.id]
    }
    

使用 IAM 存取群組模組 以程式化方式管理群組成員資格,以進行自動使用者配置。 探索用於成員管理的 Terraform IBM 模組

  1. 完成建立組態檔案後,初始化 Terraform CLI。 如需詳細資訊,請參閱 初始化工作目錄

    terraform init
    
  2. main.tf 檔案提供資源。 如需詳細資訊,請參閱 使用 Terraform 佈建基礎結構

    1. 執行 terraform plan 以產生 Terraform 執行計畫,預覽建議的動作。

      terraform plan
      
    2. 執行 terraform apply 以建立計劃中定義的資源。

      terraform apply
      

您新增到群組的成員可以使用您指派給群組的存取權限等級。