授與使用者對標籤資源及服務 ID 的存取權
身為帳戶擁有者,您可能想要委託一些標記資源和服務 ID 的責任。 若要讓使用者將標籤附加至資源或服務 ID,您必須授與他們適當的存取權。 使用 IBM Cloud® Identity and Access Management (IAM) 存取原則,授與使用者對資源群組中資源的存取權。
標籤在整個帳戶中可見,可跨地理區域抄寫。 因為標籤不是管制資訊,所以請避免建立使用個人資訊 (例如您的姓名、地址、電話號碼、電子郵件位址或其他識別或專有資訊) 的標籤。
標記許可權
帳戶中的任何使用者都可以檢視標籤。 標記資源時,對該資源具有 read 存取權的所有使用者都可以檢視該標籤。 若要連接或分離資源或服務 ID 上的標籤,視資源類型及標籤類型而定,需要特定的存取角色或許可權。 請參閱下表,瞭解每種資源類型需要什麼角色。
| 資源類型 | 角色 |
|---|---|
| 已啟用 IAM | 若要連接或分離資源上的使用者標籤、編輯者或管理者 若要連接或分離存取權管理標籤,資源上的管理者 若要檢視已連接存取權管理標籤之資源上的已指派原則,「檢視者」角色 |
| 標準基礎架構上的裸機 | 檢視硬體詳細資料並存取一組特定的服務或所有裸機伺服器 |
| 標準基礎架構上的專用主機 | 檢視虛擬專用主機詳細資料,以及對一組特定服務或所有專用主機的存取權 |
| 標準基礎架構上的虛擬伺服器 | 檢視虛擬伺服器詳細資料,以及對一組特定服務或所有虛擬伺服器的存取權 |
| 標準基礎架構上的 Cloud Object Storage S3 | 儲存空間管理許可權 |
| 標準基礎架構上的 File Storage | 儲存空間管理許可權 |
| 標準基礎架構上的 Evault 備份 | 儲存空間管理許可權 |
| 標準基礎架構上的 Content Delivery Network | 管理 CDN 帳戶許可權 |
| 標準基礎架構上的 Direct Link | 帳戶成員 |
| Hardware Firewall | 管理防火牆 |
| FortiGate Security Appliance | 管理防火牆 |
| IBM Cloud Load Balancer | 管理負載平衡器 |
| Gateway Appliance | 管理網路閘道 |
| 服務 ID | 若要連接或分離使用者標籤, IAM 身分服務上的編輯者或管理者 若要連接或分離存取管理標籤, IAM 身分服務上的管理者 |
授權使用者存取啟用 IAM 的標籤資源
請完成下列步驟,將「編輯者」角色指派給使用者,以標記已啟用 IAM 的資源:
- 從 IBM Cloud 主控台,按一下管理 > 存取 (IAM),然後選擇存取群組。
- 按一下建立。
- 輸入群組名稱和說明,然後按一下建立。
- 按一下 新增使用者,從表格中選取一或多個使用者,然後按一下 新增至群組,將使用者新增至存取群組。
- 按一下存取 > 指定存取權限。
- 選取 所有已啟用身分及存取權的服務 或特定服務。
- 選取特定位置。
- 從平台存取角色清單中選取 編輯者,然後按一下 檢閱。
- 按一下 新增,將原則配置新增至原則摘要。
- 按一下指派。
使用 API 授與使用者對標籤已啟用 IAM 功能資源的存取權
若要指派使用者的編輯者角色來標記已啟用 IAM 的資源,請呼叫 IAM 原則管理 API,如下列範例要求中所示。 將變數取代為您的目標服務和資源名稱。
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": "iam_id",
"value": "IBMid-123453user"
}
]
}'
],
"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("iam_id")
.value(EXAMPLE_USER_ID)
.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: 'iam_id',
value: exampleUserId,
},
],
},
];
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='iam_id', value=example_user_id)])
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("iam_id"),
Value: &exampleUserID,
}
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))
授予使用者存取標籤經典基礎結構資源的權限
經典基礎架構的可標籤資源為虛擬 Guest、虛擬專用主機、網路應用程式遞送控制器、閘道成員、子網路、VLAN 及 VLAN 防火牆 (專用)。 請完成下列步驟,將「管理員」服務存取角色指派給使用者,以標記標準基礎架構服務:
- 按一下管理 > 存取 (IAM),然後選取使用者。
- 按一下表格中的使用者名稱。
- 按一下標準基礎架構。
- 從許可權標籤中,展開裝置種類。
- 選取檢視硬體詳細資料和檢視虛擬伺服器詳細資料。 如果您需要指派 Cloud Object Storage S3、File Storage 或 Evault Backup 的存取權限,請指派 Storage manage 權限。 如果您需要指派對 Content Delivery Network的存取權,請指派 管理 CDN 帳戶 許可權。
- 按一下儲存。
- 按一下裝置標籤。
- 視您希望使用者能夠標記的資源而定,選取 所有裸機伺服器 或 所有虛擬伺服器。
授與使用者對標籤服務 ID 的存取權
完成下列步驟,以指派使用者在 IAM Identity Service 上的管理者角色:
- 按一下管理 > 存取 (IAM),然後選取使用者。
- 按一下表格中的使用者名稱。
- 選取 IAM 身分服務,然後按 下一步。
- 選取 所有資源,然後按 下一步。
- 選擇管理員角色。
- 按一下 檢閱 > 新增。
- 按一下指派。
使用 API 授與使用者對標籤服務 ID 的存取權
若要為使用者指派 IAM Identity Service 上的管理者角色,請呼叫 IAM 原則管理 API,如下列範例要求所示。 將值取代為目標使用者的 IAM ID 及帳戶 ID。
curl -X POST 'https://iam.cloud.ibm.com/v1/policies' -H 'Authorization: Bearer $TOKEN' -H 'Content-Type: application/json' -d '{
"type": "access",
"description": "Administrator role for the IAM Identity Service so that user can tag service IDs",
"subjects": [
{
"attributes": [
{
"name": "iam_id",
"value": "IBMid-123453user"
}
]
}'
],
"roles":[
{
"role_id": "crn:v1:bluemix:public:iam::::role:Administrator"
}
],
"resources":[
{
"attributes": [
{
"name": "accountId",
"value": "$ACCOUNT_ID"
},
{
"name": "serviceName",
"value": "iam-identity"
}
]
}
]
}'
SubjectAttribute subjectAttribute = new SubjectAttribute.Builder()
.name("iam_id")
.value(EXAMPLE_USER_ID)
.build();
PolicySubject policySubjects = new PolicySubject.Builder()
.addAttributes(subjectAttribute)
.build();
PolicyRole policyRoles = new PolicyRole.Builder()
.roleId("crn:v1:bluemix:public:iam::::role:Administrator")
.build();
ResourceAttribute accountIdResourceAttribute = new ResourceAttribute.Builder()
.name("accountId")
.value(exampleAccountId)
.operator("stringEquals")
.build();
ResourceAttribute serviceNameResourceAttribute = new ResourceAttribute.Builder()
.name("serviceType")
.value("iam-identity")
.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: 'iam_id',
value: exampleUserId,
},
],
},
];
const policyRoles = [
{
role_id: 'crn:v1:bluemix:public:iam::::role:Administrator',
},
];
const accountIdResourceAttribute = {
name: 'accountId',
value: exampleAccountId,
operator: 'stringEquals',
};
const serviceNameResourceAttribute = {
name: 'serviceType',
value: 'iam-identity',
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='iam_id', value=example_user_id)])
policy_roles = PolicyRole(
role_id='crn:v1:bluemix:public:iam::::role:Administrator')
account_id_resource_attribute = ResourceAttribute(
name='accountId', value=example_account_id)
service_name_resource_attribute = ResourceAttribute(
name='serviceType', value='iam-identity')
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("iam_id"),
Value: &exampleUserID,
}
policySubjects := &iampolicymanagementv1.PolicySubject{
Attributes: []iampolicymanagementv1.SubjectAttribute{*subjectAttribute},
}
policyRoles := &iampolicymanagementv1.PolicyRole{
RoleID: core.StringPtr("crn:v1:bluemix:public:iam::::role:Administrator"),
}
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("iam-identity"),
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))