创建企业管理的可信个人资料模板
在拥有许多子账户的企业中,手动配置每个账户的信任配置文件既耗时又容易出错。 使用可信的个人资料模板,动态授权联合身份用户在您的企业中访问账户。
当您使用企业管理的可信配置文件模板时,您只能与联合用户建立信任关系。 要在子帐户中为计算资源、IBM Cloud 服务和服务ID设置受信任配置文件,请参 阅创建受信任配置文件。
用户无需成为账户会员即可应用可信资料。 如果用户与可信配置文件具有相同的身份提供商( IdP ),且符合信任条件,则可以应用该配置文件。 例如,企业目录中的某个用户需要访问一组账户来完成一项特定任务。 创建一个可信的个人资料模板,其中包含针对该用户的信任条件以及他们需要的政策。 然后,将可信的个人资料模板分配给需要访问权限的账户。 现在,用户可以通过在每个帐户中应用可信的个人资料来切换帐户,并且他们可以在各个帐户之间进行一致的访问。
身份服务的管理员可以在其帐户中向企业管理的可信配置文件添加信任关系和策略,但不能修改您在模板中定义的信任关系和策略。
准备工作
-
在开始之前,您需要 启用外部身份提供商的身份验证。
-
要了解企业管理的IAM模板如何使您的企业更安全,请参阅 企业管理的IAM访问权限的工作原理。
-
您必须是企业帐户的成员才能创建和分配企业管理的IAM模板。
-
要创建企业管理的IAM模板,请确保您被授予以下访问权限:
- 在“所有IAM账户管理服务”中具有模板管理员角色的策略
-
要将企业管理的IAM模板分配给子账户,请确保您被授予以下访问权限:
- 在“所有IAM账户管理服务”中具有模板分配管理员角色的策略
- 至少具有企业服务查看者角色的策略
默认情况下,包括账户所有者在内,没有任何用户拥有模板管理员或模板分配管理员的角色。
-
企业中的新账户和现有账户必须选择企业管理 IAM。 更多信息,请参阅 企业管理的IAM。
创建受信任的配置文件模板
当用户需要访问多个子账户时,或者一组用户需要临时访问多个子账户时,请考虑使用可信的配置文件模板。
要创建可信配置文件模板,请按照以下步骤操作:
-
转到管理 > 访问 (IAM) > 模板,然后在 IBM Cloud 控制台中选择受信任的配置文件。
-
单击创建。
-
输入受信任的配置文件模板的名称和描述,以便企业用户了解其用途。
-
为企业管理的受信任配置文件输入名称、电子邮件和描述,说明其对子账户用户的作用,并在描述中务必包含该受信任配置文件可执行的操作列表。
在邮件中,您可以添加个人邮箱地址或分发列表。
您可以在配置文件名称中使用替换变量,为每个账户定制配置文件。 支持以下变量:
${template_id}:将被可信配置文件模板的唯一标识符取代。${template_name}:将被受信任的配置文件模板的当前名称替换。${template_version}:将被当前版本的受信任配置文件模板取代。${account_id}:将被替换为受信任的配置文件模板所对应的账户标识符。${account_name}:将被替换为受信任的配置文件模板所对应的账户名称。
账户名称等值的更改不会导致受信任配置文件名称的更新。 配置文件名称在将模板分配给账户或升级模板版本时设置。 这意味着如果账户名称稍后更改,个人资料名称不会自动更新。 新账户名只会在下次分配模板或升级时使用。
-
单击创建。
(可选)添加信任关系
单个用户
使用 IBM Cloud IAM ID 与账户内外的个人用户建立信任。
要建立信任,请完成以下步骤:
- 单击信任关系 > 个人用户。
- 单击添加,然后选择账户用户或外部用户来邀请企业成员并分配模板。
- 单击“账户用户”在账户中添加用户。
- 选择一个或多个用户。
- 单击“**添加 **”将用户添加到关联的配置文件中。
- 单击“外部用户”添加账户中没有的用户。
- 输入 IAM ID。
- 输入相关账户 ID。 您可以添加多个账户,其中可以包括与用户当前工作账户不同的账户。
- (可选)输入描述。
- 单击“**添加 **”将用户添加到关联的配置文件中。
- 单击“账户用户”在账户中添加用户。
点击要编辑或删除的用户旁边的操作图标,选择添加或删除。
联合用户
根据企业目录中的属性设置相应条件,从而与联合用户建立信任关系。 当联合用户满足您定义的条件时,他们就可以申请该配置文件。
要建立信任,请完成以下步骤:
- 单击信任关系 > 联合用户。
- 单击添加,选择按 IBMid 联合的用户或按 IBM Cloud AppID 联合的用户作为身份验证方法,并输入默认身份提供者( IdP )。
- 根据您的 IdP 数据添加条件,以定义联合用户如何以及何时应用该配置文件。
- 单击添加条件可定义多个条件。 联邦用户必须满足所有条件才能申请可信个人资料。 有关用于创建条件的字段的更多信息,请参阅 IAM 条件属性。
- 查看身份提供商数据,以搜索您个人数据中的属性名称和值,数据来自您的 IdP。 更多信息,请参阅 使用 IdP 数据建立可信档案。
- 定义会话持续时间,即用户可以使用个人资料多长时间,然后必须重新验证。
- 单击添加。
点击要编辑或删除的联合用户旁边的操作图标,选择添加或删除。
计算资源
与计算资源建立信任关系,使在特定集群中运行的程序能够安全地访问必要的资源。
要建立信任,请完成以下步骤:
- 单击信任关系 > 计算资源。
- 单击添加,然后选择计算服务。
- 单击添加条件可定义多个条件。 有关用于创建条件的字段的更多信息,请参阅 IAM 条件属性。
- 单击添加。
单击要编辑或删除的计算资源旁边的操作图标,选择添加或删除。
IBM Cloud 服务
通过允许使用云资源名称标识的云服务实例,与 IBM Cloud 服务建立信任关系。
要建立信任,请完成以下步骤:
- 单击信任关系 > IBM Cloud 服务。
- 单击添加,然后输入 CRN。
- (可选)输入描述。
- 单击添加。
单击要编辑或删除的 IBM Cloud 服务旁边的操作图标,选择添加或删除。
服务标识
通过验证服务,建立对服务 ID 的信任。 可为特定服务创建一个服务 ID,并生成 API 密钥,以便对其进行安全验证。 此外,服务 ID 还可以承担受信任的配置文件,根据需要继承权限和访问资源。
要建立信任,请完成以下步骤:
- 单击信任关系 > 服务 ID。
- 单击添加,然后输入服务 ID。
- (可选)输入描述。
- 单击添加。
单击要编辑或删除的服务 ID 旁边的操作图标,选择添加或删除。
(可选)添加访问策略
访问政策允许联合用户访问儿童账户,并应用个人资料。
-
点击 “访问”>“添加”。
-
输入名称并描述您要指定的策略。
您为可信配置文件模板配置的每项策略都会创建一个策略模板。 您可以参考一个策略模板,在其他企业IAM模板中分配访问权限。
-
选择一项服务或一组服务,然后单击“下一步”。
-
将访问范围设为所有资源,或根据属性选择特定资源,然后单击“下一步”。
-
在角色和操作部分,选择定义访问范围的角色。 您可以在策略模板流程中创建自定义角色模板,也可以从选定服务的现有自定义角色模板中选择自定义角色。
- 单击创建自定义角色,定义自定义操作组合。
- 输入模板名称。
- (可选)输入模板描述。
- 请输入自定义角色的名称。
- 请输入自定义角色的 ID。
- (可选)为自定义角色输入描述。
- 选择操作并单击“创建”。 自定义角色会与已为策略选择的任何其他角色一起被列出和选择。
使用搜索栏查找支持特定操作的角色。 例如,搜索“读取”、“编辑”或“查看”,即可显示适用这些操作的角色列表。
-
(可选)添加条件,指定您希望策略何时授予访问权限。
-
单击添加。
删除访问策略
您可以在模板提交和分配之前删除策略。
更新模板详情
在提交模板之前,您可以随时更新模板名称、可信配置文件名称和描述。 要更新模板详细信息,请按照以下步骤操作:
- 转到 “管理”>“访问控制(IAM)”>“模板”。
- 选择您要更新的可信个人资料模板。
- 点击“详细信息”部分中的 编辑 图标
。
- 对模板名称、可信配置文件名称和描述进行必要的更新。
- 单击保存。
如果您在提交模板后需要更新,请创建一个新版本。
查看您的可信个人资料模板
审核并提交可信的个人资料模板,以便不再对版本进行任何更改。 这样,模板分配管理员可以确保仅在您确认版本准备就绪时才分配该版本。
- 点击 “概览”>“评论”。
- 请确认您所信任的个人资料模板是否按照您的预期进行了配置。
- 点击复选框确认您无法更改版本。
- 单击提交。
为子账户分配可信的个人资料模板
将可信的个人资料模板分配给企业中的子账户。
您只能将IAM模板分配给子账户和账户组,而不能分配给企业账户。
-
点击分配账户。
-
选择您要为其分配模板的账户和账户组。
在您为每个孩子账户分配模板时,都会创建一个企业管理的可信配置文件。 子账户中的用户可以确定可信配置文件来自企业管理的IAM模板,因为该配置文件带有企业管理的 标签。
-
单击分配。
如果任务失败,请点击“重试”。
创建新版本
如果您想对已提交或分配的可信个人资料模板进行修改,请创建一个新版本。 您可以基于最新版本创建新版本,也可以选择其他版本。
要创建受信任配置文件模板的新版本,请按照以下步骤操作:
-
在 IBM Cloud 控制台中,依次选择 “管理”>“访问(IAM)”>“模板”。
-
选择您信赖的个人资料模板。
-
点击新版本
。
-
选择您想要作为新版本基础的版本。
-
输入新的模板名称和描述,或保留您正在使用的模板。
输入新的模板名称将更新此版本和所有先前版本的模板名称。 模板描述会单独存储在每个版本中。
-
输入新的可信个人资料名称和描述,或保留您正在使用的名称和描述。
输入新的受信任配置文件名称后,在您分配新版本后,子账户中显示的先前受信任配置文件名称将被替换。
-
选择您想要在新版本中保留的对象。
- (可选)选择信任关系。
- (可选)选择访问。
-
单击创建。
-
对配置进行其他任何调整。
-
点击 “审核” 并提交新版本。 更多信息,请参阅“审核您可信的个人资料模板”。
要指定可信配置文件模板的新版本,请完成以下步骤:
- 在 IBM Cloud 控制台中,依次选择 “管理”>“访问(IAM)”>“模板”。
- 点击“可信资料”。
- 单击表格展开图标
您想要使用的模板。
- 选择当前分配给子账户的版本。
- 点击“任务”。
- 在您想要分配不同版本的账户或账户组分配上点击更新。
- 点击“选择版本”。
- 选择您要替换当前版本的版本。
- 单击更新。
- 对每个账户或账户组重复这些步骤,以便为其分配不同的版本。
您指定的新的模板版本将替换旧版本。 了解更多关于 分配新版本 的信息。
取消任务
您可以从分配了模板的一个或多个账户中删除模板分配。 如果模板无法正常工作,您可以尝试这样做。 当您从账户删除模板任务时,默认情况下会恢复模板的先前版本。 如果您删除的任务是模板的第一个版本或唯一版本,则子账户中的可信配置文件也会被删除。
要删除一项任务,请按照以下步骤操作:
- 在 IBM Cloud 控制台中,依次选择 “管理”>“访问(IAM)”>“模板”。
- 点击“可信配置文件”,选择您信任的配置文件模板。
- 点击更新任务。
- 要从一个或几个账户删除任务,请取消选择要删除模板任务的账户。
- 要从所有分配了模板的账户中删除分配,请点击取消全部分配。
使用CLI创建可信的个人资料模板
当您有许多子账户需要相同的可信资料时,请考虑使用可信资料模板。 例如,您的组织可能制定了内部标准,或者要求遵守行业法规。
要使用 CLI 创建受信任的配置文件模板,请按照以下步骤操作:
-
创建一个JSON文件,用于配置可信配置文件模板定义。 有关可在JSON文件中使用的属性的更多信息,请参阅 IAM Identity API。
以下示例JSON文件指定了企业账户的
account_id、模板的name和profile配置。 此可信资料适用于数据库管理员。 允许特定用户应用identities中定义的模板。还定义了rules,根据 SAML 的属性授予访问配置文件的权限。{ "account_id": "5bbe28be34524sdbdaa34d37d1f2294a", "name": "dbadmintemplate", "profile": { "name": "Profile for DB Admins", "description": "allows users to admin db instances", "identities": [ { "type": "user", "identifier": "IBMid-123456789", "accounts": [ "5bbe28be34524sdbdaa34d37d1f2294a" ] } ], "rules": [ { "type": "Profile", "realm_name": "${IDP_REALM_NAME}", "expiration": 43200, "conditions": [ { "claim": "group", "operator": "EQUALS", "value": "\"admins\"" } ] } ] }, "policy_template_references": [ { "id": "Policy Template-12345", "version": 1 } ] } -
使用
trusted-profile-template-create命令创建可信的个人资料模板,示例请求如下:ibmcloud iam trustedprofile-template-create dbadmintemplate --file /path/to/db_trusted-profile_template.json
使用CLI更新可信的个人资料模板
在提交之前,您可以随时更新可信的个人资料模板。 要更新特定版本的可信配置文件模板,请完成以下步骤:
-
使用新的可信配置文件模板定义更新您的JSON文件。 有关可在JSON文件中使用的属性的更多信息,请参阅 IAM Identity API。
{ "account_id": "5bbe28be34524sdbdaa34d37d1f2294a", "name": "DBAdministrator", "profile": { "name": "Profile for DB Admins", "description": "allows users to admin db instances", "identities": [ { "type": "user", "identifier": "IBMid-123456789", "accounts": [ "5bbe28be34524sdbdaa34d37d1f2294a" ] } ], "rules": [ { "type": "Profile", "realm_name": "${IDP_REALM_NAME}", "expiration": 43200, "conditions": [ { "claim": "group", "operator": "EQUALS", "value": "\"admins\"" } ] } ] }, "policy_template_references": [ { "id": "Policy Template-12345", "version": 1 } ] }
当您更新模板名称时,每个版本的名称也会随之更新。
{: note}
1. 要更新特定版本的可信配置文件模板,请使用 `trusted-profile-template-version-update` 命令,示例请求如下:
```bash {: codeblock}
ibmcloud iam trustedpprofile-template-version-update DBAdministrator 1 --file /path/to/db_trusted-profile_template.json
## 使用CLI提交可信的个人资料模板
{: #commit-trusted-profile-template-cli cli}
查看可信的个人资料模板并提交,以便无法对该版本进行进一步修改。 在将版本分配给子账户之前,必须先提交版本。 这样,模板分配管理员可以确保仅在您确认版本准备就绪时才分配该版本。
以下示例请求提交名为 `DBAdministrator` 的可信配置文件模板的版本 `1`:
```bash {: codeblock}
ibmcloud iam trusted-profile-template-version-commit DBAdministrator 1
## 使用CLI为子账户分配可信的配置文件模板
{: #assign-trusted-profile-template-cli cli}
将可信的个人资料模板分配给企业中的子账户。
您只能将IAM模板分配给子账户和账户组,而不能分配给企业账户。
{: note}
要为可信的个人资料模板创建任务,请完成以下步骤:
1. 列出您企业账户中的可信配置文件模板,并记录您要分配给子账户的可信配置文件模板的名称和版本号:
```bash {: codeblock}
ibmcloud iam trusted-profile-templates
1. 使用 `account-trusted profile-assignment-create` 命令将模板分配给 `Account` 或 `AccountGroup`。
ibmcloud iam trusted-profile-assignment-create DBAdministrator 1 AccountGroup 955fc2274567474f8da802d5c376504b
如果任务失败,请使用 `trusted-profile-assignment-update` 方法重试。
{: tip}
## 使用命令行界面(CLI)创建新版本
{: #new-version-trusted-profile-template cli}
如果您想对已提交或分配的可信个人资料模板进行修改,请创建一个新版本。
1. 使用新的可信配置文件模板定义更新您的JSON文件。 有关可在JSON文件中使用的属性的更多信息,请参阅 [IAM Identity API](/docs/apis/iam-identity-token-api#create-profile-template-version)。
1. 使用 `trusted-profile-template-version-create` 方法创建新版本。 以下示例请求创建了模板 `DBAdministrator` 的新版本。
ibmcloud iam trusted-profile-template-version-create DBAdministrator --file /path/to/db_trusted-profile_template.json
## 使用CLI更新任务
{: #update-assignment-trusted-profile-cli cli}
更新任务以迁移到新版本或重试失败的分配。
您指定的新的模板版本将替换旧版本。 了解更多关于 [分配新版本](/docs/enterprise-management?topic=enterprise-management-working-with-versions#new-version) 的信息。
{: note}
1. 列出您企业账户中的可信资料分配,并记下您要更新的分配的 `template_id`:
ibmcloud iam trusted-profile-assignments
1. 更新受信任配置文件的分配。 如果您要重试作业,请使用相同的版本号。 以下示例请求将任务 `ProfileTemplate-cac1b203-5956-4981-bdec-0a4af4feab4d` 迁移到版本2。
ibmcloud iam trusted-profile-assignment-update ProfileTemplate-cac1b203-5956-4981-bdec-0a4af4feab4d 2
## 使用CLI取消任务
{: #remove-assignment-trusted-profile-cli cli}
您可以从分配了模板的账户或账户组中删除模板分配。 如果模板无法正常工作,您可以尝试这样做。 当您从账户删除模板任务时,默认情况下会恢复模板的先前版本。 如果您删除的任务是模板的第一个版本或唯一版本,子账户中的企业托管可信配置文件也会被删除。
要删除一项任务,请按照以下步骤操作:
1. 使用 `account-trusted profile-assignments` 方法列出账户中的任务。 请将您要删除的任务记录在 `ASSIGNMENT_ID` 中。
1. 使用 `account-trusted profile-assigment-delete` 方法取消任务。 以下示例请求将删除任务 `AccountSettingsAssignment-63d65ed159ff463b8ec09ea77d22a05b`。
ibmcloud iam account-trusted profile-assignment-delete AccountSettingsAssignment-63d65ed159ff463b8ec09ea77d22a05b
## 使用CLI删除版本
{: #delete-trusted-profile-template-version-cli cli}
在删除受信任的配置文件模板版本之前,必须先删除该模板版本的所有分配。 请按照以下步骤删除特定版本:
1. 列出您企业账户中的可信个人资料模板,并记录您要删除的模板的名称和版本号:
ibmcloud iam account-trusted profile-templates
1. 删除版本:
ibmcloud iam account-trusted profile-template-delete AccountSettingsTemplateUpdated 2
1. 要删除所有版本,请重复上述步骤。 请确保您先移除每个版本的作业。
## 使用API创建可信的个人资料模板
{: #create-trusted-profile-template-api api}
当您有许多子账户需要相同的可信资料时,请考虑使用可信资料模板。 例如,您的组织可能制定了内部标准,或者要求遵守行业法规。
要使用API创建可信的个人资料模板,请完成以下步骤:
1. 配置可信配置文件模板定义。 有关可用属性的更多信息,请参阅 [IAM Identity API](/docs/apis/iam-identity-token-api#create-profile-template)。
以下示例指定了企业账户的 account_id、模板的 name 和 profile 配置。 此可信资料适用于数据库管理员。 允许特定用户应用 identities 中定义的模板。还定义了 rules,根据 SAML 的属性授予访问配置文件的权限。
{
"account_id": "5bbe28be34524sdbdaa34d37d1f2294a",
"name": "dbadmintemplate",
"profile": {
"name": "Profile for DB Admins",
"description": "allows users to admin db instances",
"identities": [
{
"type": "user",
"identifier": "IBMid-123456789",
"accounts": [
"5bbe28be34524sdbdaa34d37d1f2294a"
]
}
],
"rules": [
{
"type": "Profile",
"realm_name": "${IDP_REALM_NAME}",
"expiration": 43200,
"conditions": [
{
"claim": "group",
"operator": "EQUALS",
"value": "\"admins\""
}
]
}
]
},
"policy_template_references": [
{
"id": "Policy Template-12345",
"version": 1
}
]
}
ProfileClaimRuleConditions condition = new ProfileClaimRuleConditions.Builder()
.claim("blueGroups")
.operator("EQUALS")
.value("\"cloud-docs-dev\"")
.build();
List<ProfileClaimRuleConditions> conditions = new ArrayList<>();
conditions.add(condition);
TrustedProfileTemplateClaimRule claimRule = new TrustedProfileTemplateClaimRule.Builder()
.name("My Rule")
.realmName(realmName)
.type(claimRuleType)
.expiration(43200)
.conditions(conditions)
.build();
TemplateProfileComponentRequest profile = new TemplateProfileComponentRequest.Builder()
.addRules(claimRule)
.name(profileTemplateProfileName)
.description("Trusted profile created from a template")
.build();
CreateProfileTemplateOptions createProfileTemplateOptions = new CreateProfileTemplateOptions.Builder()
.name(profileTemplateName)
.description("IAM enterprise trusted profile template example")
.accountId(enterpriseAccountId)
.profile(profile)
.build();
Response<TrustedProfileTemplateResponse> response = service.createProfileTemplate(createProfileTemplateOptions).execute();
TrustedProfileTemplateResponse trustedProfileTemplateResult = response.getResult();
// Save the id for use by other test methods.
profileTemplateId = trustedProfileTemplateResult.getId();
profileTemplateVersion = trustedProfileTemplateResult.getVersion().longValue();
System.out.println(trustedProfileTemplateResult);
```
```javascript {: javascript codeblock}
const condition = {
claim: "blueGroups",
operator: "EQUALS",
value: "\"cloud-docs-dev\"",
}
const claimRule = {
name: "My Rule",
realm_name: realmName,
type: 'Profile-SAML',
expiration: 43200,
conditions: [condition],
}
const profile = {
rules: [claimRule],
name: "Profile-From-Example-Template",
description: "Trusted profile created from a template",
}
const templateParams = {
name: "Example-Profile-Template",
description: "IAM enterprise trusted profile template example",
accountId: enterpriseAccountId,
profile: profile,
}
try {
const res = await iamIdentityService.createProfileTemplate(templateParams);
profileTemplateEtag = res.headers.etag;
const { result } = res;
profileTemplateId = result.id;
profileTemplateVersion = result.version;
console.log(JSON.stringify(result, null, 2));
} catch (err) {
console.warn(err);
}
```
```python {: python codeblock}
profile_claim_rule_conditions = {}
profile_claim_rule_conditions['claim'] = 'blueGroups'
profile_claim_rule_conditions['operator'] = 'EQUALS'
profile_claim_rule_conditions['value'] = '\"cloud-docs-dev\"'
profile_claim_rule = {}
profile_claim_rule['name'] = 'My Rule'
profile_claim_rule['realm_name'] = 'https://sdk.test.realm/1234'
profile_claim_rule['type'] = 'Profile-SAML'
profile_claim_rule['expiration'] = 43200
profile_claim_rule['conditions'] = [profile_claim_rule_conditions]
profile = {}
profile['name'] = 'Profile-From-Example-Template'
profile['description'] = 'Trusted profile created from a template'
profile['rules'] = [profile_claim_rule]
create_response = iam_identity_service.create_profile_template(
name='Example-Profile-Template',
description='IAM enterprise trusted profile template example',
account_id=enterprise_account_id,
profile=profile,
)
profile_template = create_response.get_result()
print('\ncreate_profile_template() response: ', json.dumps(profile_template, indent=2))
global profile_template_id
profile_template_id = profile_template['id']
global profile_template_version
profile_template_version = profile_template['version']
```
```go {: go codeblock}
profileClaimRuleConditions := new(iamidentityv1.ProfileClaimRuleConditions)
profileClaimRuleConditions.Claim = core.StringPtr("blueGroups")
profileClaimRuleConditions.Operator = core.StringPtr("EQUALS")
profileClaimRuleConditions.Value = core.StringPtr("\"cloud-docs-dev\"")
profileTemplateClaimRule := new(iamidentityv1.TrustedProfileTemplateClaimRule)
profileTemplateClaimRule.Name = core.StringPtr("My Rule")
profileTemplateClaimRule.RealmName = &realmName
profileTemplateClaimRule.Type = &claimRuleType
profileTemplateClaimRule.Expiration = core.Int64Ptr(int64(43200))
profileTemplateClaimRule.Conditions = []iamidentityv1.ProfileClaimRuleConditions{*profileClaimRuleConditions}
profile := new(iamidentityv1.TemplateProfileComponentRequest)
profile.Name = &profileTemplateProfileName
profile.Description = core.StringPtr("Example Profile created from Profile Template")
profile.Rules = []iamidentityv1.TrustedProfileTemplateClaimRule{*profileTemplateClaimRule}
createOptions := &iamidentityv1.CreateProfileTemplateOptions{
Name: &profileTemplateName,
Description: core.StringPtr("Example Profile Template"),
AccountID: &enterpriseAccountID,
Profile: profile,
}
createResponse, response, err := iamIdentityService.CreateProfileTemplate(createOptions)
b, _ := json.MarshalIndent(createResponse, "", " ")
fmt.Println(string(b))
// Grab the ID and Etag value from the response for use in the update operation
profileTemplateId = *createResponse.ID
profileTemplateVersion = *createResponse.Version
profileTemplateEtag = response.GetHeaders().Get("Etag")
```
保存响应中的 ProfileTemplate ID和entity_tag值,以便在更新操作中使用。
{ tip}
## 使用API更新可信的个人资料模板
{: #update-trusted-profile-template-api api}
在提交之前,您可以随时更新可信的个人资料模板。 有关可在JSON文件中使用的属性的更多信息,请参阅 [IAM Identity API](/docs/apis/iam-identity-token-api#update-profile-template-version)。 要更新特定版本的可信配置文件模板,请完成以下步骤:
1. 列出您企业帐户中可信任的配置文件模板,并记下您要更新的模板版本的响应中的 `ProfileTemplate` ID和ETag。
```bash {: curl codeblock}
curl -X GET 'https://iam.cloud.ibm.com/v1/profile_templates?account_id=5bbe28be34524sdbdaa34d37d1f2294a' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
ListProfileTemplatesOptions listOptions = new ListProfileTemplatesOptions.Builder()
.accountId(enterpriseAccountId)
.build();
Response<TrustedProfileTemplateList> response = service.listProfileTemplates(listOptions).execute();
TrustedProfileTemplateList listResult = response.getResult();
System.out.println(listResult);
const params = {
accountId: enterpriseAccountId,
}
try {
const res = await iamIdentityService.listProfileTemplates(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}
list_response = iam_identity_service.list_profile_templates(account_id=enterprise_account_id)
profile_template_list = list_response.get_result()
print('\nlist_profile_templates response: ', json.dumps(profile_template_list, indent=2))
listOptions := &iamidentityv1.ListProfileTemplatesOptions{
AccountID: &enterpriseAccountID,
}
listResponse, response, err := iamIdentityService.ListProfileTemplates(listOptions)
b, _ := json.MarshalIndent(listResponse, "", " ")
fmt.Println(string(b))
1. 更新可信个人资料模板定义。
```bash {: curl codeblock}
curl -X PUT 'https://iam.cloud.ibm.com/v1/profile_templates/{template_id}/versions/{version}' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN' -d '{ "account_id": "5bbe28be34524sdbdaa34d37d1f2294a", "name": "db admin template", "profile": { "name": "Profile for DB Admins", "description": "allows users to admin db instances", "rules": [ { "type": "Profile", "realm_name": "${IDP_REALM_NAME}", "expiration": 43200, "conditions": [ { "claim": "name", "operator": "EQUALS", "value": ""My Name"" } ] } ] }, "policy_template_references": [ { "id": "Policy Template-12345", "version": 1 } ] }'
```java {: java codeblock}
UpdateProfileTemplateVersionOptions updateOptions = new UpdateProfileTemplateVersionOptions.Builder()
.accountId(enterpriseAccountId)
.templateId(profileTemplateId)
.version(Long.toString(profileTemplateVersion))
.ifMatch(profileTemplateEtag)
.name(profileTemplateName)
.description("IAM enterprise trusted profile template example - updated")
.build();
Response<TrustedProfileTemplateResponse> updateResponse = service.updateProfileTemplateVersion(updateOptions).execute();
TrustedProfileTemplateResponse updateResult = updateResponse.getResult();
// Grab the Etag value from the response for use in the update operation.
profileTemplateEtag = updateResponse.getHeaders().values("Etag").get(0);
System.out.println(updateResult);
const params = {
accountId: enterpriseAccountId,
templateId: profileTemplateId,
version: profileTemplateVersion,
ifMatch: profileTemplateEtag,
name: "Example-Profile-Template",
description: "IAM enterprise trusted profile template example - updated",
}
try {
const res = await iamIdentityService.updateProfileTemplateVersion(params);
profileTemplateEtag = res.headers.etag;
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}
{
"id": "ProfileTemplate-767fc1f6-c77c-4196-b3d6-a009a5a536e9",
"version": 1,
"account_id": "5bbe28be34524sdbdaa34d37d1f2294a",
"name": "db admin template",
"committed": false,
"profile": {
"name": "Profile for DB Admins",
"description": "allows users to admin db instances",
"rules": [
{
"type": "Profile-SAML",
"realm_name": "${IDP_REALM_NAME}",
"expiration": 43200,
"conditions": [
{
"claim": "name",
"operator": "EQUALS",
"value": "\"My Name\""
}
]
}
]
},
"policy_template_references": [
{
"id": "Policy Template-12345",
"version": "1"
}
],
"created_at": "2023-03-07T13:55:33:428+0000",
"created_by_id": "IBMid-12345678901",
"last_modified_at": "2023-03-07T13:55:33:428+0000",
"last_modified_by_id": "IBMid-12345678901",
"entity_tag": "1-2da85a8f1172fc3527378318d3182778",
"crn": "crn:v1:staging:public:iam-identity::a/5bbe28be34524sdbdaa34d37d1f2294a::template:ProfileTemplate-767fc1f6-c77c-4196-b3d6-a009a5a536e9"
}
{
"id": "ProfileTemplate-767fc1f6-c77c-4196-b3d6-a009a5a536e9",
"version": 1,
"account_id": "5bbe28be34524sdbdaa34d37d1f2294a",
"name": "db admin template",
"committed": false,
"profile": {
"name": "Profile for DB Admins",
"description": "allows users to admin db instances",
"rules": [
{
"type": "Profile-SAML",
"realm_name": "${IDP_REALM_NAME}",
"expiration": 43200,
"conditions": [
{
"claim": "name",
"operator": "EQUALS",
"value": "\"My Name\""
}
]
}
]
},
"policy_template_references": [
{
"id": "Policy Template-12345",
"version": "1"
}
],
"created_at": "2023-03-07T13:55:33:428+0000",
"created_by_id": "IBMid-12345678901",
"last_modified_at": "2023-03-07T13:55:33:428+0000",
"last_modified_by_id": "IBMid-12345678901",
"entity_tag": "1-2da85a8f1172fc3527378318d3182778",
"crn": "crn:v1:staging:public:iam-identity::a/5bbe28be34524sdbdaa34d37d1f2294a::template:ProfileTemplate-767fc1f6-c77c-4196-b3d6-a009a5a536e9"
}
当您更新模板名称时,每个版本的名称也会随之更新。
使用API提交可信的个人资料模板
查看可信的个人资料模板并提交,这样你就不能再对版本进行任何修改了。 在将版本分配给子账户之前,必须先提交版本。 这样,模板分配管理员可以确保仅在您确认版本准备就绪时才进行分配。
- 获取您要查看并提交的可信个人资料模板的版本。
curl -X GET 'https://iam.cloud.ibm.com/v1/profile_templates/{template_id}/versions/{version}' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
GetProfileTemplateVersionOptions getProfileTemplateOptions = new GetProfileTemplateVersionOptions.Builder()
.templateId(profileTemplateId)
.version(Long.toString(profileTemplateVersion))
.build();
Response<TrustedProfileTemplateResponse> response = service.getProfileTemplateVersion(getProfileTemplateOptions).execute();
TrustedProfileTemplateResponse profileTemplateResult = response.getResult();
profileTemplateEtag = response.getHeaders().values("Etag").get(0);
System.out.println(profileTemplateResult);
const params = {
templateId: profileTemplateId,
version: profileTemplateVersion,
}
try {
const res = await iamIdentityService.getProfileTemplateVersion(params);
profileTemplateEtag = res.headers.etag;
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}
get_response = iam_identity_service.get_profile_template_version(
template_id=profile_template_id, version=str(profile_template_version)
)
profile_template = get_response.get_result()
print('\nget_profile_template response: ', json.dumps(profile_template, indent=2))
global profile_template_etag
profile_template_etag = get_response.get_headers()['Etag']
profile_template_etag is not None
getOptions := &iamidentityv1.GetProfileTemplateVersionOptions{
TemplateID: &profileTemplateId,
Version: core.StringPtr(strconv.FormatInt(profileTemplateVersion, 10)),
}
getResponse, response, err := iamIdentityService.GetProfileTemplateVersion(getOptions)
b, _ := json.MarshalIndent(getResponse, "", " ")
fmt.Println(string(b))
profileTemplateEtag = response.GetHeaders().Get("Etag")
- 查看回复,确认是否已准备好提交。
- 提交可信配置文件模板的版本。
curl -X POST 'https://iam.cloud.ibm.com/v1/profile_templates/{template_id}/{version}/commit' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
CommitProfileTemplateOptions commitOptions = new CommitProfileTemplateOptions.Builder()
.templateId(profileTemplateId)
.version(Long.toString(profileTemplateVersion))
.build();
Response<Void> commitResponse = service.commitProfileTemplate(commitOptions).execute();
const commitParams = {
templateId: profileTemplateId,
version: profileTemplateVersion,
}
try {
const res = await iamIdentityService.commitProfileTemplate(commitParams);
} catch (err) {
console.warn(err);
}
commit_response = iam_identity_service.commit_profile_template(
template_id=profile_template_id, version=str(profile_template_version)
)
commitOptions := &iamidentityv1.CommitProfileTemplateOptions{
TemplateID: &profileTemplateId,
Version: core.StringPtr(strconv.FormatInt(profileTemplateVersion, 10)),
}
response, err := iamIdentityService.CommitProfileTemplate(commitOptions)
通过使用API为子账户分配可信的个人资料模板
将可信的个人资料模板分配给企业中的子账户。
您只能将IAM模板分配给子账户和账户组,而不能分配给企业账户。
要为可信的个人资料模板创建任务,请完成以下步骤:
- 列出您企业帐户中可信任的个人资料模板,并记下您要分配的模板版本的响应中的
ProfileTemplateID和版本。
curl -X GET 'https://iam.cloud.ibm.com/v1/profile_templates?account_id=5bbe28be34524sdbdaa34d37d1f2294a' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
ListProfileTemplatesOptions listOptions = new ListProfileTemplatesOptions.Builder()
.accountId(enterpriseAccountId)
.build();
Response<TrustedProfileTemplateList> response = service.listProfileTemplates(listOptions).execute();
TrustedProfileTemplateList listResult = response.getResult();
System.out.println(listResult);
const params = {
accountId: enterpriseAccountId,
}
try {
const res = await iamIdentityService.listProfileTemplates(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}
list_response = iam_identity_service.list_profile_templates(account_id=enterprise_account_id)
profile_template_list = list_response.get_result()
print('\nlist_profile_templates response: ', json.dumps(profile_template_list, indent=2))
listOptions := &iamidentityv1.ListProfileTemplatesOptions{
AccountID: &enterpriseAccountID,
}
listResponse, response, err := iamIdentityService.ListProfileTemplates(listOptions)
b, _ := json.MarshalIndent(listResponse, "", " ")
fmt.Println(string(b))
ibmcloud iam trusted-profile-templates
- 将模板分配给
Account或AccountGroup。
curl -X POST 'https://iam.cloud.ibm.com/v1/profile_assignments' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN' -d '{
"template_id": "ProfileTemplate-cac1b203-5956-4981-bdec-0a4af4feab4d",
"template_version": 1,
"target_type": "Account",
"target": "5bbe28be34524e88a34d37d1f2294a8a"
}'
CreateTrustedProfileAssignmentOptions assignOptions = new CreateTrustedProfileAssignmentOptions.Builder()
.templateId(profileTemplateId)
.templateVersion(profileTemplateVersion)
.targetType("Account")
.target(enterpriseSubAccountId)
.build();
Response<TemplateAssignmentResponse> assignResponse = service.createTrustedProfileAssignment(assignOptions).execute();
TemplateAssignmentResponse assignmentResponseResult = assignResponse.getResult();
// Save the id for use by other test methods.
profileTemplateAssignmentId = assignmentResponseResult.getId();
// Grab the Etag value from the response for use in the update operation.
profileTemplateAssignmentEtag = assignResponse.getHeaders().values("Etag").get(0);
System.out.println(assignmentResponseResult);
const assignParams = {
templateId: profileTemplateId,
templateVersion: profileTemplateVersion,
targetType: "Account",
target: enterpriseSubAccountId,
}
try {
const assRes = await iamIdentityService.createTrustedProfileAssignment(assignParams);
const { result } = assRes;
profileTemplateAssignmentId = result.id;
profileTemplateAssignmentEtag= assRes.headers.etag;
console.log(JSON.stringify(result, null, 2));
} catch (err) {
console.warn(err);
}
assign_response = iam_identity_service.create_trusted_profile_assignment(
template_id=profile_template_id,
template_version=profile_template_version,
target_type='Account',
target=enterprise_subaccount_id,
)
assignment = assign_response.get_result()
print('\ncreate_trusted_profile_assignment() response: ', json.dumps(assignment, indent=2))
global profile_template_assignment_id
profile_template_assignment_id = assignment['id']
global profile_template_assignment_etag
profile_template_assignment_etag = assign_response.get_headers()['Etag']
assignOptions := &iamidentityv1.CreateTrustedProfileAssignmentOptions{
TemplateID: &profileTemplateId,
TemplateVersion: &profileTemplateVersion,
TargetType: core.StringPtr("Account"),
Target: &enterpriseSubAccountID,
}
assignResponse, response, err := iamIdentityService.CreateTrustedProfileAssignment(assignOptions)
b, _ := json.MarshalIndent(assignResponse, "", " ")
fmt.Println(string(b))
// Grab the Etag and id for use by other test methods.
profileTemplateAssignmentEtag = response.GetHeaders().Get("Etag")
profileTemplateAssignmentId = *assignResponse.ID
如果任务失败,请使用 更新任务操作 重试。
使用 API 创建新版本
如果您想对已提交或分配的可信个人资料模板进行修改,请创建一个新版本。
curl -X POST 'https://iam.cloud.ibm.com/v1/profile_templates/{template_id}/versions/' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN' -d '{
"account_id": "5bbe28be34524sdbdaa34d37d1f2294a",
"name": "db admin template",
"profile": {
"name": "Profile for DB Admins",
"description": "allows users to admin db instances",
"rules": [
{
"type": "Profile",
"realm_name": "${IDP_REALM_NAME}",
"expiration": 43200,
"conditions": [
{
"claim": "name",
"operator": "EQUALS",
"value": "\"My Name\""
}
]
}
]
},
"policy_template_references": [
{
"id": "Policy Template-12345",
"version": 1
}
]
}'
ProfileClaimRuleConditions condition = new ProfileClaimRuleConditions.Builder()
.claim("blueGroups")
.operator("EQUALS")
.value("\"cloud-docs-dev\"")
.build();
List<ProfileClaimRuleConditions> conditions = new ArrayList<>();
conditions.add(condition);
TrustedProfileTemplateClaimRule claimRule = new TrustedProfileTemplateClaimRule.Builder()
.name("My Rule")
.realmName(realmName)
.type(claimRuleType)
.expiration(43200)
.conditions(conditions)
.build();
List<String> accounts = new ArrayList<String>();
accounts.add(enterpriseAccountId);
ProfileIdentityRequest profileIdentity = new ProfileIdentityRequest.Builder()
.identifier(iamId)
.accounts(accounts)
.type("user")
.description("Identity description")
.build();
List<ProfileIdentityRequest> identities = new ArrayList<ProfileIdentityRequest>();
identities.add(profileIdentity);
TemplateProfileComponentRequest profile = new TemplateProfileComponentRequest.Builder()
.addRules(claimRule)
.name(profileTemplateProfileName)
.description("Trusted profile created from a template - new version")
.identities(identities)
.build();
CreateProfileTemplateVersionOptions createOptions = new CreateProfileTemplateVersionOptions.Builder()
.accountId(enterpriseAccountId)
.templateId(profileTemplateId)
.name(profileTemplateName)
.description("IAM enterprise trusted profile template example - new version")
.profile(profile)
.build();
Response<TrustedProfileTemplateResponse> createResponse = service.createProfileTemplateVersion(createOptions).execute();
TrustedProfileTemplateResponse createResult = createResponse.getResult();
// Save the version for use by other test methods.
profileTemplateVersion = createResult.getVersion().longValue();
System.out.println(createResult);
const condition = {
claim: "blueGroups",
operator: "EQUALS",
value: "\"cloud-docs-dev\"",
}
const claimRule = {
name: "My Rule",
realm_name: realmName,
type: 'Profile-SAML',
expiration: 43200,
conditions: [condition],
}
const identity = {
identifier: iamId,
accounts: [enterpriseAccountId],
type: "user",
description: "Identity description",
}
const profile = {
rules: [claimRule],
name: "Profile-From-Example-Template",
description: "Trusted profile created from a template - new version",
identities: [identity],
}
const templateParams = {
templateId: profileTemplateId,
name: "Example-Profile-Template",
description: "IAM enterprise trusted profile template example - new version",
accountId: enterpriseAccountId,
profile: profile,
}
try {
const res = await iamIdentityService.createProfileTemplateVersion(templateParams);
const { result } = res;
profileTemplateVersion = result.version;
console.log(JSON.stringify(result, null, 2));
} catch (err) {
console.warn(err);
}
profile_claim_rule_conditions = {}
profile_claim_rule_conditions['claim'] = 'blueGroups'
profile_claim_rule_conditions['operator'] = 'EQUALS'
profile_claim_rule_conditions['value'] = '\"cloud-docs-dev\"'
profile_claim_rule = {}
profile_claim_rule['name'] = 'My Rule'
profile_claim_rule['realm_name'] = 'https://sdk.test.realm/1234'
profile_claim_rule['type'] = 'Profile-SAML'
profile_claim_rule['expiration'] = 43200
profile_claim_rule['conditions'] = [profile_claim_rule_conditions]
profile_identity = {}
profile_identity['identifier'] = iam_id
profile_identity['accounts'] = [enterprise_account_id]
profile_identity['type'] = 'user'
profile_identity['description'] = 'Identity description'
profile = {}
profile['name'] = 'Profile-From-Example-Template'
profile['description'] = 'Trusted profile created from a template - new version'
profile['rules'] = [profile_claim_rule]
profile['identities'] = [profile_identity]
create_response = iam_identity_service.create_profile_template_version(
template_id=profile_template_id,
name='Example-Profile-Template',
description='IAM enterprise trusted profile template example - new version',
account_id=enterprise_account_id,
profile=profile,
)
profile_template = create_response.get_result()
print('\ncreate_profile_template_version() response: ', json.dumps(profile_template, indent=2))
global profile_template_version
profile_template_version = profile_template['version']
profileClaimRuleConditions := new(iamidentityv1.ProfileClaimRuleConditions)
profileClaimRuleConditions.Claim = core.StringPtr("blueGroups")
profileClaimRuleConditions.Operator = core.StringPtr("EQUALS")
profileClaimRuleConditions.Value = core.StringPtr("\"cloud-docs-dev\"")
profileTemplateClaimRule := new(iamidentityv1.TrustedProfileTemplateClaimRule)
profileTemplateClaimRule.Name = core.StringPtr("My Rule")
profileTemplateClaimRule.RealmName = &realmName
profileTemplateClaimRule.Type = &claimRuleType
profileTemplateClaimRule.Expiration = core.Int64Ptr(int64(43200))
profileTemplateClaimRule.Conditions = []iamidentityv1.ProfileClaimRuleConditions{*profileClaimRuleConditions}
profile := new(iamidentityv1.TemplateProfileComponentRequest)
profile.Name = &profileTemplateProfileName
profile.Description = core.StringPtr("Example Profile created from Profile Template - new version")
profile.Rules = []iamidentityv1.TrustedProfileTemplateClaimRule{*profileTemplateClaimRule}
createOptions := &iamidentityv1.CreateProfileTemplateVersionOptions{
Name: &profileTemplateName,
Description: core.StringPtr("Example Profile Template - new version"),
AccountID: &enterpriseAccountID,
TemplateID: &profileTemplateId,
Profile: profile,
}
createResponse, response, err := iamIdentityService.CreateProfileTemplateVersion(createOptions)
b, _ := json.MarshalIndent(createResponse, "", " ")
fmt.Println(string(b))
// save the new version to be used in subsequent calls
profileTemplateVersion = *createResponse.Version
使用API更新任务
更新任务以迁移到新版本或重试失败的分配。
您指定的新的模板版本将替换旧版本。 了解更多关于 分配新版本 的信息。
- 列出您企业账户中的可信配置文件分配,并记录您要更新的分配的
TemplateAssignmentID和版本:
curl -X GET 'https://iam.cloud.ibm.com/v1/profile_assignments?account_id=5bbe28be34524sdbdaa34d37d1f2294a' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
ListTrustedProfileAssignmentsOptions listOptions = new ListTrustedProfileAssignmentsOptions.Builder()
.accountId(enterpriseAccountId)
.templateId(profileTemplateId)
.build();
Response<TemplateAssignmentListResponse> listResponse = service.listTrustedProfileAssignments(listOptions).execute();
TemplateAssignmentListResponse listResult = listResponse.getResult();
System.out.println(listResult);
const params = {
accountId: enterpriseAccountId,
templateId: profileTemplateId,
}
try {
const res = await iamIdentityService.listTrustedProfileAssignments(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}
list_response = iam_identity_service.list_trusted_profile_assignments(
account_id=enterprise_account_id, template_id=profile_template_id
)
assignment_list = list_response.get_result()
print('\nlist_trusted_profile_assignments() response: ', json.dumps(assignment_list, indent=2))
listOptions := &iamidentityv1.ListTrustedProfileAssignmentsOptions{
AccountID: &enterpriseAccountID,
TemplateID: &profileTemplateId,
}
listResponse, response, err := iamIdentityService.ListTrustedProfileAssignments(listOptions)
b, _ := json.MarshalIndent(listResponse, "", " ")
fmt.Println(string(b))
- 更新受信任配置文件的分配。 如果您要重试作业,请使用相同的版本号。 以下示例请求将任务迁移到版本2。
curl -X PATCH 'https://iam.cloud.ibm.com/v1/profile_assignments/<assignment_id>' -H 'Authorization: Bearer $TOKEN' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN' -d '{
"template_version": 2
}'
UpdateTrustedProfileAssignmentOptions updateOptions = new UpdateTrustedProfileAssignmentOptions.Builder()
.assignmentId(profileTemplateAssignmentId)
.templateVersion(profileTemplateVersion)
.ifMatch(profileTemplateAssignmentEtag)
.build();
Response<TemplateAssignmentResponse> updateResponse = service.updateTrustedProfileAssignment(updateOptions).execute();
TemplateAssignmentResponse updateResult = updateResponse.getResult();
// Grab the Etag value from the response for use in the update operation.
profileTemplateAssignmentEtag = updateResponse.getHeaders().values("Etag").get(0);
System.out.println(updateResult);
const assignParams = {
assignmentId: profileTemplateAssignmentId,
templateVersion: profileTemplateVersion,
ifMatch: profileTemplateAssignmentEtag,
}
try {
const assRes = await iamIdentityService.updateTrustedProfileAssignment(assignParams);
console.log(JSON.stringify(assRes.result, null, 2));
} catch (err) {
console.warn(err);
}
assign_response = iam_identity_service.update_trusted_profile_assignment(
assignment_id=profile_template_assignment_id,
template_version=profile_template_version,
if_match=profile_template_assignment_etag,
)
assignment = assign_response.get_result()
print('\nupdate_profile_template_assignment response: ', json.dumps(assignment, indent=2))
profile_template_assignment_etag = assign_response.get_headers()['Etag']
updateOptions := &iamidentityv1.UpdateTrustedProfileAssignmentOptions{
AssignmentID: &profileTemplateAssignmentId,
TemplateVersion: &profileTemplateVersion,
IfMatch: &profileTemplateAssignmentEtag,
}
updateResponse, response, err := iamIdentityService.UpdateTrustedProfileAssignment(updateOptions)
b, _ := json.MarshalIndent(updateResponse, "", " ")
fmt.Println(string(b))
// Grab the Etag and id for use by other test methods.
profileTemplateAssignmentEtag = response.GetHeaders().Get("Etag")
使用API取消任务
您可以从分配了模板的账户或账户组中删除模板分配。 如果模板无法正常工作或不再需要,您可以尝试删除。 当您从账户删除模板分配时,如果存在旧版本模板,则默认将其恢复。 如果您删除的任务是模板的第一个版本或唯一版本,则子账户中的企业托管可信配置文件也会被删除。
要删除一项任务,请按照以下步骤操作:
- 列出您企业账户中的可信资料分配,并记下您要删除的分配的
TemplateAssignmentID。
curl -X GET 'https://iam.cloud.ibm.com/v1/profile_assignments?account_id=5bbe28be34524sdbdaa34d37d1f2294a' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
ListTrustedProfileAssignmentsOptions listOptions = new ListTrustedProfileAssignmentsOptions.Builder()
.accountId(enterpriseAccountId)
.templateId(profileTemplateId)
.build();
Response<TemplateAssignmentListResponse> listResponse = service.listTrustedProfileAssignments(listOptions).execute();
TemplateAssignmentListResponse listResult = listResponse.getResult();
System.out.println(listResult);
const params = {
accountId: enterpriseAccountId,
templateId: profileTemplateId,
}
try {
const res = await iamIdentityService.listTrustedProfileAssignments(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}
list_response = iam_identity_service.list_trusted_profile_assignments(
account_id=enterprise_account_id, template_id=profile_template_id
)
assignment_list = list_response.get_result()
print('\nlist_trusted_profile_assignments() response: ', json.dumps(assignment_list, indent=2))
listOptions := &iamidentityv1.ListTrustedProfileAssignmentsOptions{
AccountID: &enterpriseAccountID,
TemplateID: &profileTemplateId,
}
listResponse, response, err := iamIdentityService.ListTrustedProfileAssignments(listOptions)
b, _ := json.MarshalIndent(listResponse, "", " ")
fmt.Println(string(b))
- 取消任务。
删除任务可能会导致之前的任务变为活动状态。 更多信息,请参阅 使用模板版本。
curl -X DELETE 'https://iam.cloud.ibm.com/v1/profile_assignments/<assignment_id>' -H 'Authorization: Bearer $TOKEN' }'
DeleteTrustedProfileAssignmentOptions deleteOptions = new DeleteTrustedProfileAssignmentOptions.Builder()
.assignmentId(profileTemplateAssignmentId)
.build();
Response<ExceptionResponse> deleteResponse = service.deleteTrustedProfileAssignment(deleteOptions).execute();
const params = {
assignmentId: profileTemplateAssignmentId,
}
try {
const res = await iamIdentityService.deleteTrustedProfileAssignment(params);
} catch (err) {
console.warn(err);
}
delete_response = iam_identity_service.delete_trusted_profile_assignment(
assignment_id=profile_template_assignment_id
)
deleteOptions := &iamidentityv1.DeleteTrustedProfileAssignmentOptions{
AssignmentID: &profileTemplateAssignmentId,
}
excResponse, response, err := iamIdentityService.DeleteTrustedProfileAssignment(deleteOptions)
使用 API 删除版本
在删除受信任的配置文件模板版本之前,必须先删除该模板版本的所有分配。 请按照以下步骤删除特定版本:
- 列出您企业账户中的可信个人资料模板,并记下您要删除的模板版本的响应中的
ProfileTemplateID和版本。
curl -X GET 'https://iam.cloud.ibm.com/v1/profile_templates?account_id=5bbe28be34524sdbdaa34d37d1f2294a' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
ListProfileTemplatesOptions listOptions = new ListProfileTemplatesOptions.Builder()
.accountId(enterpriseAccountId)
.build();
Response<TrustedProfileTemplateList> response = service.listProfileTemplates(listOptions).execute();
TrustedProfileTemplateList listResult = response.getResult();
System.out.println(listResult);
const params = {
accountId: enterpriseAccountId,
}
try {
const res = await iamIdentityService.listProfileTemplates(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}
list_response = iam_identity_service.list_profile_templates(account_id=enterprise_account_id)
profile_template_list = list_response.get_result()
print('\nlist_profile_templates response: ', json.dumps(profile_template_list, indent=2))
listOptions := &iamidentityv1.ListProfileTemplatesOptions{
AccountID: &enterpriseAccountID,
}
listResponse, response, err := iamIdentityService.ListProfileTemplates(listOptions)
b, _ := json.MarshalIndent(listResponse, "", " ")
fmt.Println(string(b))
- 删除版本:
curl -X DELETE 'https://iam.cloud.ibm.com/v1/profile_templates/{template_id}/versions/{version}' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
DeleteProfileTemplateVersionOptions deleteOptions = new DeleteProfileTemplateVersionOptions.Builder()
.templateId(profileTemplateId)
.version("1")
.build();
Response<Void> deleteResponse = service.deleteProfileTemplateVersion(deleteOptions).execute();
const params = {
templateId: profileTemplateId,
version: 1,
}
try {
const res = await iamIdentityService.deleteProfileTemplateVersion(params);
} catch (err) {
console.warn(err);
}
delete_response = iam_identity_service.delete_profile_template_version(
template_id=profile_template_id, version='1'
)
deleteOptions := &iamidentityv1.DeleteProfileTemplateVersionOptions{
TemplateID: &profileTemplateId,
Version: core.StringPtr("1"),
}
response, err := iamIdentityService.DeleteProfileTemplateVersion(deleteOptions)
使用API删除所有版本
请确保您先移除每个版本的作业。
curl -X DELETE 'https://iam.cloud.ibm.com/v1/profile_templates/ProfileTemplate-767fc1f6-c77c-4196-b3d6-a009a5a536e9' -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN'
DeleteAllVersionsOfProfileTemplateOptions deleteTeplateOptions = new DeleteAllVersionsOfProfileTemplateOptions.Builder()
.templateId(profileTemplateId)
.build();
Response<Void> deleteResponse = service.deleteAllVersionsOfProfileTemplate(deleteTeplateOptions).execute();
const params = {
templateId: profileTemplateId,
}
try {
const res = await iamIdentityService.deleteAllVersionsOfProfileTemplate(params);
} catch (err) {
console.warn(err);
}
delete_response = iam_identity_service.delete_all_versions_of_profile_template(
template_id=profile_template_id
)
deleteOptions := &iamidentityv1.DeleteAllVersionsOfProfileTemplateOptions{
TemplateID: &profileTemplateId,
}
response, err := iamIdentityService.DeleteAllVersionsOfProfileTemplate(deleteOptions)